Skip to main content

自動從配置檔載入 Python 路徑到 sys.path

Project description

Path Loader

自動從配置檔載入 Python 路徑到 sys.path

Python Version License: MIT

安裝

pip install path-loader

快速開始

1. 建立配置檔

在專案根目錄建立 .pypath:

# .pypath
src
lib

2. 使用

Python 啟動時會自動載入:

# 直接 import 你的模組
import my_module

配置檔格式

# 支援註解

# 相對路徑 (相對於 .pypath 所在目錄)
src
lib/modules

# 絕對路徑
/usr/local/custom_lib
C:\Projects\Common

# 空白行會被忽略

手動控制

import path_loader

# 基本使用
path_loader.load_paths()

# 自訂配置檔名
path_loader.load_paths(config_names=['my_config.txt'])

# 從特定目錄開始搜尋
path_loader.load_paths(start_dir='/project/root')

# 只搜尋不載入
config = path_loader.find_pypath_file()
if config:
    paths = path_loader.parse_pypath_file(config)
    print(paths)

範例

專案結構

my_project/
├── .pypath          # 內容: src\nlib
├── src/
│   └── utils.py
├── lib/
│   └── helper.py
└── main.py

使用

# main.py
# 不需要任何額外程式碼,直接 import
from utils import my_function
from helper import HelperClass

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

path_loader-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

path_loader-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file path_loader-0.1.1.tar.gz.

File metadata

  • Download URL: path_loader-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for path_loader-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d21074324a39d316cd831a1a3ee7b1aa2a6ca9f01bc6754c25fc609612d39ad6
MD5 7a254a947f71b45048b3d22954f17baf
BLAKE2b-256 b4eb834d0b1edc5940b72d3575e804ddad7f612ba27aea991700f91a927ee790

See more details on using hashes here.

File details

Details for the file path_loader-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: path_loader-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for path_loader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e294a218c69ba576ea9053f48e8b42906ae86b8978cacf080e4056c3f09f887
MD5 4816cea4d1fbbb011fd934d0edd4de4e
BLAKE2b-256 b40e6159f8ece78807c478369b87211c5eeff22713afb4f76bf0662c888107e0

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