Skip to main content

Automatically add parent directories to sys.path in Python

Project description

📌 addpath 패키지 README (Markdown 형식, 한글 버전)

📢 이 패키지는 Python에서 상위 디렉토리를 자동으로 sys.path에 추가하여, 불필요한 sys.path.insert() 호출을 줄이는 것을 목표로 합니다.

# 📌 addpath - Python에서 자동으로 상위 디렉토리를 추가하는 패키지

## 🚀 소개
`addpath`는 Python에서 **상위 디렉토리를 자동으로 `sys.path`에 추가**하는 유틸리티 패키지입니다.  
더 이상 `sys.path.insert(0, "..")` 같은 코드를 반복해서 작성할 필요가 없습니다!

## 📌 설치 방법
PyPI에서 바로 설치할 수 있습니다.

```sh
pip install addpath

또는 GitHub에서 직접 설치할 수도 있습니다.

pip install git+https://github.com/noggong/addpath.git

🚀 사용법

1️⃣ 기본 사용법

import addpath

# 현재 스크립트의 상위 디렉토리를 sys.path에 추가
addpath.add_parent_path()

이제 상위 디렉토리에 있는 모듈을 바로 import할 수 있습니다!

2️⃣ 특정 레벨의 상위 디렉토리 추가

기본적으로 add_parent_path() 함수는 현재 실행 중인 파일의 1단계 상위 디렉토리를 sys.path에 추가합니다.
그러나, 더 상위 디렉토리를 추가하고 싶다면 levels 값을 조정하면 됩니다.

# 상위 디렉토리 2단계 추가
addpath.add_parent_path(levels=2)

이제 두 단계 위에 있는 패키지도 import할 수 있습니다.


📌 예제 프로젝트 구조

my_project/
│── main.py
│── src/
│   │── my_module.py

📌 예제 코드 (src/my_module.py)

def hello():
    return "안녕하세요! addpath를 사용하면 편리해요."

📌 main.py에서 my_module.py를 import하는 방법

import addpath
addpath.add_parent_path()

import my_module
print(my_module.hello())  # "안녕하세요! addpath를 사용하면 편리해요."

더 이상 sys.path.insert()를 반복해서 추가할 필요가 없습니다!


📌 자동으로 sys.path를 설정해야 하는 경우

  • 프로젝트 구조가 복잡한 경우
  • 테스트 코드에서 부모 디렉토리의 모듈을 불러와야 할 때
  • Jupyter Notebook에서 외부 모듈을 쉽게 불러오고 싶을 때
  • Python 스크립트 실행 시 불필요한 sys.path.append() 코드 없이 실행하고 싶을 때

🚀 기능 정리

add_parent_path(levels=1) → 현재 디렉토리의 levels만큼 상위 디렉토리를 sys.path에 추가
pip install addpath → 어디서든 간편하게 설치 후 사용 가능
✔ Python 3.6 이상 지원 🚀


📌 라이선스

이 프로젝트는 MIT 라이선스로 제공됩니다. 자유롭게 사용 및 수정할 수 있습니다.


📌 기여 방법

addpath 프로젝트에 기여하고 싶다면, GitHub에서 Fork 후 PR을 보내주세요! 🚀

git clone https://github.com/yourusername/addpath.git
cd addpath
pip install -e .

이제 개발 환경에서 addpath를 테스트하고 개선할 수 있습니다. 🚀🔥


📌 이제 Python 프로젝트에서 sys.path 문제를 간단하게 해결하세요! 🚀


✅ **Markdown 문법이 적용된 README로, 바로 GitHub이나 PyPI에서 사용 가능합니다!** 🚀🔥

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

addpath-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

addpath-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file addpath-0.1.0.tar.gz.

File metadata

  • Download URL: addpath-0.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for addpath-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83d3b4312a330c80d59b40cad5aaef6930a51b899bd54d71d9b8f8c56a150b38
MD5 8d5141cc48b837ab402ffe5449f82e6c
BLAKE2b-256 2413a569d31d0cf122a1beaa6a10419dab7cbf3d9e9aa6ab77b9230884216aba

See more details on using hashes here.

File details

Details for the file addpath-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: addpath-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for addpath-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a607d507a007f5d73bf04b7f74fb95a29a932bd42385d702f2703fc050edd484
MD5 2d956aff603218181d274c8d62e57928
BLAKE2b-256 a53d37b8447a816eacfcb821642268ab91bfb1b6d33a3d3c9ac5ff1effb2d093

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