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

py_compile.compile: AttributeError on importlib.utils #80814

Closed
dataflake mannequin opened this issue Apr 15, 2019 · 4 comments
Closed

py_compile.compile: AttributeError on importlib.utils #80814

dataflake mannequin opened this issue Apr 15, 2019 · 4 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir

Comments

@dataflake
Copy link
Mannequin

dataflake mannequin commented Apr 15, 2019

BPO 36633
Nosy @tirkarthi, @dataflake

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-04-15.14:29:56.716>
created_at = <Date 2019-04-15.13:51:34.526>
labels = ['3.7', 'library']
title = 'py_compile.compile: AttributeError on importlib.utils'
updated_at = <Date 2019-04-15.14:29:56.715>
user = 'https://github.com/dataflake'

bugs.python.org fields:

activity = <Date 2019-04-15.14:29:56.715>
actor = 'xtreak'
assignee = 'none'
closed = True
closed_date = <Date 2019-04-15.14:29:56.716>
closer = 'xtreak'
components = ['Library (Lib)']
creation = <Date 2019-04-15.13:51:34.526>
creator = 'dataflake'
dependencies = []
files = []
hgrepos = []
issue_num = 36633
keywords = []
message_count = 4.0
messages = ['340271', '340275', '340276', '340277']
nosy_count = 2.0
nosy_names = ['xtreak', 'dataflake']
pr_nums = []
priority = 'normal'
resolution = 'third party'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue36633'
versions = ['Python 3.6', 'Python 3.7']

@dataflake
Copy link
Mannequin Author

dataflake mannequin commented Apr 15, 2019

The following code in py_compile.compile fails (tested on 3.6.6 and 3.7.3) with tracebacks that end like the one shown at the bottom. There's an AttributeError about importlib.utils.

"""
if cfile is None:
if optimize >= 0:
optimization = optimize if optimize >= 1 else ''
cfile = importlib.util.cache_from_source(file,
optimization=optimization)
else:
cfile = importlib.util.cache_from_source(file)
"""

Sample tail end of traceback:

"""
File "/Users/jens/src/.eggs/Chameleon-3.6-py3.7.egg/chameleon/template.py", line 243, in _cook
cooked = self.loader.build(source, filename)
File "/Users/jens/src/.eggs/Chameleon-3.6-py3.7.egg/chameleon/loader.py", line 177, in build
py_compile.compile(name)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/py_compile.py", line 130, in compile
cfile = importlib.util.cache_from_source(file)
AttributeError: module 'importlib' has no attribute 'util'
"""

@dataflake dataflake mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Apr 15, 2019
@tirkarthi
Copy link
Member

Can you please add a simplified script to reproduce this and possibly without any external dependencies? Looking at the traceback it seems to come from the project chameleon at https://github.com/malthe/chameleon/blob/983877e628a75f42c473cb2ea2350fb0727eb85b9/src/chameleon/loader.py#L177 . The file seems standalone without some helper functions from utils file.

@dataflake
Copy link
Mannequin Author

dataflake mannequin commented Apr 15, 2019

Thank you for the prompt reply.

It turns out this is not a bug in py_compile. Other code we use imports importlib.util briefly for a quick check at module level and then deletes it, also at module scope. Removing the deletion fixes the issue.

Thanks again and apologies!

@tirkarthi
Copy link
Member

No problem, closing the issue.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant