https://github.com/rednafi/rubric
Linter config initializer for Python
https://github.com/rednafi/rubric
black config configuration-files configuration-management flake8 isort linters makefile mypy pip-tools poetry pyproject-toml python toml
Last synced: 6 months ago
JSON representation
Linter config initializer for Python
- Host: GitHub
- URL: https://github.com/rednafi/rubric
- Owner: rednafi
- License: mit
- Archived: true
- Created: 2021-05-30T13:13:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-25T02:15:41.000Z (about 2 years ago)
- Last Synced: 2025-04-02T07:28:16.624Z (6 months ago)
- Topics: black, config, configuration-files, configuration-management, flake8, isort, linters, makefile, mypy, pip-tools, poetry, pyproject-toml, python, toml
- Language: Python
- Homepage:
- Size: 192 KB
- Stars: 28
- Watchers: 2
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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][black] as the primary code formatter.
* [EditorConfig][editor-config] to enforce consistent style across different editors.
* [Ruff][ruff] to ensure style guide conformance and sort the imports.
* [Mypy][mypy] to check the type hints.
* [Pip-tools][pip-tools] to manage the dependencies.
* [Hatch][hatch] to generate build artifacts for reusable libraries.
* [Pre-commit][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):
```sh
rubric --show -f requirements.txt -f .editorconfig
```This will print:
```txt
============================ 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:
```sh
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:
```sh
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:```sh
rubric --overwrite -f filename1 -f filename2
```* If you want to append the configs to an existing file, then run:
```sh
rubric --append -f filename1 -f filename2
```* You can also point Rubric to a directory.
```sh
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:```sh
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
```[logo]: https://user-images.githubusercontent.com/30027932/122619075-6a87b700-d0b1-11eb-9d6b-355446910cc1.png
[black]: https://github.com/psf/black
[editor-config]: https://editorconfig.org/
[ruff]: https://github.com/charliermarsh/ruff
[mypy]: https://github.com/python/mypy
[pip-tools]: https://github.com/jazzband/pip-tools
[pre-commit]: https://pre-commit.com/
[hatch]: https://hatch.pypa.io/latest/
✨ 🍰 ✨