Access file paths from pyproject.toml
Project description
project-paths
Access file paths from pyproject.toml
Thanks to @Madoshakalaka for the idea!
# pyproject.toml
[tool.project-paths]
readme = "README.md"
# app.py
from project_paths import paths
# paths.readme is a pathlib.Path object:
print(paths.readme.read_text())
Install
pip install project-paths
Usage
Does your application have a bunch of configurable file paths? Do you wish you just had one place to configure list them all?
Add paths to [tool.project-paths]
With this module, define your paths in your pyproject.toml
file under
the [tool.project-paths]
table:
[tool.project-paths]
docs = "path/to/my/docs"
settings = "path/to/my/settings.py"
config = "/opt/path/to/my/config
# Add as many paths as you want!
Anything string defined with [tool.project-paths]
will be made
available. Relative paths are relative to pyproject.toml
.
Access paths using project_paths.paths.<path name>
Now you can access all the paths listed in pyproject.toml
with
project_paths.paths
. Every path is returned as
a pathlib.Path
object:
from project_paths import paths
print(paths.docs.glob("*.md"))
assert paths.config.exists()
exec(paths.settings.read_text())
# Or anything you want!
Caveats
Names in [tool.project-paths]
should be a valid Python identifier
and the names cannot have a leading underscore. If a name has
a leading underscore, a warning is issued and the name is inaccessible:
[tool.project-paths]
# BAD: paths that start with a '_' cannot be used
_my_path = "path/to/wherever"
# GOOD: path is a valid Python identifier!
my_path = "path/to/where
License
2021 © Eddie Antonio Santos. MIT Licensed.
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
Hashes for project-paths-0.1.0.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a2fb5bd7d0fcb49332a1b20fa785fe10469f74ffc3e73465e492eab7e57774 |
|
MD5 | 6a98335975e06c6d81d44ff248ca5401 |
|
BLAKE2b-256 | bc0b96315bab45ea085a9a6739e4df9cc1b3b0f0b18c1d7fe95dc095a714f48d |
Hashes for project_paths-0.1.0.post0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 089c4a0b2faa928fa139796228c0695cc284e184acf42e1506e42989b80ce433 |
|
MD5 | 81a440dfb3d84b8a0005ce837a998f7f |
|
BLAKE2b-256 | 67715b777912b45833fc87856c4ebb6082b9fb0361a2ba72dff462f4f20ef618 |