amalgamate icon indicating copy to clipboard operation
amalgamate copied to clipboard

Feature Request: ability to amalgamate into single file

Open yaroslavvb opened this issue 8 years ago • 3 comments

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__]

yaroslavvb avatar Aug 16 '16 20:08 yaroslavvb

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.

scopatz avatar Aug 21 '16 21:08 scopatz

I'd totally enjoy this feature, too! A single file-package can also by pyminified!

operatorequals avatar Dec 21 '17 14:12 operatorequals

I second this request too with a little addition: amalgamate a script file with all its non-standard dependencies.

eadmaster avatar Apr 20 '21 01:04 eadmaster