indygreg / PyOxidizer

A modern Python application packaging and distribution tool
Mozilla Public License 2.0
5.4k stars 234 forks source link

Packaging custom Python applications #258

Open fgadaleta opened 4 years ago

fgadaleta commented 4 years ago

Is there a way/tutorial to package custom/local Python applications (that eventually depend on other modules usually installed from pip and requirements.txt file) ?

indygreg commented 4 years ago

Yes. PythonDistribution Starlark types have various methods to run pip, gather resources from virtualenvs, etc. See https://pyoxidizer.readthedocs.io/en/stable/config_api.html#pythondistribution-pip-install-args-extra-envs and the sections below it.

We could probably do with more examples outside of the low-level config API documentation.

fgadaleta commented 4 years ago

Yes, I was following that Documentation and setup.py fails. I wonder what I am doing wrong. My config is

def make_exe(dist):
    python_config = PythonInterpreterConfig(
        run_module="black",
        sys_paths=["$ORIGIN/lib"],
    )

    return dist.to_python_executable(
        name="black",
        config=python_config,
        extension_module_filter='all',
        include_sources=True,
        include_resources=False,
        include_test=False,
    )

def make_install(dist, exe):
    files = FileManifest()
    files.add_python_resource(".", exe)
    files.add_python_resources("lib", dist.pip_install(["black==19.3b0"]))
    files.add_python_resources("lib", dist.setup_py_install(package_path="/home/frag/Documents/myapp-python"))
    return files

register_target("python_dist", make_python_dist)
register_target("exe", make_exe, depends=["python_dist"])
register_target("install", make_install, depends=["python_dist", "exe"], default=True)

resolve_targets()

and the error:

...

error: Setup script exited with error: SandboxViolation: open('/tmp/pyoxidizer-setup-py-install.jFzNZGajbPW3/pyoxidizer-build-state/ciso8601.cpython-37m-x86_64-linux-gnu.so', 'wb') {}

The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.

This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand.  Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.

error[SETUP_PY_ERROR]: error running setup.py
  --> pyoxidizer.bzl:31:38
   |
31 |     files.add_python_resource("lib", dist.setup_py_install(package_path="/home/frag/Documents/myapp-python"))
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ setup_py_install()

error: error running setup.py

Of course myapp-python contains a setup.py that is installed successfully on a regular Python interpreter via python setup.py install