Skip to main content

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

Metadata

Release files for root-relative 0.28

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for root-relative 0.28
File Size Uploaded
root_relative-0.28.tar.gz 3.3 kB Details

Release files / root_relative-0.28.tar.gz

Download URL root_relative-0.28.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
105bb3809b9e1cf7a938081f994637ea8be6cb2b514efb2110ef422a46df5131
BLAKE2b-256 checksum
How to use checksums
b0460741e8f1c6e0052657b32c0a3254c5b6a75c77c06b3d78c4871816a51759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.28 This release

1 release file

0.27

1 release file

0.26

1 release file

0.25

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page