Skip to main content

import package_root # into your PYTHON_PATH

Project description

Package √Root

PyPI version Test

import package_root # into your PYTHONPATH

Stop appending your package root path to your Python path by hand like this:

from os.path import abspath, dirname, join
sys.path.insert(1, abspath(join(dirname(__file__), '..')))

It's annoying and error prone. Let us do it for you. <3

import package_root

How does this witchcraft work you ask?

We detect the file that called import package_root. We search until we find a parent directory without an __init__.py file. That's your package_root. We make it sys.path[1] because friends don't let friends mess with sys.path[0].

Still confused? Let's say you have the following setup:

your_awesome_pacakge/
    foo/
        __init__.py
        your_dope_module.py
        bar/
            __init__.py
            baz.ipynb
            baz.py
    .no_init_at_this_level

If you're in baz.ipynb or baz.py, we'll append your_awesome_package to your path so you can import whatever you want from your_awesome_package.

# baz.ipynb or baz.py
import package_root
import foo.your_dope_module # works!

Don't believe us? We have tests to prove it.

Important Notes

Installation

pip install package_root

Usage

import package_root # And nothing else

Contributing

Feel free to report bugs, but we won't accept feature requests since this package is intended to do one thing and do it well.

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

package_root-1.0.0.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

package_root-1.0.0-py3-none-any.whl (3.1 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