Skip to main content

gadd

Very opinionated formatting python files after git add

Intent

I needed a small tool to reformat and lint all the staged .py files according to the specific rules. I wanted it to be able to pip install it and available in the PATH. Also, I wanted to clearly see what changes are made by the formatter and be able to reverse it. It is called gadd because you run it after git add command. It will do:

Obeys .flake8, .pylintrc and whitelist.py config files in the current directory.

It meant be be executed in the root of the project.

Usage

python3 -m pip install --user pipx
python3 -m pipx ensurepath
  • Install gadd with pipx:
pipx install gadd
  • Stage file to test:
git add some_file.py
gadd

Publish to pip with poetry

Make it pip installable with CLI command.

Make and publish pip package with poetry:

  • Install poetry. I would highly recommend to install it with pipx
cd gadd
pipx install poetry
poetry init
  • Modify pyproject.toml file:
 [tool.poetry]
name = "gadd"
version = "0.1.0"
description = "Sort imports, remove unused imports, run Black, flake8, pylint, vulture in one go for al staged .py files"
authors = ["Almaz Kunpeissov <hello@akun.dev>"]
keywords = ["Black", "Sort imports", "analysis", "automation", "autopep8", "code", "flake8", "formatter", "gofmt", "lint", "linter", "pyfmt", "pylint", "python", "remove unused imports", "rustfmt", "static", "vulture", "yapf"]
readme = "README.md"
license = "MIT"
homepage = "https://github.com/almazkun/gadd"
repository = "https://github.com/almazkun/gadd"
documentation = "https://github.com/almazkun/gadd"
include = [
    "LICENSE",
]
classifiers = [
    "Topic :: Software Development :: Libraries :: Python Modules",
    "Topic :: Software Development :: Quality Assurance",
    "Topic :: Software Development :: Debuggers",
]

[tool.poetry.dependencies]
python = "^3.6"
autoflake = "^1.4"
black = "^21"
flake8 =  "^4.0"
gitpython = "^3.1"
isort =  "^5.10"
pylint = "^2.11"
vulture = "^2.3"

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
gadd = 'gadd:main'

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
  • Poetry build wheels:
poetry build
  • Poetry publish:
poetry publish

TODO

  • load from .conf file for vulture
  • make it async
  • remove python warnings (PYLINTHOME is now '.cache/pylint' but obsolescent '.pylint.d' is found; you can safely remove the latter)
  • Fix isorts output

Metadata

Release files for gadd 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gadd 0.2.3
File Size Uploaded
gadd-0.2.3.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gadd 0.2.3
File Interpreter ABI Platform
gadd-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / gadd-0.2.3.tar.gz

Download URL gadd-0.2.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d7a53c6a448ae6683f106f1a2c878b319bdb46dd8d319e6f8836679471e6bc43
BLAKE2b-256 checksum
How to use checksums
62f69c898098f29237fb79ca7b9c7c257dd0877b1279d97ac4d6a66f609db3f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.9 Darwin/21.1.0

Release files / gadd-0.2.3-py3-none-any.whl

Download URL gadd-0.2.3-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
797ed5dc0575783247686e390cd128246cecf9df7a41c1d8d431b785e702c1ca
BLAKE2b-256 checksum
How to use checksums
8c272d8ff16f27a4115fb81dc395cfbd2ac601e4f332a74ec66f7246272bf239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.9 Darwin/21.1.0

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page