Skip to content
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

it fails on import copy #313

Closed
dportabella opened this issue Apr 12, 2017 · 9 comments · Fixed by #876
Closed

it fails on import copy #313

dportabella opened this issue Apr 12, 2017 · 9 comments · Fixed by #876

Comments

@dportabella
Copy link

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
@dportabella
Copy link
Author

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

@JdeH JdeH self-assigned this Apr 17, 2017
@JdeH
Copy link
Collaborator

JdeH commented 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
Copy link
Author

Ok, thanks.
do you plan to support the "collections" library?

@JdeH
Copy link
Collaborator

JdeH commented 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
Copy link

harto commented 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
Copy link
Collaborator

JdeH commented Jan 14, 2018

@harto

I've opened #442 as a place to discuss this.

Kind regards
Jacques

@JennaSys
Copy link
Collaborator

JennaSys commented Mar 4, 2020

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.

@JennaSys
Copy link
Collaborator

JennaSys commented 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 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?

@JennaSys
Copy link
Collaborator

JennaSys commented Jul 6, 2024

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.

@JennaSys JennaSys linked a pull request Jul 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants