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 details)

Uploaded Source

File details

Details for the file root_relative-0.28.tar.gz.

File metadata

  • Download URL: root_relative-0.28.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for root_relative-0.28.tar.gz
Algorithm Hash digest
SHA256 105bb3809b9e1cf7a938081f994637ea8be6cb2b514efb2110ef422a46df5131
MD5 7aa89202edde908420b36dc6a8ab938c
BLAKE2b-256 b0460741e8f1c6e0052657b32c0a3254c5b6a75c77c06b3d78c4871816a51759

See more details on using hashes here.

Supported by

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