Heuristically detect the root of a project directory
Project description
fpr
Find Project Root — heuristically detect the root of a project directory.
Installation
pip install modularizer-fpr
Usage
Command Line
# From current directory
fpr
# From a specific path
fpr /path/to/some/nested/folder
# Show scoring for all candidate directories
fpr --verbose
# Output relative path
fpr --rel
# Custom weights (repeatable)
fpr -w "./Cargo.toml:100" -w "target:-50"
# Weights as JSON string
fpr --weights-json '{"./Cargo.toml": 100, "target": -50}'
# Weights from JSON file
fpr --weights-file my-weights.json
# Skip default weights entirely
fpr --no-defaults -w "./package.json:100"
# Combine sources (priority: defaults < file < json < -w)
fpr --weights-file base.json -w "./my-marker:200"
Python API
from fpr import find_project_root, score_all, score_directory, WEIGHTS
# Find the project root (returns a Path)
root = find_project_root()
root = find_project_root("/some/nested/path")
root = find_project_root(verbose=True) # prints all scores
# Get scores for all candidate directories
best_path, best_score, all_scores = score_all("/some/nested/path")
# best_path: Path to highest-scoring directory
# best_score: int score of that directory
# all_scores: dict mapping Path -> score for all candidates
# Score a single directory
score = score_directory("/my/project")
# Use custom weights
custom_weights = {
"./Cargo.toml": 100, # strongly prefer Rust projects
"target": -50, # penalize being inside target/
}
root = find_project_root(weights=custom_weights)
How It Works
fpr walks up from the starting directory, scoring each ancestor based on common project markers.
Pattern Types
Weights use glob-like patterns with * (any except /) and ** (any including /):
| Pattern | Matches |
|---|---|
./foo |
Directory contains a child named foo |
foo |
Directory itself is named foo |
**/foo/**/ |
foo appears anywhere in ancestry |
**/foo/ |
Direct parent is foo |
**/foo/*/ |
Grandparent is foo |
Default Weights
Positive weights (project indicators):
- Config files:
./pyproject.toml,./package.json,./Cargo.toml,./go.mod, etc. - VCS directories:
./.git,./.hg,./.svn - Lock files:
./poetry.lock,./yarn.lock,./package-lock.json - Dev tooling:
./Dockerfile,./Makefile,./.editorconfig
Negative weights (penalties):
- Name patterns:
src,dist,node_modules,venv, etc. - Parent patterns:
**/venv/**/,**/node_modules/**/, etc.
Returns the highest-scoring directory, or the starting directory if no strong signals are found.
License
Unlicense
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modularizer_fpr-0.1.0.tar.gz.
File metadata
- Download URL: modularizer_fpr-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
018e4faf8fc1c1442e0f05a63f3c9f33f107f2c54b27eb65987531d609899cd6
|
|
| MD5 |
3878cb4e8aa897a4bc61bd1b3f6329b0
|
|
| BLAKE2b-256 |
33bedb34d6b88a8473fa49552d363c1a7fc079f6e4211f95f3325cd278fedefd
|
Provenance
The following attestation bundles were made for modularizer_fpr-0.1.0.tar.gz:
Publisher:
publish.yml on modularizer/fpr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularizer_fpr-0.1.0.tar.gz -
Subject digest:
018e4faf8fc1c1442e0f05a63f3c9f33f107f2c54b27eb65987531d609899cd6 - Sigstore transparency entry: 757803626
- Sigstore integration time:
-
Permalink:
modularizer/fpr@cdd03b5522a591b72b08d86ec7925df8faf479fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/modularizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cdd03b5522a591b72b08d86ec7925df8faf479fa -
Trigger Event:
release
-
Statement type:
File details
Details for the file modularizer_fpr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: modularizer_fpr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d6f4402df53b64d2c9c17a9e7d9507ddaf52bc9085a93cacb67d10f69fa51e1
|
|
| MD5 |
7d53b849449adaaae882034e1d6e5135
|
|
| BLAKE2b-256 |
82a8fdc142d8903f3881aab8b30ac894d0113bbd315b632038fcf6d0bad62a6c
|
Provenance
The following attestation bundles were made for modularizer_fpr-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on modularizer/fpr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularizer_fpr-0.1.0-py3-none-any.whl -
Subject digest:
1d6f4402df53b64d2c9c17a9e7d9507ddaf52bc9085a93cacb67d10f69fa51e1 - Sigstore transparency entry: 757803629
- Sigstore integration time:
-
Permalink:
modularizer/fpr@cdd03b5522a591b72b08d86ec7925df8faf479fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/modularizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cdd03b5522a591b72b08d86ec7925df8faf479fa -
Trigger Event:
release
-
Statement type: