Skip to content

Commit

Permalink
feat: adds black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Oct 8, 2021
1 parent 1f3684f commit c00abcb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 33 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
58 changes: 41 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 2 additions & 11 deletions README_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ pip3 install project_name

# Install locally
make install

# Get Makefile help
make help
```

## Usage
Expand All @@ -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
```
6 changes: 2 additions & 4 deletions project_name/my_module.py
Original file line number Diff line number Diff line change
@@ -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()


Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tool.black]
experimental-string-processing = true
line-length = 120
skip-string-normalization = true

[tool.isort]
profile = "black"
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
]

DEV_REQUIREMENTS = [
'black',
'coveralls == 3.*',
'flake8',
'isort',
'pytest == 6.*',
'pytest-cov == 2.*',
]
Expand Down

0 comments on commit c00abcb

Please sign in to comment.