All Projects → facundobatista → pyempaq

facundobatista / pyempaq

Licence: GPL-3.0 License
A simple but powerful Python packer to run any project with any virtualenv dependencies anywhwere.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pyempaq

integration-test
ensure core packaging tools work well with each other
Stars: ✭ 15 (-28.57%)
Mutual labels:  packaging, virtualenv
Rpmvenv
RPM packager for Python virtualenv.
Stars: ✭ 128 (+509.52%)
Mutual labels:  packaging, virtualenv
Pipenv
Python Development Workflow for Humans.
Stars: ✭ 22,542 (+107242.86%)
Mutual labels:  packaging, virtualenv
Hatch
A modern project, package, and virtual env manager for Python
Stars: ✭ 2,268 (+10700%)
Mutual labels:  packaging, virtualenv
pip-deepfreeze
A simple pip freeze workflow for Python application developers
Stars: ✭ 21 (+0%)
Mutual labels:  packaging, virtualenv
Distillery
Every alchemist requires good tools, and one of the greatest tools in the alchemist's disposal is the distillery. The purpose of the distillery is to take something and break it down to its component parts, reassembling it into something better, more powerful. That is exactly what this project does - it takes your Mix project and produces an Erlang/OTP release, a distilled form of your raw application's components; a single package which can be deployed anywhere, independently of an Erlang/Elixir installation. No dependencies, no hassle.
Stars: ✭ 2,869 (+13561.9%)
Mutual labels:  distribution, packaging
Fades
fades is a system that automatically handles the virtualenvs in the cases normally found when writing scripts and simple programs, and even helps to administer big projects.
Stars: ✭ 182 (+766.67%)
Mutual labels:  packaging, virtualenv
distribution
Siddhi streaming runtime and tooling distribution
Stars: ✭ 22 (+4.76%)
Mutual labels:  distribution, packaging
whey
A simple Python wheel builder for simple projects.
Stars: ✭ 17 (-19.05%)
Mutual labels:  distribution, packaging
coindis
Bitcoin faucet supporting service without time limit.
Stars: ✭ 23 (+9.52%)
Mutual labels:  distribution
openrestaurant
Everything you need for your restaurant website.
Stars: ✭ 25 (+19.05%)
Mutual labels:  distribution
tos-live
Tom os - An arch based distribution
Stars: ✭ 17 (-19.05%)
Mutual labels:  distribution
siddhi-operator
Operator allows you to run stream processing logic directly on a Kubernetes cluster
Stars: ✭ 16 (-23.81%)
Mutual labels:  distribution
gradle-izpack-plugin
Gradle plugin that provides support for packaging applications for the Java platform via IzPack.
Stars: ✭ 60 (+185.71%)
Mutual labels:  packaging
begin-with-init.vim
Minimal neovim distribution as init.vim
Stars: ✭ 32 (+52.38%)
Mutual labels:  distribution
ansible-role-pip
Ansible Role - Pip (for Python)
Stars: ✭ 147 (+600%)
Mutual labels:  packaging
jasper
🧳 Single-binary packaging for Ruby applications that supports native and Wasm targets
Stars: ✭ 29 (+38.1%)
Mutual labels:  packaging
pathofexile-flatpak
Path of Exile Flatpak
Stars: ✭ 11 (-47.62%)
Mutual labels:  packaging
user login and register
user login and register system in django
Stars: ✭ 43 (+104.76%)
Mutual labels:  virtualenv
vania
A module which fairly distributes a list of arbitrary objects among a set of targets, considering weights.
Stars: ✭ 75 (+257.14%)
Mutual labels:  distribution

PyEmpaq

A simple but powerful Python packer to run any project with any virtualenv dependencies anywhwere.

With PyEmpaq you can convert any Python project (see limitations below) into a single .pyz file with all the project's content packed inside.

Packing is super simple, see this demo:

pack-demo

That single file is everything that needs to be distributed. When the final user executes it, the original project will be expanded, its dependencies installed in a virtualenv, and then executed. Note that no special permissions or privileges are required, as everything happens in the user environment.

See that in action:

run-demo

Both the packaging and the execution are fully multiplatorm. This means that you can pack a project in Linux, Windows, Mac or whatever, and it will run ok in Linux, Windows, Mac or whatever. The only requirement is Python to be already installed.

You can try yourself some packed with PyEmpaq examples, very easy, just download any of these files and run it with Python:

logo

You can install pyempaq directly from PyPI; see instructions below.

