Skip to main content

automagically install imports

Project description

Importation 🛸

automagically install missing imports

PyPI version

Is this a good idea? Probably not.

Should you use this? Probably not.

What is this?

importation hijacks the import keyword in Python to test if the module is importable, and auto-installs missing packages.

If you're in a virtual environment, it installs it to your current virtual environment. If not, it creates one at __pypackages__/importation, adds it to sys.path so packages are discoverable, and installs missing packages there.

It takes PEP-582 "Python local packages directory" one step further by resolving packages in __pypackages__ plus auto-installing to them.

How do I get it?

> python -m pip install importation --user

How do I use it?

Just import it.

The act of importing it has the side effect of hijacking Python's import system.

# example.py
import importation  # noqa: 401
import httpx

print("module resolved at", httpx.__file__)

Then

$ python test.py
# module resolved at /home/__pypackages__/importation/lib/python3.8/site-packages/httpx/__init__.py

To debug or view details of what it's doing set the IMPORTATION_VERBOSE environment variable:

$ IMPORTATION_VERBOSE=1 python test.py

Disclaimer

This has not been tested beyond this extremely simple example.

Credits

This package was inspired by PEP-582 and magicimport.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

importation-0.0.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

importation-0.0.1-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page