Skip to content

Commit 9cf8e0f

Browse files
authored
Changes to work with latest environment and libraries (#630)
* Remove jinja2.ext.with_ . It's a no-op since 2.9 and removed since 3.1 . https://jinja.palletsprojects.com/en/3.0.x/extensions/#with-statement * Lock aiohttp version to 3.7.4 since 3.8.0+ introduced ill behavior. aio-libs/aiohttp#5572 * Use misaka for markdown rendering since hoedown is incompatible with latest Python. * Fix aiomongo to work with pymongo 3.5 . * Unlimit Python version and limit MongoDB version. * Allow range for aiohttp version. * Add Python 3.9 to test.yml . * Bump Python version requirement to 3.6 since cffi won't install easily on 3.5 . * Update README.md . * Use escape and Markup from markupsafe since it's removed from jinja2 since 3.1.0 .
1 parent f24a75e commit 9cf8e0f

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

.github/workflows/test.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
runs-on: ubuntu-latest
7575
strategy:
7676
matrix:
77-
python-version: [3.5, 3.6, 3.7, 3.8]
77+
python-version: [3.6, 3.7, 3.8, 3.9]
7878
services:
7979
rabbitmq:
8080
image: rabbitmq
@@ -115,4 +115,3 @@ jobs:
115115
116116
- name: Unit tests
117117
run: python -m unittest
118-
continue-on-error: ${{ matrix.python-version == '3.8' }}

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ There is pre-built docker package at `vijos/vj4`. This is maintained by [@moesoh
4343

4444
#### Prerequisites
4545

46-
* [Python 3.5.3+, <3.8](https://www.python.org/downloads/)
47-
* [MongoDB 3.0+](https://docs.mongodb.org/manual/installation/)
46+
* [Python 3.6+](https://www.python.org/downloads/)
47+
* [MongoDB 3.0+, <3.6](https://docs.mongodb.org/manual/installation/)
4848
* [Node.js 10.0+](https://nodejs.org/en/download/package-manager/)
4949
* [RabbitMQ](http://www.rabbitmq.com/)
5050

@@ -61,10 +61,10 @@ You don't need root privilege to run `yarn`. It installs stuffs in the project d
6161

6262
You may want to use [tuna](https://pypi.tuna.tsinghua.edu.cn/) if you are in China.
6363

64-
Some requirements may need `Python.h`. In Debian/Ubuntu you can use
64+
Some requirements may need `Python.h` and `ffi.h`. In Debian/Ubuntu you can use
6565

6666
```bash
67-
apt install python3-dev
67+
apt install python3-dev libffi-dev
6868
```
6969

7070
to resolve this.

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
aiohttp>=3
1+
aiohttp>=3.6.0,<3.8.0
22
jinja2>=2.9.0
33
sockjs>=0.7.0,<0.10.0
4-
hoedown
4+
misaka
55
accept
66
aioamqp
77
git+https://github.com/LukeXuan/aiosmtplib # custom aiosmtlib with ssl support
@@ -11,6 +11,6 @@ httpagentparser
1111
geoip2
1212
GitPython
1313
PyYAML
14-
aiomongo
14+
git+https://github.com/iceboy233/aiomongo
1515
yarl
1616
aiohttp-sentry

vj4/template.py

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Environment(jinja2.Environment):
2525
def __init__(self):
2626
super(Environment, self).__init__(
2727
loader=jinja2.FileSystemLoader(path.join(path.dirname(__file__), 'ui/templates')),
28-
extensions=[jinja2.ext.with_],
2928
auto_reload=options.debug,
3029
autoescape=True,
3130
trim_blocks=True,

vj4/util/misc.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import base64
22
import hashlib
3-
import hoedown
43
import jinja2
54
import markupsafe
5+
import misaka
66
import re
77
from urllib import parse
88

99
from vj4.util import options
1010

1111

12-
MARKDOWN_EXTENSIONS = (hoedown.EXT_TABLES | # Parse PHP-Markdown style tables.
13-
hoedown.EXT_FENCED_CODE | # Parse fenced code blocks.
14-
hoedown.EXT_AUTOLINK | # Automatically turn safe URLs into links.
15-
hoedown.EXT_NO_INTRA_EMPHASIS | # Disable emphasis_between_words.
16-
hoedown.EXT_MATH | # Parse TeX $$math$$ syntax, Kramdown style.
17-
hoedown.EXT_SPACE_HEADERS | # Require a space after '#' in headers.
18-
hoedown.EXT_MATH_EXPLICIT | # Instead of guessing by context, parse $inline math$ and $$always block math$$ (requires EXT_MATH).
19-
hoedown.EXT_DISABLE_INDENTED_CODE) # Don't parse indented code blocks.
20-
MARKDOWN_RENDER_FLAGS = (hoedown.HTML_ESCAPE | # Escape all HTML.
21-
hoedown.HTML_HARD_WRAP) # Render each linebreak as <br>.
12+
MARKDOWN_EXTENSIONS = (misaka.EXT_TABLES | # Parse PHP-Markdown style tables.
13+
misaka.EXT_FENCED_CODE | # Parse fenced code blocks.
14+
misaka.EXT_AUTOLINK | # Automatically turn safe URLs into links.
15+
misaka.EXT_NO_INTRA_EMPHASIS | # Disable emphasis_between_words.
16+
misaka.EXT_MATH | # Parse TeX $$math$$ syntax, Kramdown style.
17+
misaka.EXT_SPACE_HEADERS | # Require a space after '#' in headers.
18+
misaka.EXT_MATH_EXPLICIT | # Instead of guessing by context, parse $inline math$ and $$always block math$$ (requires EXT_MATH).
19+
misaka.EXT_DISABLE_INDENTED_CODE) # Don't parse indented code blocks.
20+
MARKDOWN_RENDER_FLAGS = (misaka.HTML_ESCAPE | # Escape all HTML.
21+
misaka.HTML_HARD_WRAP) # Render each linebreak as <br>.
2222

2323

2424
FS_RE = re.compile(r'\(vijos\:\/\/fs\/([0-9a-f]{40,})\)')
2525

2626

2727
def nl2br(text):
28-
markup = jinja2.escape(text)
29-
return jinja2.Markup('<br>'.join(markup.split('\n')))
28+
markup = markupsafe.escape(text)
29+
return markupsafe.Markup('<br>'.join(markup.split('\n')))
3030

3131

3232
def fs_replace(m):
@@ -36,7 +36,7 @@ def fs_replace(m):
3636

3737
def markdown(text):
3838
text = FS_RE.sub(fs_replace, text)
39-
return markupsafe.Markup(hoedown.html(
39+
return markupsafe.Markup(misaka.html(
4040
text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS))
4141

4242

0 commit comments

Comments
 (0)