Skip to content

it fails on import copy #313

Closed
Closed

Description

@dportabella

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

Activity

  1. dportabella commented on Apr 12, 2017

    @dportabella
    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
    
  2. self-assigned this
    on Apr 17, 2017
  3. JdeH commented on Apr 17, 2017

    @JdeH
    Collaborator

    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

  4. dportabella commented on Apr 17, 2017

    @dportabella
    Author

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

  5. JdeH commented on May 12, 2017

    @JdeH
    Collaborator

    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

  6. harto commented on Jan 14, 2018

    @harto

    @JdeH I'm interested in a port of the collections module too. Where's a good place to discuss the design of it?

  7. JdeH commented on Jan 14, 2018

    @JdeH
    Collaborator

    @harto

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

    Kind regards
    Jacques

  8. JennaSys commented on Mar 4, 2020

    @JennaSys
    Collaborator

    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.

  9. JennaSys commented on Aug 28, 2020

    @JennaSys
    Collaborator

    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?

  10. assigned and unassigned on Jul 6, 2024
  11. JennaSys commented on Jul 6, 2024

    @JennaSys
    Collaborator

    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.

  12. linked a pull request that will close this issueDev 3.9.3 #876on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions