Created
June 1, 2025 00:27
-
-
Save yeiichi/6c9ea236aee135f1e079d862100abd17 to your computer and use it in GitHub Desktop.
Initialize and provide reusable constants and paths for various project subdirectories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# noinspection PyUnresolvedReferences | |
""" | |
This script initializes and provides reusable constants and paths | |
for various project subdirectories such as `src`, `config`, `data`, | |
`tests`, and `logs`. It uses the `pathlib` library to construct | |
platform-independent paths relative to the directory where this file resides | |
(assumed to be the project root). | |
Module Constants: | |
---------------- | |
- SRC_SUBDIR: Name of the source code subdirectory. | |
- CONFIG_SUBDIR: Name of the configuration files subdirectory. | |
- DATA_SUBDIR: Name of the data files subdirectory. | |
- TESTS_SUBDIR: Name of the tests subdirectory. | |
- LOGS_SUBDIR: Name of the logs subdirectory. | |
Module Variables: | |
----------------- | |
- PROJECT_ROOT_PATH: Path object representing the project root directory. | |
- SRC_PATH: Path object representing the `src` subdirectory path. | |
- CONFIG_PATH: Path object representing the `config` subdirectory path. | |
- DATA_PATH: Path object representing the `data` subdirectory path. | |
- TESTS_PATH: Path object representing the `tests` subdirectory path. | |
- LOGS_PATH: Path object representing the `logs` subdirectory path. | |
Example Usage: | |
-------------- | |
You can use this module to compute or access paths to various | |
subdirectories of your project. For example: | |
>>> from project_paths import SRC_PATH | |
>>> print(SRC_PATH) | |
/path/to/project/src | |
Running this script directly from the command line will print the | |
paths to the project root and subdirectories. | |
""" | |
from pathlib import Path | |
# Subdirectory names (as constants for reuse) | |
SRC_SUBDIR: str = 'src' | |
CONFIG_SUBDIR: str = 'config' | |
DATA_SUBDIR: str = 'data' | |
TESTS_SUBDIR: str = 'tests' | |
LOGS_SUBDIR: str = 'logs' | |
# Path to the directory where this file resides (assumed project root) | |
PROJECT_ROOT_PATH: Path = Path(__file__).resolve().parent | |
# Common subdirectories | |
SRC_PATH: Path = PROJECT_ROOT_PATH / SRC_SUBDIR | |
CONFIG_PATH: Path = PROJECT_ROOT_PATH / CONFIG_SUBDIR | |
DATA_PATH: Path = PROJECT_ROOT_PATH / DATA_SUBDIR | |
TESTS_PATH: Path = PROJECT_ROOT_PATH / TESTS_SUBDIR | |
LOGS_PATH: Path = PROJECT_ROOT_PATH / LOGS_SUBDIR | |
# Example usage | |
if __name__ == "__main__": | |
print("Project Root Path:", PROJECT_ROOT_PATH) | |
print("Source Code Path:", SRC_PATH) | |
print("Config Path:", CONFIG_PATH) | |
print("Data Path:", DATA_PATH) | |
print("Tests Path:", TESTS_PATH) | |
print("Logs Path:", LOGS_PATH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment