Skip to main content

module-path-manager

프로젝트의 내부 모듈들에서 간편하게 chdir와 sys.path를 설정할 수 있는 라이브러리

사용 예시

아래와 같은 디렉토리 구조의 프로젝트가 있다고 가정합니다.

project/
├── README.md
├── module1/
│   └── a.py
├── module2/
│   └── b.py
├── module3/
│   └── test/
│       └── c.py
└── main.py
  • 예시 1. main.py에서 a.py, b.py, c.py를 import 한다면 아래와 같이 사용할 것입니다.
# main.py
from module1 import a
from module2 import b
from module3.test import c
  • 예시 2. a.py에서 main.py, b.py, c.py를 import 하려면 어떻게 할까요?
    • main.py는 상위 디렉토리에 있습니다.
    • b.py는 상위 디렉토리에서 module2 디렉토리에 접근해야 합니다.
    • c.py는 상위 디렉토리에서 module3/test 디렉토리에 접근해야 합니다.
# a.py
import os, sys
sys.path.append('../')
os.chdir('../')

import main
from module2 import b
from module3.test import c
  • 예시 3. b.py에서 main.py, a.py, c.py를 import 하려면 위 예시와 유사한 방식으로 하면 됩니다.
# b.py
import os, sys
sys.path.append('../')
os.chdir('../')

import main
from module1 import a
from module3.test import c
  • 예시 4. 그렇다면 c.py에서 main.py, a.py, b.py를 import 하려면 어떻게 할까요?
    • main.py는 상위 디렉토리의 상위 디렉토리에 있습니다.
    • a.py는 상위 디렉토리의 상위 디렉토리에서 module1 디렉토리에 접근해야 합니다.
    • b.py는 상위 디렉토리의 상위 디렉토리에서 module2 디렉토리에 접근해야 합니다.
# c.py
import os, sys
sys.path.append('../../')
os.chdir('../../')

import main
from module1 import a
from module2 import b
  • 위의 예시들을 보면 모듈 간의 import가 복잡해지면서 코드가 길어지고 가독성이 떨어지는 문제가 있습니다.
  • 이러한 문제를 해결하기 위해 module-path-manager를 사용하면 아래와 같이 간단하게 import를 할 수 있습니다.
# main.py / a.py / b.py / c.py
import model_path_manager
module_path_manager.set(current_file=__file__, target_file='main.py', depth=3, syspath=True, chdir=True)

import main
from module1 import a
from module2 import b
from module3.test import c

Metadata

Release files for module-path-manager 0.0.1

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

Source distribution (sdist)

Source distribution for module-path-manager 0.0.1
File Size Uploaded Provenance
module_path_manager-0.0.1.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for module-path-manager 0.0.1
File Interpreter ABI Platform
module_path_manager-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / module_path_manager-0.0.1.tar.gz

Download URL module_path_manager-0.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ac0a2ec7dbc083bb26c84f26d6d19967106254e751b1c382d915bca8c33c6424
BLAKE2b-256 checksum
How to use checksums
82cfcac1ee3019d069f44e28295b61968af3bf0ddeede763864a82724b73c3d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / module_path_manager-0.0.1-py3-none-any.whl

Download URL module_path_manager-0.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6ed13367c9c39d7f8dc2e37aca1059af3b036834a1d592f74979c71a2234530
BLAKE2b-256 checksum
How to use checksums
d4dd6c7601d674d8df4e71a059ad030de4c9d74236749915f093ed79c354c6ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Security for module-path-manager 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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