PyEmpaq is security friendly, there is nothing obscure or secretly shipped when you distribute your project with it: anybody can just open the pyz file (it's just a ZIP) and inspect it.

Limitations:

There are some limitations:

  • Only Python >= 3.7 is supported

  • Only Linux, Windows and Mac is supported

  • Only pip-installable dependencies are supported (from PyPI or whatever).

  • Only dependencies that are pure Python or provide wheels are supported.

All this means that the most majority of the projects could be packed and run by PyEmpaq. If you have any ideas on how to overcome any of these limitations, let's talk!

How does this work?

There are two phases: packing and execution.

The packing phase is executed by the project developer, only once, before distribution. It's a simple step where the developer runs PyEmpaq indicating all needed info, and PyEmpaq will produce a single <projectname>.pyz file. That's all, and that only file is what is needed for distribution.

In this packing phase, PyEmpaq builds the indicated packed file, putting inside:

  • the payload project, with all the indicated modules and binary files (currently everything from the project, but this will be improved in the future)

  • an unpacker script from PyEmpaq, which will be run during the execution phase

  • few more stuff: some needed infrastructure details for the .pyz to run correctly

After packing, the developer will distribute the packed file, final users will download/receive/get it, and execute it.

In the execution phase all that needs to be done by the final user is to run it using Python, which can be done from the command line (e.g. python3 supergame.pyz) or by doing double click from the file explorer in those systems that relate the .pyz extension to Python (e.g. Windows).

In this execution phase, the unpacker script put by PyEmpaq inside the packed file will be run, running the following steps:

  • check if the needed setup exists from a previous run; if yes, it will just run the payload project with almost no extra work; otherwise...

  • create a directory in the user data dir, and expand the .pyz file there

  • create a virtualenv in that new directory, and install all the payload's project dependencies

  • run the payload's project inside that virtualenv

The verification that the unpacker does to see if has a reusable setup from the past is based on the .pyz timestamp; if it changed (a new file was distributed), a new setup will be created and used.

Command line options

There is one mandatory parameter:

  • source: it needs to point the configuration file or to the directory where the configuration will be located (it will be searched by its default name pyempaq.yaml).

Examples:

  • pyempaq .

  • pyempaq /data/project/

  • pyempaq ~/repo/proj/config.yaml

Note: in the future we will be able to control verbosity, we're not there yet.

The configuration file

All the information that PyEmpaq needs to pack a project comes from a configuration file, which the developer would normally have in the project itself.

The following is the structure of the pyempaq.yaml configuration file:

  • name [mandatory]: the name of the project.

  • basedir [optional, defaults to where the configuration file is located]: the project's base directory.

  • exec [mandatory]: the section where is defined the information to execute the project once unpacked; it holds different subkeys (some subkeys are marked with †: ONE of those keys must be present, but only ONE):

    • script [†]: the filepath of the python script to run; when unpacking PyEmpaq will do python3 SCRIPT.

    • module [†]: the name of the module to invoke; when unpacking PyEmpaq will do python3 -m MODULE.

    • entrypoint [†]: freeform, as a list of strings; when unpacking PyEmpaq will only insert the proper python3 at the beginning: python3 STR1 STR2 ....

    • default-args [optional]: the default arguments to be passed to the script/module/entrypoint (if not overriden when the distributed .pyz is executed); note that this option is not available yet.

  • requirements: a list of filepaths pointing to the requirement files with pip-installable dependencies.

  • dependencies: a list of strings to directly specify packages to be installed by pip without needing to have a requirement file.

All specified filepaths must exist inside the project and must be relative (to the project's base directory), with the exception of basedir itself which can be absolute or relative (to the configuration file location).

The following are examples of different configuration files (which were the ones used to build the packed examples mentioned before):

How to install PyEmpaq

Directly from PyPI:

pip install --user --upgrade --ignore-installed pyempaq

It's handy to install it using pipx, if you have it:

pipx install pyempaq

If you have fades you don't even need to install pyempaq, just run it:

fades -d pyempaq -x pyempaq

In the future there will be more ways to install it. Please open an issue if you desire an installation method (extra points if you specify how), thanks!

Try packing an example project

PyEmpaq sources come with a small example project if you want to play a little packing it. Just a couple of dir/files under examples/srcproject:

  • a src and media, with stuff to be imported and accessed.

  • a pyempaq.yaml with the configuration for PyEmpaq.

  • a ep.py file which is the project's entrypoint; all it does is to inform it started, import the internal module, access the media files, and use the declared dependency, reporting every step.

This explores most of the needs of any project. You can try this example, and surely after you will be ready to actually pack any other project you want.

So, let's pack the example source project. As you're working with the PyEmpaq project itself (as you're packing its example), you don't really need to have it installed yet. In that case, if you have fades installed is super easy:

fades -r requirements.txt -m pyempaq examples/srcproject/

Otherwise, you would need to create and use a virtual environment:

python3 -m venv env
source env/bin/activate
pip install -r requirements
python3 -m pyempaq examples/srcproject/

After running that command, you will see a pyempaq-example.pyz file. That is the whole project encoded in a single file.

At this point you may move that pyempaq-example.pyz to another directory, or to another machine, even that other machine having another operating system.

Then, try it:

python3 pyempaq-example.pyz

You should see the project's reportings that we mentioned above (note: these lines will be surrounded by debug ones that will be hidden by default in the future):

Hello world
Code access ok .../pyempaq/projectname-20210722013526/orig/src/foo.py
Media access ok
Module requests imported .../pyempaq/projectname-20210722013526/venv/lib/python3.8/site-packages/requests/__init__.py

This shows that what you've run actually started, accessed the internal modules and other files, and imported correctly a custom-installed dependency.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].