Skip to main content

Inserts the nearest git repository root into sys.path.

Project description

Git root to sys.path

A small package that will allow running python scripts (which refer to each other) from any level of the git directory hierarchy.

This can be useful for debugging.

Comment: The root of a submodule is the git root also.

Why

Suppose our project contains many modules and packages in a hierarchical structure like this.

── src
    ├── pk1
    │   └── mod1  
    ├── pk2
    │   ├── mod2
    │   └── mod3
    └── submodule_pk
        ├── mod4
        └── mod5

In each module, we want to refer to other parts of the program via the full path in the git repository.

So something like this in the main repository (refers to main repository):

from src.pk1.mod1 import xyz

or in the main repository (refers to submodule):

from src.submodule_pk.mod4 import qwe

And also in submodule we want to refer to other parts of the submodule like this:

from mod4 import qwe

Because the submodule is in another context (from its point of view) the main repository also.


We also want to have test code close to what is being tested.

For example in mod3.py file (mod3 module):

from src.submodule_pk.mod4 import qwe
from src.pk1.mod1 import xyz

class M:
    def __init()__:
        ...
   
   def a() -> str:
        ...    
...

if __name__ == "__main__":
   
    # for simple test ....
   
    print(M().a())

And he also wants modules to be able to run as standalone scripts from anywhere.

cd src/pk2
python3 mod3.py

Or so that we can simply run them from a development environment (such as PyCharm, VC, etc.) by pressing the "Run" button.

Instalation

Pick one

pip install git+https://gitlab.com/ivo-marvan/git_root_to_syspath
pip install git_root_to_syspath

Usage

Put this line in the header of each file:

from git_root_to_syspath import agr; agr()

Or optionally:

from git_root_to_syspath import agr; PROJECT_ROOT = agr()

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

git_root_to_syspath-0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_root_to_syspath-0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file git_root_to_syspath-0.1.tar.gz.

File metadata

  • Download URL: git_root_to_syspath-0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.4 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for git_root_to_syspath-0.1.tar.gz
Algorithm Hash digest
SHA256 9344d3d814804ef0583e7e4221a96429281cf44b3d82c13036ddb648ad2e4a80
MD5 d4243a2e1afa2eb786e16064c925f11f
BLAKE2b-256 c18b1292abe125cea09d6af16fe0e9e35c7337592bc90913af54d615af6e3e65

See more details on using hashes here.

File details

Details for the file git_root_to_syspath-0.1-py3-none-any.whl.

File metadata

  • Download URL: git_root_to_syspath-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.4 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for git_root_to_syspath-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 799c0a4e682a308a2689ee0f71d9a5b37f5f0028e3613321e3c161814a66f528
MD5 c9ef609278a0b991383d1424c44572b3
BLAKE2b-256 e724b21dc119ad079609bdb75dbddb54702549dedc2491285184084cb6e1b8d6

See more details on using hashes here.

Supported by

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