amol- / dukpy Goto Github PK
View Code? Open in Web Editor NEWSimple JavaScript interpreter for Python
License: MIT License
Simple JavaScript interpreter for Python
License: MIT License
This is stated in the README.rst file.
Since production ready is likely a fairly subjective status, what steps would it take to remove this status?
The inclusion of this library in the new version of pypac - which my team uses - has led us to wonder how we could change this status.
@amol- First of all thanks so much for putting up this interesting project!
As you have also mentioned webassets in your presentation on EuroPython 2016.
https://www.slideshare.net/__amol__/pyconit7-dukpy-webassets-free-yourself-from-nodejs-chains
I wondered whether it would be possible to use dukpy to resolve paths of all css and js files in a node_modules
folder.
Currently the necessary function require.resolve('module_name');
does not work.
We could then feed those paths directly into webassets' Bundle()
.
If we could simply catch and bundle all packages we have downloaded that way, it would alleviate the need to update our Bundle config every time we add dependencies. Or create an elaborate config in the first place.
Hence we would only need to run dukpy.install_jspackage('bootstrap
) and it would be automagically made available in our web templates. Thereby we could indeed dismiss npm.
IMHO. This could be one of the hidden superpowers of dukpy
. (Opposed to mere transpilations, because we can do this with webassets already.)
hi, when I try to insall dukpy with latest version 0.2.2 (or 0.2.1, 0.2.0) on mac, some error messages occur.
Mac: RELEASE_X86_64 x86_64
Python: 3.7
pip3: 18.0
when run command:
pip3 install dukpy
error messages:
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -DDUK_OPT_DEEP_C_STACK=1 -DDUK_OPT_NONSTD_REGEXP_DOLLAR_ESCAPE=1 -DDUK_OPT_OCTAL_SUPPORT=1 -I./src/duktape -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/duktape/duktape.c -o build/temp.macosx-10.13-x86_64-3.7/src/duktape/duktape.o
duk_bi_date_unix.c:53:15: error: array has incomplete element type 'struct tm'
struct tm tms[2];
^
duk_bi_date_unix.c:53:9: note: forward declaration of 'struct tm'
struct tm tms[2];
^
duk_bi_date_unix.c:134:28: error: invalid application of 'sizeof' to an incomplete type 'struct tm'
DUK_MEMZERO((void *) tms, sizeof(struct tm) * 2);
^ ~~~~~~~~~~~
./src/duktape/duk_config.h:1965:46: note: expanded from macro 'DUK_MEMZERO'
#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
^
/usr/include/secure/_string.h:76:33: note: expanded from macro 'memset'
__builtin___memset_chk (dest, VA_ARGS, __darwin_obsz0 (dest))
^~~~~~~~~~~
duk_bi_date_unix.c:53:9: note: forward declaration of 'struct tm'
struct tm tms[2];
...
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;file='/private/var/folders/x0/y4wx_dy95cg6kshhsnnvlhkr0000gn/T/pip-install-nemfkg94/dukpy/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /private/var/folders/x0/y4wx_dy95cg6kshhsnnvlhkr0000gn/T/pip-record-afo8rlwm/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/x0/y4wx_dy95cg6kshhsnnvlhkr0000gn/T/pip-install-nemfkg94/dukpy/
It would be great to get compiled wheels for Python 3.12. I'm happy to help with any work required!
Tested with Python 3.5.3 from master branch
The issue can be seen with:
import dukpy
import psutil
for i in range(100):
dukpy.evaljs("var o = {'value': 5}; o['value'] += 3; o")
print(psutil.virtual_memory())
Increase the value 100 to see larger leaks.
Please create a release with wheels for Python 3.7. I've added dukpy as a dependency for my library, PyPAC, but I'm holding off on declaring Python 3.7 support until dukpy has wheels for it on PyPI.
And thanks for your work! I really appreciate it.
Hi,
Thanks for developing and maintaining dukpy!
I stumbled into a situation that makes me think that dukpy needs to update its dependencies:
I need to babel-transpile KaTeX and noticed that this does not currently work with dukpy; I get the following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 49: invalid continuation byte
This is caused by a regex in KaTeX (https://github.com/KaTeX/KaTeX/blob/master/src/Lexer.js#L39) containing a unicode code point. Babel 6.14 - as currently used in dukpy - wrongly transforms it into the code point literal.
(An interesting point is that the error is raised "by chance", because this code point happens to represent a unicode surrogate, which Python's utf-8 disallows decoding.)
This is clearly a bug in babel 6.14, that was later fixed. Modifying dukpy to use the latest babel-standalone 6.x (currently 6.26, e.g. from https://github.com/babel/babel-standalone/releases/download/release-6.26.0/babel.min.js) fixes this issue.
A second problem arises when one tries to use dukpy with the newer babel-standalone 7.x: duktape then fails:
File "/home/.../.local/share/virtualenvs/fsjm-django/lib/python3.7/site-packages/dukpy/evaljs.py", line 136, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
File "/home/.../.local/share/virtualenvs/fsjm-django/lib/python3.7/site-packages/dukpy/evaljs.py", line 57, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: RangeError: register limit (line 1)
src/pyduktape.c:1
duk_js_compiler.c:1376
I did not try to make dukpy use a newer duktape release.
So:
Thanks!
Not particularly an issue as such, trying to use in an environment where unable to install build tools required to use package. Wondering if binary for 3.9 could be added to PyPi?
I passed a JavaScript file I have been working on into dukpy's evaljs
and got an error. I found the offending line and did some testing and discovered that it doesn't like the let
keyword. Some examples of what I used are:
let a;
let b = 5;
let c='hello world';
Each line above (which is valid JavaScript) results in this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\HPOWNE~1\DOCUME~1\CHRIST~1\projects\TDP\thea\KIVY_V~1\lib\site-packages\dukpy\evaljs.py", line 57, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: SyntaxError: unterminated statement (line 1)
src\pyduktape.c:1
duk_js_compiler.c:6594
It would seem as if the let
keyword is not supported. Is there a reason for that or has it simply not been added yet?
Duktape hasn't seen a release in an year, https://github.com/jerryscript-project/jerryscript is much more maintained. It would be reasonable to verify if we can easily embed/vendor it without adding complexity to the build system or break any API.
With new updates I suggest updating link to https://pypi.org/p/dukpy and adding AppVeyor badge.
Hi, when trying to pip install dukpy, it fails with the following:
copying dukpy\jsmodules\less\less\visitors\visitor.js -> build\lib.win-amd64-3.9\dukpy\jsmodules\less\less\visitors
running build_ext
building 'dukpy._dukpy' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> dukpy
note: This is an issue with the package mentioned above, not pip.
Microsoft Visual C++ is a dependency? Is it required to build this package?
Or if I have another c compiler, can I force to use that one?
(windows 10, python 3.9.7)
I tried installing webpack
via dukpy.install_jspackage
but it fails because some dependencies do not have a package
folder in the .tgz file:
import dukpy
dukpy.install_jspackage("webpack", "5.59.0", "assets_dl/")
Packages going to be installed: webpack->5.59.0, @types/eslint-scope->3.7.1, @types/eslint->7.28.1, @types/estree->0.0.50, @types/json-schema->7.0.9, @types/estree->0.0.50, @types/estree->0.0.50, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/wasm-edit->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-buffer->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-wasm-section->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-buffer->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/wasm-gen->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, @webassemblyjs/wasm-gen->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, @webassemblyjs/wasm-opt->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-buffer->1.11.1, @webassemblyjs/wasm-gen->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, @webassemblyjs/wasm-parser->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, @webassemblyjs/wasm-parser->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, @webassemblyjs/wast-printer->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/wasm-parser->1.11.1, @webassemblyjs/ast->1.11.1, @webassemblyjs/helper-numbers->1.11.1, @webassemblyjs/floating-point-hex-parser->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/helper-api-error->1.11.1, @webassemblyjs/helper-wasm-bytecode->1.11.1, @webassemblyjs/ieee754->1.11.1, @xtuc/ieee754->1.2.0, @webassemblyjs/leb128->1.11.1, @xtuc/long->4.2.2, @webassemblyjs/utf8->1.11.1, acorn->8.5.0, acorn-import-assertions->1.8.0, browserslist->4.17.4, caniuse-lite->1.0.30001270, electron-to-chromium->1.3.873, escalade->3.1.1, node-releases->2.0.0, picocolors->1.0.0, chrome-trace-event->1.0.3, enhanced-resolve->5.8.3, graceful-fs->4.2.8, tapable->2.2.1, es-module-lexer->0.9.3, eslint-scope->5.1.1, esrecurse->4.3.0, estraverse->5.2.0, estraverse->4.3.0, events->3.3.0, glob-to-regexp->0.4.1, graceful-fs->4.2.8, json-parse-better-errors->1.0.2, loader-runner->4.2.0, mime-types->2.1.33, mime-db->1.50.0, neo-async->2.6.2, schema-utils->3.1.1, @types/json-schema->7.0.9, ajv->6.12.6, fast-deep-equal->3.1.3, fast-json-stable-stringify->2.1.0, json-schema-traverse->0.4.1, uri-js->4.4.1, punycode->2.1.1, ajv-keywords->3.5.2, tapable->2.2.1, terser-webpack-plugin->5.2.4, jest-worker->27.3.1, @types/node->16.11.1, merge-stream->2.0.0, supports-color->8.1.1, has-flag->4.0.0, p-limit->3.1.0, yocto-queue->0.1.0, schema-utils->3.1.1, @types/json-schema->7.0.9, ajv->6.12.6, fast-deep-equal->3.1.3, fast-json-stable-stringify->2.1.0, json-schema-traverse->0.4.1, uri-js->4.4.1, punycode->2.1.1, ajv-keywords->3.5.2, serialize-javascript->6.0.0, randombytes->2.1.0, safe-buffer->5.2.1, source-map->0.6.1, terser->5.9.0, commander->2.20.3, source-map->0.7.3, source-map-support->0.5.20, buffer-from->1.1.2, source-map->0.6.1, watchpack->2.2.0, glob-to-regexp->0.4.1, graceful-fs->4.2.8, webpack-sources->3.2.1
Fetching https://registry.npmjs.org/webpack/-/webpack-5.59.0.tgz..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Fetching https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.1.tgz...
Traceback (most recent call last):
File "/usr/lib/python3.9/shutil.py", line 814, in move
os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/tmp/tmpgi47tjcg/package' -> '[...]/assets_dl/@types/eslint-scope'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "[...]/dl_webpack.py", line 3, in <module>
dukpy.install_jspackage("webpack", "5.59.0", "assets_dl/")
File "[...]/lib/python3.9/site-packages/dukpy/install.py", line 82, in install_jspackage
shutil.move(os.path.join(tmpdir, 'package'),
File "/usr/lib/python3.9/shutil.py", line 834, in move
copy_function(src, real_dst)
File "/usr/lib/python3.9/shutil.py", line 443, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.9/shutil.py", line 265, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpgi47tjcg/package'
Please consider to use unittest.mock instead, at least optionally.
Hi,
Im getting this error on render.com:
Traceback (most recent call last):
Nov 17 03:33:06 AM File "kaktos.py", line 6, in <module>
Nov 17 03:33:06 AM system.process_command()
Nov 17 03:33:06 AM File "/opt/render/project/src/modules/system.py", line 122, in process_command
Nov 17 03:33:06 AM run(command_params)
Nov 17 03:33:06 AM File "/opt/render/project/src/modules/commands/build.py", line 12, in run
Nov 17 03:33:06 AM system.build_pages()
Nov 17 03:33:06 AM File "/opt/render/project/src/modules/system.py", line 85, in build_pages
Nov 17 03:33:06 AM assets.build_js()
Nov 17 03:33:06 AM File "/opt/render/project/src/modules/assets.py", line 44, in build_js
Nov 17 03:33:06 AM b.write(minify_js(og.read()))
Nov 17 03:33:06 AM File "/opt/render/project/src/modules/assets.py", line 21, in minify_js
Nov 17 03:33:06 AM result = str(es5(babel_compile(str(code))["code"]))
Nov 17 03:33:06 AM File "/opt/render/project/src/.venv/lib/python3.8/site-packages/dukpy/babel.py", line 13, in babel_compile
Nov 17 03:33:06 AM return evaljs(
Nov 17 03:33:06 AM File "/opt/render/project/src/.venv/lib/python3.8/site-packages/dukpy/evaljs.py", line 138, in evaljs
Nov 17 03:33:06 AM return JSInterpreter().evaljs(code, **kwargs)
Nov 17 03:33:06 AM File "/opt/render/project/src/.venv/lib/python3.8/site-packages/dukpy/evaljs.py", line 31, in __init__
Nov 17 03:33:06 AM self._init_process()
Nov 17 03:33:06 AM File "/opt/render/project/src/.venv/lib/python3.8/site-packages/dukpy/evaljs.py", line 87, in _init_process
Nov 17 03:33:06 AM self.evaljs("process = {}; process.env = dukpy.environ", environ=dict(os.environ))
Nov 17 03:33:06 AM File "/opt/render/project/src/.venv/lib/python3.8/site-packages/dukpy/evaljs.py", line 61, in evaljs
Nov 17 03:33:06 AM return json.loads(res.decode('utf-8'))
Nov 17 03:33:06 AM UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 6510: invalid continuation byte
Do you know what can be wrong?
(py35) C:\Users\Batman>easy_install dukpy
Searching for dukpy
Reading https://pypi.python.org/simple/dukpy/
Downloading https://pypi.python.org/packages/37/ac/b0bb18515ada37defe2d2a44471fc
114264c3c5f435b4d2d23432537c239/dukpy-0.1.0.tar.gz#md5=09c90bf96c552b33d99a11911
cff8d0a
Best match: dukpy 0.1.0
Processing dukpy-0.1.0.tar.gz
Writing C:\Users\Batman\AppData\Local\Temp\easy_install-0ykfkg6z\dukpy-0.1.0\set
up.cfg
Running dukpy-0.1.0\setup.py -q bdist_egg --dist-dir C:\Users\Batman\AppData\Loc
al\Temp\easy_install-0ykfkg6z\dukpy-0.1.0\egg-dist-tmp-tf5yv703
duktape.c
_support.c
src_support.c(1): fatal error C1083: Cannot open include file: 'unistd.h': No s
uch file or directory
error: Setup script exited with error: command 'C:\Program Files (x86)\Microso
ft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
I'm trying to run less.js with dukpy, but the library appears to use the Node.js path module which seems to be unavailable with dukpy.
Is this fixable?
(venv) rav@gonzales:~/dukpy$ dukpy-install less
Packages going to be installed: less->2.7.1, image-size->0.5.0, source-map->0.5.6, graceful-fs->4.1.5, mime->1.3.4, errno->0.1.4, prr->0.0.0, promise->7.1.1, asap->2.0.4, mkdirp->0.5.1, minimist->0.0.8
Fetching https://registry.npmjs.org/promise/-/promise-7.1.1.tgz..........................
Fetching https://registry.npmjs.org/image-size/-/image-size-0.5.0.tgz.......
Fetching https://registry.npmjs.org/asap/-/asap-2.0.4.tgz...........
Fetching https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz.......................................................................................................................................................................................
Fetching https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.5.tgz........
Fetching https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz......
Fetching https://registry.npmjs.org/prr/-/prr-0.0.0.tgz....
Fetching https://registry.npmjs.org/mime/-/mime-1.3.4.tgz............
Fetching https://registry.npmjs.org/errno/-/errno-0.1.4.tgz......
Fetching https://registry.npmjs.org/less/-/less-2.7.1.tgz...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Fetching https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz.....
Installing less in ./js_modules Done!
(venv) rav@gonzales:~/dukpy$ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dukpy.evaljs import evaljs
>>> evaljs('require("less")')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/ssd/home/venvs/kasse/lib/python3.5/site-packages/dukpy/evaljs.py", line 119, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
File "/ssd/home/venvs/kasse/lib/python3.5/site-packages/dukpy/evaljs.py", line 53, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: Error: cannot find module: less
anon src/pyduktape.c:5 preventsyield
require native strict preventsyield
eval src/pyduktape.c:1 preventsyield
Trying to import the path
module directly similarly fails:
>>> interpreter = dukpy.JSInterpreter()
>>> interpreter.loader.register_path('./js_modules')
>>> interpreter.evaljs('require("path")'
... )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/ssd/home/venvs/kasse/lib/python3.5/site-packages/dukpy/evaljs.py", line 53, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: Error: cannot find module: path
anon src/pyduktape.c:5 preventsyield
require native strict preventsyield
eval src/pyduktape.c:1 preventsyield
>>> interpreter.evaljs('require("./path")')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/ssd/home/venvs/kasse/lib/python3.5/site-packages/dukpy/evaljs.py", line 53, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: Error: cannot find module: path
anon src/pyduktape.c:5 preventsyield
require native strict preventsyield
eval src/pyduktape.c:1 preventsyield
Any plans to upgrade LessCss source files?
Hello,
I came to your lib via javascripthon. Do you have any plan to support windows build?
Thanks
Here are the errors:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DDUK_OPT_DEEP_C_STACK=1 -DDUK_OPT_NONSTD_REGEXP_DOLLAR_ESCAPE=1 -DDUK_OPT_OCTAL_SUPPORT=1 -I.\src\duktape -IC:\Python35-x64\include -IC:\Python35-x64\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /Tcsrc\duktape\duktape.c /Fobuild\temp.win-amd64-3.5\Release\src\duktape\duktape.obj
336 duktape.c
337 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DDUK_OPT_DEEP_C_STACK=1 -DDUK_OPT_NONSTD_REGEXP_DOLLAR_ESCAPE=1 -DDUK_OPT_OCTAL_SUPPORT=1 -I.\src\duktape -IC:\Python35-x64\include -IC:\Python35-x64\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\winrt" /Tcsrc\_support.c /Fobuild\temp.win-amd64-3.5\Release\src\_support.obj
338 _support.c
339 src\_support.c(1): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
340 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
341
342 ----------------------------------------
343Command "C:\Python35-x64\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\pip-build-i9t2zpp9\\dukpy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\appveyor\AppData\Local\Temp\1\pip-46n0b6pn-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\appveyor\AppData\Local\Temp\1\pip-build-i9t2zpp9\dukpy\
In dukpy.evaljs
, the math function Math.trunc
raises the exception _dukpy.JSRuntimeError: TypeError: undefined not callable
. Other math functions, such as Math.floor
, work.
To reproduce in Python 3 (tested in 3.6.9):
>>> import dukpy
>>> print(dukpy.evaljs("Math.trunc(2.3)"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/xxx/.local/lib/python3.6/site-packages/dukpy/evaljs.py", line 134, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
File "/home/xxx/.local/lib/python3.6/site-packages/dukpy/evaljs.py", line 57, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: TypeError: undefined not callable
duk_js_call.c:776
eval src/pyduktape.c:1 preventsyield
>>> print(dukpy.evaljs("Math.floor(2.3)"))
2
I'm curious if anyone knows what (if any) calls to dukpy are thread safe?
From what I have been able to gather so far. The safest bet is to instantiate dukpy.JSInterpreter() for each 'thread/request' in a web app. The downside to this is having to load any library javascript code durring the request.
Is this not safe?
app = Flask(__name__)
jsi = JSInterpreter()
jsi.evaljs(libs_js)
@app.route('/'):
def index():
jsi.eval(request_js)
...
Is this the 'correct' way?
app = Flask(__name__)
@app.before_request
def before_request():
g.jsi = JSInterpreter()
g.jsi.evaljs(libs_js)
@app.route('/'):
def index():
g.jsi.eval(request_js)
...
Pyecharts user pointed out that the link in the following error message is no longer valid. Could you please see if you could address this issue in your next release?
Running setup.py install for dukpy: finished with status 'error'
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
Reference:
I want to install pyecahrts ,but it happened some error ,looks like Dukpy error, so I pip3 install dukpy.
Then this error happened:
Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;file='/private/var/folders/lj/k3xsm5p51j78fgjswrcty33m0000gn/T/pip-install-cf5q7g6j/dukpy/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /private/var/folders/lj/k3xsm5p51j78fgjswrcty33m0000gn/T/pip-record-ump5c0lu/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/lj/k3xsm5p51j78fgjswrcty33m0000gn/T/pip-install-cf5q7g6j/dukpy/
How can I do?
If I implement a library to, for instance, pull some javascript off the web and evaluate it -- would I open the door to malicious code accessing things that it couldn't if I were running it in the browser?
Hi,
I need help with building a dukpy filter. I am trying to build tools to create vue.js assets via webassets.
I copied the logic in the less filter. When I run the tests I just get:
JSRuntimeError: SyntaxError: unterminated statement (line 2).
However the file pointed to is the package.json file. The full code is in my fork at..
https://github.com/kevingill1966/dukpy
Full traceback is in
https://github.com/kevingill1966/dukpy/blob/master/PROBLEM.rst
Summary traceback...
File "/srv/insight_nrn/submodules/dukpy/dukpy/webassets/vuejsfilter.py", line 24, in input
src = dukpy.vue_template_compiler(_in.read(), options=options)
File "/srv/insight_nrn/submodules/dukpy/dukpy/vuejs.py", line 18, in vue_template_compiler
options=options
File "/srv/insight_nrn/submodules/dukpy/dukpy/evaljs.py", line 57, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
JSRuntimeError: SyntaxError: unterminated statement (line 2)
vue-template-compiler/package.json:2
duk_js_compiler.c:6594
anon native strict preventsyield
anon vue-template-compiler:5 preventsyield
require native strict preventsyield
eval src/pyduktape.c:1 preventsyield
I'm getting an error when the js code contains a special emoji.
MWE:
dukpy.evaljs("var data = '💫'; data")
Error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 1: invalid continuation byte
Thank you
Please create a release with wheels for Python 3.8. Thanks!
Currently dukpy ships with Babel 6.4.4 minified, which does not include a fix for a particular bug that I am encountering.
Would it be easy to update dukpy to a newer Babel?
Something like
import Vue from 'vue';
Or
import Ember from 'ember';
We are in a situation where it is difficult to ensure that MS Build Tools is installed on a machine that is using pip install-ing dukpy. As wheel files have not been uploaded to PyPI for Python 3.9 this results in a failed installation for us. Although we can come up with workarounds on our side, we figured other users may have the same problem. Is there any appetite for uploading 3.9 .whl files for the latest release?
Thanks for reading.
Hi,
There's a few ways of improving this distribution package:
setuptools_scm
into setup.py
to enable version guessing via git tag — you'll never need to hardcode the version in Python files;Would you accept my help with this?
This is more of a feature request.
Currently, if there is an exception inside a function called with call_python()
, it ends up being consumed by dukpy and gets translated into a dukpy.JSRuntimeError
.
However, dukpy itself seems to have all the necessary information to just rethrow this exception to the caller of evaljs()
, which would be more useful for error handling. If preserving existing behaviour is necessary, maybe it could be an optional argument to evaljs()
that is set to False
by default.
Is this something that could be added?
In evaljs, trailing commas are allowed in array declarations, but when using Array constructors, it causes a crash:
import dukpy
testArray1 = '''
var array1 = [1, 2, 3, ];
array1.reduce(function(a, b) { return a + b; }, 0);
'''
print(dukpy.evaljs(testArray1))
testArray2 = '''
var array2 = new Array(1, 2, 3, );
array2.reduce(function(a, b) { return a + b; }, 0);
'''
print(dukpy.evaljs(testArray2))
~ $ python3 test.py
6
Traceback (most recent call last):
File "test.py", line 12, in <module>
print(dukpy.evaljs(testArray2))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dukpy/evaljs.py", line 134, in evaljs
return JSInterpreter().evaljs(code, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dukpy/evaljs.py", line 57, in evaljs
res = _dukpy.eval_string(self, jscode, jsvars)
_dukpy.JSRuntimeError: SyntaxError: empty expression not allowed (line 2)
src/pyduktape.c:2
duk_js_compiler.c:4731
How can I use it to execute es6 code, Are there any similar examples
Just a minor issue. When installing on macOS, the wheel fails to build. This is due to the missing LICENSE file listed in the setup.cfg
metadata. Most likely you just need to add the file to the MANIFEST.in
.
error: [Errno 2] No such file or directory: 'LICENSE'
----------------------------------------
Failed building wheel for dukpy
That said, the package does install correctly as a traditional sdist. I don't fully understand the install process here, but it looks like installation attempts to build the wheel first, which fails then falls back to installing the sdist.
From what I can see you are not sandbox'ing duktape at all... is this correct?
Hi @amol-,
this is a feature request, not a bug.
As you maybe remember, i'm using duckpy with babeljs to compile ES6+ javascript to ES5 js.
In this use case, evaluating the babeljs minified source code which is 750 KB takes time and this slows down the overall per-file translation time. If the number of code blocks (or files) to translate is known this can be resolved with an evaljs() wrapper that handles such multiple blocks. Unfortunately this doesn't cover all the use cases where it would be nice to have a js interpreter already "hot", waiting for translation job... but let me contextualize a bit.
I'm using duckpy together with metapensiero.pj (AKA Javascripthon)
to transpile anything ranging from a tree of Python 3.5 source files to a code object (a class, a function) to ES6+ JS and then to ES5 with babeljs.
Having an "hot" duckpy interpreter, with all the babeljs code already loaded would mean that converting and serving python-ish code to the client becomes possible if the client has loaded the dependencies already.
Hey, I'm wondering if DukPy can compile a file rather than a string?
What I mean is that I want to be able to provide the path to a CoffeeScript or TypeScript file and the name of an output file and have DukPy do the compilation for me. Something like this:
import dukpy
dukpy.coffee_compile('file.coffee', 'file.js')
OR
import dukpy
dukpy.typescript_compile('file.ts', 'file.js')
Im currently using another package called libsass-python for compiling Sass and Scss files to CSS and it offers this functionality. Would be great if DukPy could do the same!
I know I could write this functionality myself by getting a Python script to read a file into a string variable, pass that sting variable to the DukPy compile function and then write the output to a file. I just thought I would first check to see if this functionality already exists... don't want to reinvent the wheel!
Hi,
is (and how) it possible to specify my js-requirements in setup.py. Do you have a simple example for that? Is there a hook or something i can register the install_jspackage in an smart way.
thanks in advance
I get the error
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 70813: ordinal not in range(128)
every time I try to run any JS code via dukpy.babel_compile
Here's an example snippet:
dukpy.babel_compile("var o = {'value': 5}; o['value'] += 7; o")
Env: Python 3.4 with virtualenv
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.