amalgamate
amalgamate copied to clipboard
Feature Request: ability to amalgamate into single file
For purposes of distribution it's useful to be able amalgamate the package into a single file that someone can save locally and import.
Right now amalgamate comes pretty close because it produces two files __init__.py
and __amalgamate__.py
and the later can be used as single file distribution in most cases. The case when this doesn't work is when original package uses local package imports with aliases.
In other words imports like this
import .subpackage as subpackage
subpackage.function()
The reason this happens is that subpackages are registered as system packages as follows in __init__.py
sys.modules["subpackage"] = amalgamate
Instead this could be fixed by combining everything into single file and registering the package as follows
sys.modules["subpackage"] = sys.modules[__name__]
Thanks for opening this @yaroslavvb! I would certainly welcome this. It would probably be only a handful of lines to implement. However, a command line switch would also be needed to allow the user to request single-file mode or __amalgam__
mode.
I'd totally enjoy this feature, too! A single file-package can also by pyminified!
I second this request too with a little addition: amalgamate a script file with all its non-standard dependencies.