-
Notifications
You must be signed in to change notification settings - Fork 43
migrate to QuickJS and prepare for 0.6.0 #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3fd1476
8358cee
3d40efe
94a10c9
f35c703
9b8961f
85f8f27
8d87d8a
66e8dd2
5d19ac5
d25a0a0
28c4bb7
8421896
82be5f8
4240c62
fcd2cf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: lint | ||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| ruff: | ||
| name: Ruff | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Install lint tools | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install ruff pre-commit | ||
| - name: Ruff check | ||
| run: | | ||
| ruff check . | ||
| ruff format --check . | ||
|
Comment on lines
+22
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't install |
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use native integration, not local and you won't need to install |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| repos: | ||
| - repo: local | ||
| hooks: | ||
| - id: ruff-check | ||
| name: ruff-check | ||
| entry: ruff check . | ||
| language: system | ||
| types: [python] | ||
| - id: ruff-format | ||
| name: ruff-format | ||
| entry: ruff format --check . | ||
| language: system | ||
| types: [python] |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend annotating whatever rules you list: https://github.com/cherrypy/cheroot/blob/662cd9dcf426253536f921c618b480e65a429cb1/.ruff.toml |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||
| line-length = 88 | ||||
| target-version = "py39" | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set
Suggested change
|
||||
| extend-exclude = ["src/duktape", "dukpy/jsmodules", "dukpy/jscore"] | ||||
|
|
||||
| [lint] | ||||
| select = ["E", "F"] | ||||
| ignore = ["E501"] | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| recursive-include src *.h | ||
| recursive-include src/quickjs *.c *.h VERSION | ||
| recursive-include dukpy/jscore *.js | ||
| recursive-include dukpy/jsmodules *.js | ||
| include LICENSE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,13 @@ dukpy | |
| .. image:: https://img.shields.io/pypi/v/dukpy.svg | ||
| :target: https://pypi.org/p/dukpy | ||
|
|
||
| .. raw:: html | ||
|
|
||
| <img align="left" width="100px" src="dukpy_logo.png" alt="DukPy logo"> | ||
|
|
||
|
|
||
| DukPy is a simple javascript interpreter for Python built on top of | ||
| duktape engine **without any external dependency**. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice to leave a historic reference explaining the project name. |
||
| QuickJS engine **without any external dependency**. | ||
| It comes with a bunch of common transpilers built-in for convenience: | ||
|
|
||
| - *CoffeeScript* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,29 @@ | ||
| import os | ||
| from .evaljs import evaljs | ||
|
|
||
| BABEL_COMPILER = os.path.join(os.path.dirname(__file__), 'jsmodules', 'babel-6.26.0.min.js') | ||
| BABEL_COMPILER = os.path.join( | ||
| os.path.dirname(__file__), "jsmodules", "babel-6.26.0.min.js" | ||
| ) | ||
|
|
||
|
|
||
| def babel_compile(source, **kwargs): | ||
| """Compiles the given ``source`` from ES6 to ES5 using Babeljs""" | ||
| presets = kwargs.get('presets') | ||
| presets = kwargs.get("presets") | ||
| if not presets: | ||
| kwargs['presets'] = ["es2015"] | ||
| with open(BABEL_COMPILER, 'rb') as babel_js: | ||
| kwargs["presets"] = ["es2015"] | ||
| with open(BABEL_COMPILER, "rb") as babel_js: | ||
| return evaljs( | ||
| (babel_js.read().decode('utf-8'), | ||
| 'var bres, res;' | ||
| 'bres = Babel.transform(dukpy.es6code, dukpy.babel_options);', | ||
| 'res = {map: bres.map, code: bres.code};'), | ||
| ( | ||
| babel_js.read().decode("utf-8"), | ||
| "var bres, res;" | ||
| "bres = Babel.transform(dukpy.es6code, dukpy.babel_options);", | ||
| "res = {map: bres.map, code: bres.code};", | ||
| ), | ||
| es6code=source, | ||
| babel_options=kwargs | ||
| babel_options=kwargs, | ||
| ) | ||
|
|
||
|
|
||
| def jsx_compile(source, **kwargs): | ||
| kwargs['presets'] = ['es2015', 'react'] | ||
| return babel_compile(source, **kwargs)['code'] | ||
| kwargs["presets"] = ["es2015", "react"] | ||
| return babel_compile(source, **kwargs)["code"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| import os | ||
| from .evaljs import evaljs | ||
|
|
||
| COFFEE_COMPILER = os.path.join(os.path.dirname(__file__), 'jsmodules', 'coffeescript.js') | ||
| COFFEE_COMPILER = os.path.join( | ||
| os.path.dirname(__file__), "jsmodules", "coffeescript.js" | ||
| ) | ||
|
|
||
|
|
||
| def coffee_compile(source): | ||
| """Compiles the given ``source`` from CoffeeScript to JavaScript""" | ||
| with open(COFFEE_COMPILER, 'rb') as coffeescript_js: | ||
| with open(COFFEE_COMPILER, "rb") as coffeescript_js: | ||
| return evaljs( | ||
| (coffeescript_js.read().decode('utf-8'), | ||
| 'CoffeeScript.compile(dukpy.coffeecode)'), | ||
| coffeecode=source | ||
| ( | ||
| coffeescript_js.read().decode("utf-8"), | ||
| "CoffeeScript.compile(dukpy.coffeecode)", | ||
| ), | ||
| coffeecode=source, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These versions are quite outdated.