Giter Club home page Giter Club logo

trailrunner's Introduction

trailrunner

Walk paths and run things

version documentation changelog license build status code coverage

trailrunner is a simple library for walking paths on the filesystem, and executing functions for each file found. trailrunner obeys project level .gitignore files, and runs functions on a process pool for increased performance. trailrunner is designed for use by linting, formatting, and other developer tools that need to find and operate on all files in project in a predictable fashion with a minimal API:

walk() takes a single Path, and generates a list of significant files in that tree:

>>> from trailrunner import walk
>>> sorted(walk(Path("trailrunner")))
[
    PosixPath('trailrunner/__init__.py'),
    PosixPath('trailrunner/__version__.py'),
    PosixPath('trailrunner/core.py'),
    PosixPath('trailrunner/tests/__init__.py'),
    PosixPath('trailrunner/tests/__main__.py'),
    PosixPath('trailrunner/tests/core.py'),
]

run() takes a list of Path objects and a function, and runs that function once for each path given. It runs these functions on a process pool, and returns a mapping of paths to results:

>>> from trailrunner import run
>>> paths = [Path('trailrunner/core.py'), Path('trailrunner/tests/core.py')]
>>> run(paths, str)
{
    PosixPath('trailrunner/core.py'): 'trailrunner/core.py',
    PosixPath('trailrunner/tests/core.py'): 'trailrunner/tests/core.py',
}

walk_and_run() does exactly what you would expect:

>>> from trailrunner import walk_and_run
>>> walk_and_run([Path('trailrunner/tests')], str)
{
    PosixPath('trailrunner/tests/__init__.py'): 'trailrunner/tests/__init__.py',
    PosixPath('trailrunner/tests/__main__.py'): 'trailrunner/tests/__main__.py',
    PosixPath('trailrunner/tests/core.py'): 'trailrunner/tests/core.py',
}

Install

trailrunner requires Python 3.6 or newer. You can install it from PyPI:

$ pip install trailrunner

License

trailrunner is copyright John Reese, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for details.

trailrunner's People

Contributors

amyreese avatar dependabot[bot] avatar thatch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.