python tool to solve many issues with relative paths and imports in your complex framework.
Project description
pydtl-relativepath
pydtl-relativepath tool from pydtl community can be used to solve many issues that occurs with relative paths and imports from various modules in your complex framework.
🔍 Features
- Convert Relative Paths to Absolute: Easily convert relative paths to absolute paths based on the current working directory or the current file's directory.
- PathLib Compatibility: Seamlessly works with PathLib, allowing for modern path manipulations.
- Customizable Path Construction: Adjust path construction through parameters like
parent_dir_jump
to navigate through directory structures. - Error Handling: Provides clear error messages for invalid inputs, such as incorrect
relative_type
values orparent_dir_jump
configurations.
🔧 Installation
To install pydtl-relativepath
, run the following command in your terminal:
pip install pydtl-relativepath
💻 Usage Examples
Convert Path Relative to Working Directory
To convert a path relative to the current working directory into an absolute path:
from pydtl_relativepath import rel2abs, RelativePathType
path = rel2abs("README.md", relative_type=RelativePathType.RELATIVE_TO_WORKING_DIRECTORY)
print(path) # Outputs the absolute path to README.md
Convert Path Relative to Current File's Directory
To convert a path relative to the current file's directory:
from pydtl_relativepath import rel2abs, RelativePathType
path = rel2abs("..", "README.md", relative_type=RelativePathType.RELATIVE_TO_CURRENT_FILE)
print(path) # Outputs the absolute path to README.md located one directory up from the current file
Using parent_dir_jump to Navigate Directories
To navigate up or down the directory structure while converting paths:
from pydtl_relativepath import rel2abs, RelativePathType
# Navigate up one directory from the current file's location
path = rel2abs("README.md", relative_type=RelativePathType.RELATIVE_TO_CURRENT_FILE, parent_dir_jump=-1)
print(path) # Outputs the absolute path to README.md located one directory up
Handling Errors
The package is designed to raise informative errors for invalid inputs:
from pydtl_relativepath import rel2abs, RelativePathType
try:
path = rel2abs("README.md", relative_type="invalid_type")
except ValueError as e:
print(e) # Will print an error message regarding the invalid relative_type
🤝 Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues to improve the package or add new features.
See our Contribution Guide for more details.
📜 License
pydtl-relativepath is released under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydtl_relativepath-0.2.0.tar.gz
.
File metadata
- Download URL: pydtl_relativepath-0.2.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 331aa62c5ae0feffdf696a8a0b777bd410bf48397c826e3b34a31bfedba209f2 |
|
MD5 | a8baeb07e1937a2be6104528753ae484 |
|
BLAKE2b-256 | 62839f8ede8e43a5bea148889b9f215e1a66514251f342b972acbf3f7e380651 |
File details
Details for the file pydtl_relativepath-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pydtl_relativepath-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2b16372ae6b2e757eef4106b307c16f67509ae26573019b00663c53fe979f56 |
|
MD5 | df08147add351ebf33bd9b052df74c39 |
|
BLAKE2b-256 | 7fc255ae1ab1f40409ea3559c912bb685d6ae39470f083b580b6bfb2a993d746 |