Smoosh Python modules into one big one.
Project description
python-combiner
A command-line tool to compile Python files into one ginormous one, with plugin support and more.
Command-line usage
I think you can install it with pip since it's on PyPi, but no promises.
usage: python-combiner [-h] -i INPUT [-o [OUTPUT]] [--ignore-imports IGNORE_IMPORTS [IGNORE_IMPORTS ...]] [--remove-imports REMOVE_IMPORTS [REMOVE_IMPORTS ...]] [-p PRELUDE]
[-c DEFINE_CONSTANT DEFINE_CONSTANT] [-d DEFINE] [-m | --minify | --no-minify] [-j | --json | --no-json] [-t | --time | --no-time]
[--docstring | --no-docstring] [--module-hash-length MODULE_HASH_LENGTH] [--export-dictionary-mode {dict,munch,class,class_instance}]
[--export-names-mode {locals,static}]
Compiles/merges Python files.
options:
-h, --help show this help message and exit
-i INPUT, --input INPUT
the input file, can be - for stdin
-o [OUTPUT], --output [OUTPUT]
the output file. Defaults to stdout
--ignore-imports IGNORE_IMPORTS [IGNORE_IMPORTS ...]
modules for which to ignore transforming imports for (i.e., leave them untouched)
--remove-imports REMOVE_IMPORTS [REMOVE_IMPORTS ...]
modules for which to remove imports for
-p PRELUDE, --prelude PRELUDE
some Python code to insert at the top of the file. must be well-formed parsable Python code
-c DEFINE_CONSTANT DEFINE_CONSTANT, --define-constant DEFINE_CONSTANT DEFINE_CONSTANT
defines one compile-time constant as a string. use some name that you're sure won't collide with any in your code, i.e. __MY_CONSTANT__
-d DEFINE, --define DEFINE
equivalent to defining a constant to be 1 using --define-constant.
-m, --minify, --no-minify
minifies the result
-j, --json, --no-json
outputs messages as json
-t, --time, --no-time
puts the time at the top of the generated code. --no-time for deterministic builds (default: True)
--docstring, --no-docstring
puts a generated docstring at the top of the module. added by default (default: True)
--module-hash-length MODULE_HASH_LENGTH
the length of the hash used for making modules unique
--export-dictionary-mode {dict,munch,class,class_instance}
the method that export dictionaries are converted to dot-accessible objects
--export-names-mode {locals,static}
how module exports are determined. use 'locals' for compatibility with existing code. forced to 'static' if --export-dictionary-mode is set to 'class' or
'class_instance'
Library usage
import python_compiler
python_compiler.Compiler(
source=input(),
path="/path/to/source/file",
options=python_compiler.CompilerOptions(
# ... (see docstring)
plugins=[
# Plugins
python_compiler.plugins.MinifyPlugin()
]
)
)
For more examples, see the CLI source code for
example usage. Note that path does not need to be a real path, but it's used
for import resolution. The library is mostly documented using docstrings, so
just read the source code for more help.
Plugins
Built-in plugins
Built-in plugins can be imported from the python-compiler.plugins module. See
the docstrings for usage information.
MinifyPlugin
Uses python-minifier to minify the resulting code after bundling is performed.
This can reduce the size of the resulting code by a factor of 3 or more,
depending on the input.
ConstantsPlugin
Dynamically replaces variable names with content at compile-time. Similar to
#DEFINEs if you're using the C preprocessor.
PreludePlugin
An easy way to add a snippet of code at the beginning of the output.
Plugin authoring
Plugins must inherit from the base Plugin class. An
example plugin might go something like this:
class MyPlugin(python_compiler.plugin.Plugin):
def hook_module(self, path, module):
module = my_transformation(module)
return module
There are a couple available hooks as of this writing:
hook_module
A hook run before name translation is performed and modules are bundledhook_module_post_transform
A hook run after name translation is performed but before modules are bundledhook_import
A hook run on all imports a module importshook_import_resolution
A hook run during the module resolution step. It can be used to define "virtual modules".hook_output
A hook called just prior to the end of code generation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_combiner-0.3.0.tar.gz.
File metadata
- Download URL: python_combiner-0.3.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d800553f3551d983d5818a978b65d0ba71aef0065079c1d66069b54560b06be
|
|
| MD5 |
894f07bdf273298fd26c2111e17c4569
|
|
| BLAKE2b-256 |
ba33307be901dbe5546b8d12240e2fa0796288613a6f285ad39e9ec9bbcbb1f2
|
Provenance
The following attestation bundles were made for python_combiner-0.3.0.tar.gz:
Publisher:
publish.yml on zabackary/python-combiner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_combiner-0.3.0.tar.gz -
Subject digest:
7d800553f3551d983d5818a978b65d0ba71aef0065079c1d66069b54560b06be - Sigstore transparency entry: 173458414
- Sigstore integration time:
-
Permalink:
zabackary/python-combiner@02227c4d631437a4360baebf2162988baaaeeda0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/zabackary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02227c4d631437a4360baebf2162988baaaeeda0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_combiner-0.3.0-py3-none-any.whl.
File metadata
- Download URL: python_combiner-0.3.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
756f69dc45d4e976cad5b1d57fe4cdd97ca92f4c34585dd9901d852200de0f1c
|
|
| MD5 |
4b82243e31905bf2ca0e6d49100b1df3
|
|
| BLAKE2b-256 |
9b87291e9be1da5a1db3c6e968b6cb6ca0e938e1f02df01b0142e58ec634cfd6
|
Provenance
The following attestation bundles were made for python_combiner-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on zabackary/python-combiner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_combiner-0.3.0-py3-none-any.whl -
Subject digest:
756f69dc45d4e976cad5b1d57fe4cdd97ca92f4c34585dd9901d852200de0f1c - Sigstore transparency entry: 173458415
- Sigstore integration time:
-
Permalink:
zabackary/python-combiner@02227c4d631437a4360baebf2162988baaaeeda0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/zabackary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02227c4d631437a4360baebf2162988baaaeeda0 -
Trigger Event:
push
-
Statement type: