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

Add a method on importlib.SourceLoader for creating bytecode file format/container #60698

Closed
brettcannon opened this issue Nov 17, 2012 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@brettcannon
Copy link
Member

BPO 16494
Nosy @brettcannon, @jcea, @asvetlov

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 = 'https://github.com/brettcannon'
closed_at = <Date 2014-07-18.18:50:42.350>
created_at = <Date 2012-11-17.16:00:17.112>
labels = ['type-feature', 'library']
title = 'Add a method on importlib.SourceLoader for creating bytecode file format/container'
updated_at = <Date 2014-07-18.18:50:42.349>
user = 'https://github.com/brettcannon'

bugs.python.org fields:

activity = <Date 2014-07-18.18:50:42.349>
actor = 'brett.cannon'
assignee = 'brett.cannon'
closed = True
closed_date = <Date 2014-07-18.18:50:42.350>
closer = 'brett.cannon'
components = ['Library (Lib)']
creation = <Date 2012-11-17.16:00:17.112>
creator = 'brett.cannon'
dependencies = []
files = []
hgrepos = []
issue_num = 16494
keywords = []
message_count = 3.0
messages = ['175762', '222782', '223425']
nosy_count = 4.0
nosy_names = ['brett.cannon', 'jcea', 'asvetlov', 'BreamoreBoy']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'test needed'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue16494'
versions = ['Python 3.5']

@brettcannon
Copy link
Member Author

With issue bpo-15031 providing a way to take a bytecode file and get a code object out of it, there should probably be a comparable method that takes a code object and a path stats dict and returns the bytes to write out to a file.

This could also be a slight performance win for subclasses of SourceLoader which can read bytecode files but not write them (e.g. zip files where the cost of modifying a zip file is too high). That way the method could raise NotImplementedError (or return None) to signify it doesn't want anything written out by SourceLoader.get_code() and thus skip the entire step of preparing the bytecode file bytes instead of what happens now where set_data() raises NotImplementedError after the whole set of bytes is constructed.

More importantly, it would clean up py_compile once issue bpo-15627 is in with an 'optimize' flag as py_compile.compile() would essentially become source = loader.get_source(...); code = loader.compile_source(source, optimize=...); pyc_bytes = loader.create_bytecode_file(code, loader.path_stats(...)). Otherwise get_code() will need to grow an 'optimize' flag and that doesn't seem necessary.

@brettcannon brettcannon added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 17, 2012
@brettcannon brettcannon changed the title Method on importlib.SourceLoader for creating bytecode file format/container Add a ethod on importlib.SourceLoader for creating bytecode file format/container Nov 17, 2012
@brettcannon brettcannon changed the title Add a ethod on importlib.SourceLoader for creating bytecode file format/container Add a method on importlib.SourceLoader for creating bytecode file format/container Nov 17, 2012
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Jul 11, 2014

@brett as bpo-15627 is in would you like to follow up on this.

@brettcannon brettcannon self-assigned this Jul 12, 2014
@brettcannon
Copy link
Member Author

I think I want to keep bytecode files as optimizations as much as possible, so exposing anything that explicitly writes them is just going to lead to headaches.

@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
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant