walkupward
Walk up from a start directory to find a marker file or directory, typed and dependency free.
Install
pip install walkupward
Usage
from walkupward import Marker, find, find_all, git_root, python_root, require
# Nearest directory holding pyproject.toml or setup.cfg, and which one was there.
match = find("pyproject.toml", "setup.cfg")
if match:
print(match.directory, match.names)
# Nearest directory holding both markers, or a clear error.
root = require("pyproject.toml", Marker.dir(".git"), mode="all").directory
# Every package.json from here up to (and including) the workspace root.
packages = find_all("package.json", stop_at="/home/me/workspace")
# The repository top level, linked worktrees and submodules included.
repo = git_root()
# The Python project that owns this file.
project = python_root(__file__)
The original two functions keep their behaviour:
from walkupward import find_up, walk_up
config = find_up(["pyproject.toml", "setup.cfg"]) # a Path or None
for directory in walk_up("src/pkg"): # start, then every ancestor
print(directory)
Command line
walkupward pyproject.toml # nearest directory holding pyproject.toml
walkupward --every pyproject.toml .git # nearest directory holding both
walkupward --all package.json # every enclosing directory with package.json
walkupward --preset git # repository top level
walkupward --preset editorconfig --path # the .editorconfig files that apply here
root=$(walkupward --preset git) && cd "$root"
It prints one directory per line (matched paths with --path), exits 0 when something matched and 1 when nothing did.
Errors go to stderr with exit status 1. walkupward --help lists every option.
What you get
find,find_all,iter_matches,require: one marker or several, any-of or all-of, returning a typedMatchthat names the directory and the markers present.Marker: a name plus a kind ("any","file","dir") and an optional content check.- Walk options for the general searches and Python/Node/EditorConfig presets: git style
ceilings, an inclusivestop_at,same_filesystem, andresolveto choose physical or lexical symlink handling. - Presets:
git_rootanditer_git_roots(discovery step by step like git, honouringGIT_CEILING_DIRECTORIESandGIT_DISCOVERY_ACROSS_FILESYSTEM),python_root,node_root,editorconfig_chain. - Typed errors that are also the builtin you would expect:
MarkerNotFoundError(LookupError),StartNotFoundError(FileNotFoundError),InvalidMarkerError(ValueError),WalkupPermissionError(PermissionError), all underWalkupError.
See GUIDE for every option, the exact ceiling and symlink rules, and recipes.
Why
For a one-off search, a loop over pathlib.Path.parents is often enough. walkupward
adds ordered markers, file/directory filters, inclusive boundaries, ceilings, typed
results and a CLI. Use Git itself when you need its complete repository configuration
and ownership policy: the Git preset only implements the discovery subset described in
the GUIDE.
Use an EditorConfig core to resolve settings for a file;
editorconfig_chain only finds the enclosing configuration files. Runtime dependencies: none.
Development
Install walkupward[dev], then run ruff format --check ., ruff check .,
mypy --strict src tests and pytest --basetemp=<scratch-directory>.
Tests use a 300-second per-test timeout. Git tests invoke a real local Git installation.
To check the pinned specification, run python scripts/fetch_upstream.py <scratch-directory>
and set WALKUPWARD_TRUTH to that directory. Installing editorconfig==0.17.1 enables the
optional reference-parser tests. Both sets skip cleanly when unavailable.
The CHANGELOG lists the
1.0.0 behavior changes.
License
MIT. See LICENSE.
Links
- Website: https://lianes8studio.com
- GitHub: https://github.com/JaviLianes8
- LinkedIn: https://www.linkedin.com/in/jlianes/
Metadata
Release files for walkupward 1.0.0
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 |
|---|---|---|---|---|
| walkupward-1.0.0.tar.gz | 43.4 kB | Without provenance | Details for walkupward-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| walkupward-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for walkupward-1.0.0-py3-none-any.whl |
Total release size: 67.4 kB
Release files / walkupward-1.0.0.tar.gz
| Download URL | walkupward-1.0.0.tar.gz |
|---|---|
| Size | 43.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1663a28861910052425d2a997fd63bde1667746046efac44d5538f5621d960cb
|
|
BLAKE2b-256 checksum How to use checksums |
1e260c3f63eaa5b157df1d424d8f3b791fc4cd7bd15130ac6099958c453f5c71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / walkupward-1.0.0-py3-none-any.whl
| Download URL | walkupward-1.0.0-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21bc9d0f1ec47fa4eac208ad3ed8dcd1aceb04abf0f56c49ef3eb827a35c0189
|
|
BLAKE2b-256 checksum How to use checksums |
6227af9750f318944c0146cbba853e7e9ab8293bb977c6ff4e59693dd5c2e357
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for walkupward 1.0.0
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.