Closed dportabella closed 1 month ago
I tried also on docker, with the same result:
docker run -ti python bash
echo "import copy" >test.py
pip install transcrypt
transcrypt -b test.py
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.6.24
Copyright (C) Geatec Engineering. License: Apache 2.0
Error while compiling (offending file last):
File '//test.py', line 1, at import of:
File '/usr/local/lib/python3.6/copy.py', line 51, at import of:
File '/usr/local/lib/python3.6/types.py', line 4, namely:
Attempt to import module: sys
Can't find any of:
//sys/__init__.py
//sys/__javascript__/__init__.mod.js
/usr/local/lib/python3.6/site-packages/transcrypt/modules/sys.py
/usr/local/lib/python3.6/site-packages/transcrypt/modules/__javascript__/sys.mod.js
/usr/local/bin/sys.py
/usr/local/bin/__javascript__/sys.mod.js
/usr/local/lib/python36.zip/sys.py
/usr/local/lib/python36.zip/__javascript__/sys.mod.js
/usr/local/lib/python3.6/sys.py
/usr/local/lib/python3.6/__javascript__/sys.mod.js
/usr/local/lib/python3.6/lib-dynload/sys.py
/usr/local/lib/python3.6/lib-dynload/__javascript__/sys.mod.js
/usr/local/lib/python3.6/site-packages/sys.py
/usr/local/lib/python3.6/site-packages/__javascript__/sys.mod.js
Aborted
Hi,
Unfortunately the 'copy' standard library is not yet supported by Transcrypt.
TS mostly relies on JS libs:
We strive to make a limited number of standard libs available, to ease the transition from CPython.
Currently the following standard modules are available for Transcrypt: math, cmath, re, itertools, time, random (most important functions only), logging, warnings, turtle. There's also a port of a small part of Numpy called Numscrypt, available separately from PyPi.
Kind regards Jacques
Ok, thanks. do you plan to support the "collections" library?
There were no plans in that direction, but actually that may be a useful one to support. In general for libraries we rely on third party contributions.
KR Jacques
@JdeH I'm interested in a port of the collections module too. Where's a good place to discuss the design of it?
@harto
I've opened #442 as a place to discuss this.
Kind regards Jacques
Revisiting this. I know copy
is not supported yet, but the message I get is slightly different so I wanted to add to this thread:
I'm trying to use deepcopy from the built-in copy module copy.deepcopy()
, but Transcrypt complains that it can't find PyStringMap when trying to import it
import copy
Error while compiling (offending file last):
File '/home/data/Python/Transcrypt/demo3/app.py', line 11, at import of:
File 'copy', line 60, namely:
Import error, can't find any of:
/home/data/Python/Transcrypt/demo3/org/python/core/PyStringMap.py
/home/data/Python/Transcrypt/demo3/org/python/core/PyStringMap.js
/home/data/Python/Transcrypt/demo3/venv/lib/python3.7/site-packages/transcrypt/modules/org/python/core/PyStringMap.py
/home/data/Python/Transcrypt/demo3/venv/lib/python3.7/site-packages/transcrypt/modules/org/python/core/PyStringMap.js
/home/data/Python/Transcrypt/demo3/venv/bin/org/python/core/PyStringMap.py
/home/data/Python/Transcrypt/demo3/venv/bin/org/python/core/PyStringMap.js
/usr/lib/python3.7/org/python/core/PyStringMap.py
/usr/lib/python3.7/org/python/core/PyStringMap.js
/usr/lib/python3.7/lib-dynload/org/python/core/PyStringMap.py
/usr/lib/python3.7/lib-dynload/org/python/core/PyStringMap.js
/home/data/Python/Transcrypt/demo3/venv/lib/python3.7/site-packages/org/python/core/PyStringMap.py
/home/data/Python/Transcrypt/demo3/venv/lib/python3.7/site-packages/org/python/core/PyStringMap.js
...
In the mean time I've had some luck with using the lodash.clonedeep() JS library, but it seems to return dictionaries that have to be run through Python dict() to be valid.
After getting a bit more experience with Transcrypt and re-reading this, I realized my previous post was already answered in that the Python copy
library itself is not implemented.
Related to this though, I see there are copy
and deepcopy
functions that end up in the Transcrypt JS runtime module. However that deepcopy
function does not appear to actually deep copy JavaScript objects. I have worked around this issue by using a JS library (both deepcopy and lodash.cloneDeep work), but was wondering what the relationship of the deepcopy
in the Transcrypt runtime is to the Python copy.deepcopy
function, and if so are there known limitations of that one? Or am I just misunderstanding something?
copy
module with copy
and deepcopy
is currently added in dev_3.9.3 branch to be released in v3.9.3
Need to do a bit more testing on it before releasing.
this simple file
test.py
:transcrypt fails with:
Another project that also has
import copy
, it fails with: