Skip to main content

Module that allow to launch python module without requirements to start from working dir

Project description

Tool for running CWD-agnostic Python scripts.

With this module you can run your script from any project nested folder without breaking your imports (including relative imports).

pip install root-relative
python -m root_relative package1.module1

This line will try to find the module automatically and detect the project root folder based on the module name provided. After that the CWD is automatically changed and the module is run as-a-module from the project root.

Also, there is a fix for relative import uncertainty.

If there a/b/c/d and a/b are both added to the sys.path. As a result, if you have a module inside a/b/c/d - you will have two options to import this module

import a.b.c.d.module
# or 
import c.d.module

The both options will import the module but relative imports will work differently for them.

In the first case you can easily use

from ... import another_module

but for the second case you'll have

ImportError: attempted relative import beyond top-level package

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

root_relative-0.28.tar.gz (3.3 kB view hashes)

Uploaded Source

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