Currently the process for loading the file run the file through compile and then exec.
|
compiled_code = compile( # noqa: WPS421 |
|
to_compile.read(), included_file, 'exec', |
|
) |
|
exec(compiled_code, scope) # noqa: S102, WPS421 |
This works perfectly for .py files (thanks for the project, by the way, it is really awesome).
I have a project where the files are precompiled into .pyc during building the production version, and all .py files are deleted from the codebase.
This causes two issues:
- The names in the
include call are no longer present. They've been deleted in a previous build step.
- Even if I use a workaround for issue 1, the
.pyc files do not work with the compile + exec approach.
I would like to request the ability to load .pyc files by addressing both of these points.
-
Allowing scripts to have a fallback, that is only loaded if the file is not found. Maybe that can be built into the optional implementation.
include(
optional("abc.py", "abc.pyc"),
# ...
)
-
Allowing .pyc files to be loaded. I've done it locally using this.
import marshal
import types
with open(included_file, 'rb') as to_compile:
to_compile.seek(16)
compiled_code = marshal.load(to_compile)
if isinstance(compiled_code, types.CodeType):
exec(compiled_code, scope)
Currently the process for loading the file run the file through
compileand thenexec.django-split-settings/split_settings/tools.py
Lines 111 to 114 in d7ca866
This works perfectly for
.pyfiles (thanks for the project, by the way, it is really awesome).I have a project where the files are precompiled into
.pycduring building the production version, and all.pyfiles are deleted from the codebase.This causes two issues:
includecall are no longer present. They've been deleted in a previous build step..pycfiles do not work with thecompile+execapproach.I would like to request the ability to load
.pycfiles by addressing both of these points.Allowing scripts to have a fallback, that is only loaded if the file is not found. Maybe that can be built into the
optionalimplementation.Allowing
.pycfiles to be loaded. I've done it locally using this.