Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modularizer_fpr-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modularizer_fpr-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for modularizer_fpr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 018e4faf8fc1c1442e0f05a63f3c9f33f107f2c54b27eb65987531d609899cd6
MD5 3878cb4e8aa897a4bc61bd1b3f6329b0
BLAKE2b-256 33bedb34d6b88a8473fa49552d363c1a7fc079f6e4211f95f3325cd278fedefd

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularizer_fpr-0.1.0.tar.gz:

Publisher: publish.yml on modularizer/fpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularizer_fpr-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modularizer_fpr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d6f4402df53b64d2c9c17a9e7d9507ddaf52bc9085a93cacb67d10f69fa51e1
MD5 7d53b849449adaaae882034e1d6e5135
BLAKE2b-256 82a8fdc142d8903f3881aab8b30ac894d0113bbd315b632038fcf6d0bad62a6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularizer_fpr-0.1.0-py3-none-any.whl:

Publisher: publish.yml on modularizer/fpr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page