Repository navigation
it fails on import copy #313
Copy link
Copy link
Closed
Description
this simple file test.py:
import copy
transcrypt fails with:
$ 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 '/Users/david/test.py', line 1, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/copy.py', line 51, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/types.py', line 4, namely:
Attempt to import module: sys
Can't find any of:
/Users/david/sys.py
/Users/david/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/transcrypt/modules/sys.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/transcrypt/modules/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/bin/sys.py
/Users/david/.virtualenvs/py3-data/bin/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/lib/python36.zip/sys.py
/Users/david/.virtualenvs/py3-data/lib/python36.zip/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/sys.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/lib-dynload/sys.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/lib-dynload/__javascript__/sys.mod.js
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sys.py
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/__javascript__/sys.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/sys.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/__javascript__/sys.mod.js
Another project that also has import copy, it fails with:
$ 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 '/Users/david/test.py', line 5, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/copy.py', line 51, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/types.py', line 15, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/lxml/__init__.py', line 9, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/os.py', line 25, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/abc.py', line 6, at import of:
File '/Users/david/.virtualenvs/py3-data/lib/python3.6/_weakrefset.py', line 5, namely:
Attempt to import module: _weakref
Can't find any of:
/Users/david/_weakref.py
/Users/david/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/transcrypt/modules/_weakref.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/transcrypt/modules/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/bin/_weakref.py
/Users/david/.virtualenvs/py3-data/bin/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/lib/python36.zip/_weakref.py
/Users/david/.virtualenvs/py3-data/lib/python36.zip/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/_weakref.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/lib-dynload/_weakref.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/lib-dynload/__javascript__/_weakref.mod.js
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_weakref.py
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/__javascript__/_weakref.mod.js
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/_weakref.py
/Users/david/.virtualenvs/py3-data/lib/python3.6/site-packages/__javascript__/_weakref.mod.js
Reactions are currently unavailable
Activity
dportabella commentedon Apr 12, 2017
I tried also on docker, with the same result:
JdeH commentedon Apr 17, 2017
Hi,
Unfortunately the 'copy' standard library is not yet supported by Transcrypt.
TS mostly relies on JS libs:
http://sterlicht.alwaysdata.net/transcrypt.org/docs/html/what_why.html#the-ecosystem-different-batteries
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
dportabella commentedon Apr 17, 2017
Ok, thanks.
do you plan to support the "collections" library?
JdeH commentedon May 12, 2017
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
harto commentedon Jan 14, 2018
@JdeH I'm interested in a port of the collections module too. Where's a good place to discuss the design of it?
JdeH commentedon Jan 14, 2018
@harto
I've opened #442 as a place to discuss this.
Kind regards
Jacques
JennaSys commentedon Mar 4, 2020
Revisiting this. I know
copyis 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 itimport copyIn 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.
JennaSys commentedon Aug 28, 2020
After getting a bit more experience with Transcrypt and re-reading this, I realized my previous post was already answered in that the Python
copylibrary itself is not implemented.Related to this though, I see there are
copyanddeepcopyfunctions that end up in the Transcrypt JS runtime module. However thatdeepcopyfunction 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 thedeepcopyin the Transcrypt runtime is to the Pythoncopy.deepcopyfunction, and if so are there known limitations of that one? Or am I just misunderstanding something?JennaSys commentedon Jul 6, 2024
copymodule withcopyanddeepcopyis currently added in dev_3.9.3 branch to be released in v3.9.3Need to do a bit more testing on it before releasing.