This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add a method on importlib.SourceLoader for creating bytecode file format/container
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: BreamoreBoy, asvetlov, brett.cannon, jcea
Priority: normal Keywords:

Created on 2012-11-17 16:00 by brett.cannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg175762 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-11-17 16:00
With issue #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 #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.
msg222782 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-11 19:24
@Brett as #15627 is in would you like to follow up on this.
msg223425 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-07-18 18:50
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.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60698
2014-07-18 18:50:42brett.cannonsetstatus: open -> closed
resolution: rejected
messages: + msg223425
2014-07-12 13:40:03brett.cannonsetassignee: brett.cannon
versions: + Python 3.5, - Python 3.4
2014-07-11 19:24:05BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222782
2012-12-03 15:37:10asvetlovsetnosy: + asvetlov
2012-11-26 17:12:05jceasetnosy: + jcea
2012-11-17 16:05:52brett.cannonsettitle: Add a ethod on importlib.SourceLoader for creating bytecode file format/container -> Add a method on importlib.SourceLoader for creating bytecode file format/container
2012-11-17 16:05:36brett.cannonsettitle: Method on importlib.SourceLoader for creating bytecode file format/container -> Add a ethod on importlib.SourceLoader for creating bytecode file format/container
2012-11-17 16:00:17brett.cannoncreate