-
-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Currently the process for loading the file run the file through compile and then exec.
django-split-settings/split_settings/tools.py
Lines 111 to 114 in d7ca866
| 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
includecall are no longer present. They've been deleted in a previous build step. - Even if I use a workaround for issue 1, the
.pycfiles do not work with thecompile+execapproach.
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
optionalimplementation.include( optional("abc.py", "abc.pyc"), # ... )
-
Allowing
.pycfiles 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)