Git Product home page Git Product logo

rubric's Introduction

Rubric

>> Linter Config Initializer for Python <<

 

logo

Preface

Rubric initializes the configuration files of a few Python linters and formatters. Also, it adds a README.md boilerplate and a simple Makefile with the commands to apply the tools. This helps you maintain an isomorphic workflow across multiple projects. It assumes that, in all of your Python projects, you'll use—

  • Black as the primary code formatter.
  • EditorConfig to enforce consistent style across different editors.
  • Ruff to ensure style guide conformance and sort the imports.
  • Mypy to check the type hints.
  • Pip-tools to manage the dependencies.
  • Hatch to generate build artifacts for reusable libraries.
  • Pre-commit for managing and maintaining the pre-commit hooks.

Following is a list of config files that Rubric is going to add to your target directory:

root
├── .editorconfig           # Config file for Editorconfig
├── .gitignore              # Python specific .gitignore file
├── .pre-commit-config.yaml # Config to manage pre-commit hooks.
├── Makefile                # Makefile containing the commands to lint your code
├── pyproject.toml          # Toml file to with the configs for black, ruff, and mypy
├── README.md               # A readme boilerplate
├── requirements-dev.txt    # File to specify the dev requirements
└── requirements.txt        # File to specify the pinned app requirements

The files will contain minimal but sensible default configurations for the respective tools. You're free to change them as you like.

Installation

  • Rubric requires Python 3.8 and up.

  • Make a virtual environment in your project's root directory.

  • Activate the environment and run:

    pip install rubric
    

Usage

  • To inspect all the CLI options, run:

    rubric --help
    

    You should see the following output:

    $ rubric --help
                   >> Config Initializer for Python Projects <<
    
    Usage: rubric [OPTIONS]
    
    Options:
    -h, --help                      Display help message.
    -v, --version                   Display the version number.
    -s, --show                      Show the contents of the config files.
    -a, --append                    Append to existing config files.
    -o, --overwrite                 Overwrite existing config files.
    -c, --create                    Create the config files in the current
                                    directory.
    -f, --filename [.editorconfig|.gitignore|.pre-commit-config.yaml|README.md|
            Makefile|pyproject.toml|requirements-dev.in|requirements-dev.txt|
            requirements.in|requirements.txt]
                                    Target file names.
    -d, --dirname PATH              Target directory name.
    -l, --list                      List the config files that are about to be
                                    generated.
    
    
  • Display a list of config files that are going to be created:

    rubric --list
    
    Config files that are about to be generated:
    
    => .editorconfig
    => .gitignore
    => .pre-commit-config.yaml
    => README.md
    => Makefile
    => pyproject.toml
    => requirements-dev.txt
    => requirements.txt
    
  • Take a peek into the content of any config file(s):

    rubric --show -f requirements.txt -f .editorconfig

    This will print:

    ============================ requirements.txt ============================
    
    #
    # This file is autogenerated by pip-compile with python 3.11
    # To update, run:
    #
    #    pip-compile --output-file=requirements.txt requirements.in
    #
    
    ============================ .editorconfig ============================
    
    # https://editorconfig.org
    
    root = true
    
    [*]
    indent_style = space
    indent_size = 2
    trim_trailing_whitespace = true
    insert_final_newline = true
    charset = utf-8
    end_of_line = lf
    
    [*.{py,md}]
    indent_size = 4
    
    [Makefile]
    indent_size = 4
    indent_style = tab
  • Initialize a project with the following command:

    rubric --create

    This will run the tool in a non-destructive way—that means it won't overwrite any of the configuration files that you might already have in the directory.

  • If you only want to create a selected list of config files, then run:

    rubric --create -f requirements.txt -f requirements-dev.txt
  • If you want to overwrite any of the existing config files that you might have in the directory, then run:

    rubric --overwrite -f filename1 -f filename2
  • If you want to append the configs to an existing file, then run:

    rubric --append -f filename1 -f filename2
  • You can also point Rubric to a directory.

    rubric --create --directory "some/custom/directory"
  • If you want to check and update the configs across multiple repositories in a single sweep, use the following command:

    s="dir1 dir2 dir3"; echo $s | xargs -n 1 -P $(echo $s | wc -w) rubric -c -d

    This command will spawn 3 processes to create the config files in dir1, dir2, and dir3 in parallel.

  • You can run the entire linter suite with this command:

    make lint
    
✨ 🍰 ✨

rubric's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar rednafi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rubric's Issues

Remove redundant requirements file

Currently, Rubric uses setup.py and setup.cfg for packaging and dependency management. This makes the requirements* files redundant. Remove them and change the Makefile as needed.

Add caching to the CI

Change the CI to make it more performant.

  • Add pip caching.
  • Add scheduled execution of the CI pipeline.
  • Add action update rules to the dependabot.yml file.

Replace argparse with Click

The exception handling logic of the argparse CLI has become quite convoluted. Clean it up by taking advantage of Click.

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.