From c00abcb45258e4c46dc2ad89a7047882975ec3d8 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 8 Oct 2021 00:34:42 -0600 Subject: [PATCH] feat: adds black and isort --- .github/FUNDING.yml | 1 - .github/workflows/build.yml | 4 +++ CHANGELOG.md | 7 +++++ Makefile | 58 ++++++++++++++++++++++++++----------- README_project.md | 13 ++------- project_name/my_module.py | 6 ++-- pyproject.toml | 7 +++++ setup.py | 2 ++ 8 files changed, 65 insertions(+), 33 deletions(-) delete mode 100644 .github/FUNDING.yml create mode 100644 pyproject.toml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 0b00509..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: [Justintime50] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26fc71b..60d5d75 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,10 @@ jobs: run: make install - name: Run linting run: make lint + - name: Check format + run: make format-check + - name: Check imports + run: make isort-check test: runs-on: ubuntu-latest strategy: diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e71b2..69fe493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +## v1.6.0 (2021-10-08) + +* Adds `Black` and `iSort` as dev dependencies +* Adds a `pyproject.toml` file to configure Python tools +* Completely refactors the `Makefile` to include new tools and better ways of invoking previous ones +* Removes `.github/FUNDING.yml` file in favor of `.github` global files + ## v1.5.0 (2021-09-10) * Drops support for Python 3.6 diff --git a/Makefile b/Makefile index ebf1c4a..979477b 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,61 @@ -VIRTUALENV := python3 -m venv +PYTHON_BINARY := python3 +VIRTUAL_BIN := venv/bin +PROJECT_NAME := project_name ## help - Display help about make targets for this Makefile help: @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t -## venv - Install the virtual environment -venv: - $(VIRTUALENV) ~/.venv/project_name/ - ln -snf ~/.venv/project_name/ venv - venv/bin/pip install -e ."[dev]" +## build - Builds the project in preparation for release +build: + $(PYTHON_BINARY) setup.py sdist bdist_wheel -## install - Install the project locally -install: | venv +## coverage - Test the project and generate an HTML coverage report +coverage: + $(VIRTUAL_BIN)/pytest --cov=$(PROJECT_NAME) --cov-branch --cov-report=html --cov-report=term-missing ## clean - Remove the virtual environment and clear out .pyc files clean: - rm -rf ~/.venv/project_name/ venv + rm -rf ~/.venv/$(PROJECT_NAME)/ venv find . -name '*.pyc' -delete rm -rf dist rm -rf build rm -rf *.egg-info +## black - Runs the Black Python formatter against the project +black: + $(VIRTUAL_BIN)/black $(PROJECT_NAME)/ test/ + +## black-check - Checks if the project is formatted correctly against the Black rules +black-check: + $(VIRTUAL_BIN)/black $(PROJECT_NAME)/ test/ --check + +## format - Runs all formatting tools against the project +format: black isort lint + +## format-check - Checks if the project is formatted correctly against all formatting rules +format-check: black-check isort-check lint + +## install - Install the project locally +install: + $(PYTHON_BINARY) -m venv ~/.venv/$(PROJECT_NAME)/ + ln -snf ~/.venv/$(PROJECT_NAME)/ venv + $(VIRTUAL_BIN)/pip install -e ."[dev]" + +## isort - Sorts imports throughout the project +isort: + $(VIRTUAL_BIN)/isort $(PROJECT_NAME)/ test/ + +## isort-check - Checks that imports throughout the project are sorted correctly +isort-check: + $(VIRTUAL_BIN)/isort $(PROJECT_NAME)/ test/ --check-only + ## lint - Lint the project lint: - venv/bin/flake8 project_name/*.py - venv/bin/flake8 test/unit/*.py + $(VIRTUAL_BIN)/flake8 $(PROJECT_NAME)/ test/ ## test - Test the project test: - venv/bin/pytest - -## coverage - Test the project and generate an HTML coverage report -coverage: - venv/bin/pytest --cov=project_name --cov-branch --cov-report=html --cov-report=term-missing + $(VIRTUAL_BIN)/pytest -.PHONY: help install clean lint test coverage +.PHONY: help build coverage clean black black-check format format-check install isort isort-check lint test diff --git a/README_project.md b/README_project.md index 5b09ca2..c9eae17 100644 --- a/README_project.md +++ b/README_project.md @@ -23,9 +23,6 @@ pip3 install project_name # Install locally make install - -# Get Makefile help -make help ``` ## Usage @@ -39,12 +36,6 @@ venv/bin/python my_script.py ## Development ```bash -# Lint the project -make lint - -# Run tests -make test - -# Run test coverage -make coverage +# Get a comprehensive list of development tools +make help ``` diff --git a/project_name/my_module.py b/project_name/my_module.py index 63fc3f5..6463de9 100644 --- a/project_name/my_module.py +++ b/project_name/my_module.py @@ -1,12 +1,10 @@ -class MyModule(): +class MyModule: def my_function(): pass def main(): - """The main entrypoint for this script - Used in the setup.py file - """ + """The main entrypoint for this script used in the setup.py file.""" MyModule.my_function() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fa0f60e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[tool.black] +experimental-string-processing = true +line-length = 120 +skip-string-normalization = true + +[tool.isort] +profile = "black" diff --git a/setup.py b/setup.py index 03c7ca1..1bbaed3 100644 --- a/setup.py +++ b/setup.py @@ -9,8 +9,10 @@ ] DEV_REQUIREMENTS = [ + 'black', 'coveralls == 3.*', 'flake8', + 'isort', 'pytest == 6.*', 'pytest-cov == 2.*', ]