pathaliases
A python package for handling path aliases.
Path aliases can be loaded directly from YAML files:
dir/:
subdir/:
alias: SUBDIR
some/other/dir/:
alias: SUBDIR_2
file.txt: { alias: [FILE, ALTERNATE_ALIAS] }
dir2/:
extra_keys: are ignored
alias: 2ndDir
some/very/long/path/:
into/a/deep/file/hierarchy/:
can/be/addressed/with: { alias: A_PATH_INDEPENDANT_ALIAS }
Resolving this with pathaliases.resolve_yaml_to_path_strings("aliases.yml") returns a dictionary:
{
"SUBDIR": "dir/subdir/",
"SUBDIR_2": "dir/subdir/some/other/dir/"
"FILE": "file.txt",
"ALTERNATE_ALIAS": "file.txt",
"2ndDir": "dir2/",
"A_PATH_INDEPENDENT_ALIAS": "some/very/long/path/into/a/deep/file/hierarchy/can/be/addressed/with"
}
Which can be used to make codebases independent from paths:
# Before
subdir = "dir/subdir/"
subdir_2 = os.path.join(subdir, subdir_2)
# After: *where* the dirs are is configurable
aliases = pathaliases.resolve_yaml_to_path_strings("aliases.yml")
subdir = aliases["SUBDIR"]
subdir_2 = aliases["SUBDIR_2"]
pathaliases is designed to be:
Simple - It just concatenates all the keys that lead up to an alias.
Readable - Developers and admins should be able to edit paths easily.
Standard - It uses standard file formats and conventions, making it easy to port to other languages.
Installation
Clone the repo:
$ git clone https://github.com/adamkewley/pathaliases.git $ python setup.py install
Usage
Resolve aliases directly from a YAML file:
import pathaliases
aliases = pathaliases.resolve_yaml_to_path_strings("aliases.yml")
print(aliases["SUBDIR"]) # echoes: "dir/subdir/"
Resolve aliases from a dict:
import pathaliases
aliases_dict = {
"dir/": {
"subdir/": {"alias": "SUBDIR"}
}
}
aliases = pathaliases.resolve_path_strings(aliases_dict)
print(aliases["SUBDIR"]) # echoes: "dir/subdir/"
Substituting Variables
Alias files can also contain variables, templated with ${VARNAME}:
foo/:
${var}/:
alias: ${key}
pathaliases allows you to pass in an environment when evaluating paths:
env = {
"var": "bar",
"key": "some_alias"
}
aliases = pathaliases.resolve_yaml_to_path_strings("aliases.yml", env=env)
aliases == {
"some_alias": "foo/bar/",
}
Metadata
Release files for pathaliases 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pathaliases-0.0.3.tar.gz | 3.7 kB | Without provenance | Details for pathaliases-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pathaliases-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for pathaliases-0.0.3-py3-none-any.whl |
Total release size: 9.0 kB
Release files / pathaliases-0.0.3.tar.gz
| Download URL | pathaliases-0.0.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed924d233018302f0f224bda4a53f4ac26e7a13d0e860713bac3937506919606
|
|
BLAKE2b-256 checksum How to use checksums |
7007553634467bbcfadb3cb01e30b3a9549a7d2d0e818a677f769bf349aeee2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pathaliases-0.0.3-py3-none-any.whl
| Download URL | pathaliases-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15bae1e4711bd730612dc82f6f12b15878370280e5a25b6de3f0e7ce03ece29b
|
|
BLAKE2b-256 checksum How to use checksums |
3cceb20abacdf69d87560cc0150f2a9e1f76c5577909fbb6d952e63ae000b4c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pathaliases 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.