Skip to main content

a shared library for file finding and source resolution with gitignore support

Project description

libsightseeing

a shared library for file finding and source resolution with gitignore support, after i needed a simple way to find files while respecting .gitignore

installation

pip install libsightseeing

usage

finding project root

from libsightseeing import find_project_root

# find project root from current directory
root = find_project_root()
if root:
    print(f"found project at: {root}")

# find from a subdirectory
root = find_project_root("~/Works/example/sub/dir")
if root:
    print(f"found project at: {root}")  # ~/Works/example

# use with custom markers
root = find_project_root(
    ".",
    markers=[".git", "pyproject.toml", "package.json"]
)

finding files (simple)

from libsightseeing import find_files

# find all python files
files = find_files(".", include=["*.py"])

# find files excluding tests
files = find_files("src", exclude=["tests"])

# include gitignored files
files = find_files(".", include=["*.py"], respect_gitignore=False)

finding files (advanced)

use SourceResolver when you need more control or want to reuse the resolver:

from libsightseeing import SourceResolver

# create a reusable resolver
resolver = SourceResolver(
    root=".",
    include=["src/**/*.py"],
    exclude=["tests", "*.pyc"],
    respect_gitignore=True,
)

# resolve files multiple times (e.g., in a watch loop)
files = resolver.resolve()

combining both

from libsightseeing import find_project_root, find_files

# find project root first, then find files there
root = find_project_root(".")
if root:
    files = find_files(root, include=["*.py"])

api differences

find_files() vs SourceResolver

  • find_files() — simple one-liner function. creates a resolver internally and returns files immediately. use this for one-off file finding.

  • SourceResolver — class-based api. gives you a reusable resolver object that you can call .resolve() on multiple times. use this when you need to search the same directory repeatedly or want more control.

both respect .gitignore and support the same include/exclude patterns.

features

  • find project root
    walk up the tree looking for .git, pyproject.toml, package.json, cargo.toml, etc.

  • respects .gitignore
    automatically excludes gitignored files

  • glob patterns
    supports include/exclude patterns

  • simple one-liner
    find_files() and find_project_root() for quick usage

  • configurable resolver
    SourceResolver for advanced cases

  • lightweight
    only depends on pathspec

licence

libsightseeing is unencumbered, free-as-in-freedom, and is dual-licenced under The Unlicense or the BSD Zero Clause License. (SPDX: Unlicense OR 0BSD)

you are free to use the software as you wish, without any restrictions or obligations, subject only to the warranty disclaimers in the licence text of your choosing.

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

libsightseeing-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

libsightseeing-0.2.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file libsightseeing-0.2.0.tar.gz.

File metadata

  • Download URL: libsightseeing-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for libsightseeing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1693d2d200c905d02a250afef6f552c22a0b1b10eea9fe5cb7874927262531ce
MD5 b3e78de93a58f52aa99aaebe4c5f1e2a
BLAKE2b-256 a8469a8f6807817998ece4b763e2c37b40e5794a285efde5b929d8fd008e3fb6

See more details on using hashes here.

File details

Details for the file libsightseeing-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: libsightseeing-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for libsightseeing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfc596593aaaff6bce2cc1ad79edace2efb5689284527dc6ce206e9992c73eac
MD5 35b6f3e976aea476a780f1565946f94a
BLAKE2b-256 10e0ea844411d018c44f180ddd1d81048f5c692c8eb83a7d1c57ab356ababb04

See more details on using hashes here.

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