Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce black code formatting #4

Merged
merged 5 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
# Recommend matching the black line length (default 88),
# rather than using the flake8 default of 79:
max-line-length = 88
# Q003 Change outer quotes to avoid escaping inner quotes
# W503 Line break before binary operator (preferred way)
# E203 See https://github.com/PyCQA/pycodestyle/issues/373
extend-ignore = "Q003,W503,E203"
# flake8-use-fstring
percent-greedy = 0
format-greedy = 2
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.wordWrapColumn": 80,
"editor.wordWrapColumn": 88,
"editor.wordWrap": "wordWrapColumn",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ isort-apply:

mypy:
@echo Run static code checks against source code base
$(POETRY_CMD) run mypy my_module
$(POETRY_CMD) run mypy tests
$(POETRY_CMD) run mypy $(PY_FILES)

black:
@echo Run code formatting using black
$(POETRY_CMD) run black $(PY_FILES)

lint:
@echo Run code formatting checks against source code base
$(POETRY_CMD) run flake8 $(PY_FILES)

build: test mypy isort lint
build: test mypy isort black lint
@echo Run setup.py-based build process to package application
$(POETRY_CMD) build

Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

> A best-practices template project for Python3 modules

--------------------------------------------------------------------------------

**Disclaimer**: If you see this on [pypi.org](https://pypi.org/project/python3-boilerplate/) please note that the project is only published here for testing purposes. Please visit [GitHub](https://github.com/BastiTee/python3-boilerplate) for the related template project.

--------------------------------------------------------------------------------

## Setup

- Make sure that `python` and `poetry` is installed and available on the path. Python 2 is not supported – :skull:
Expand All @@ -18,8 +12,9 @@
## Features

- Basic project/module organization according to <https://packaging.python.org>
- `Makefile` bootstrapping script
- Makefile bootstrapping script
- [poetry](https://python-poetry.org/) with virtual environments and project builds
- [black](https://github.com/psf/black) code formatting
- Unit testing with [pytest](https://docs.pytest.org/en/latest/)
- Linting ([flake8](http://flake8.pycqa.org)) and code formatting ([autopep8](https://github.com/hhatto/autopep8)) support
- [isort](https://pypi.org/project/isort/) support for automated import sorting
Expand All @@ -41,8 +36,8 @@

## Future ideas and todos

- Introduce [black](https://github.com/psf/black) in favour of other linters
- Introce Python 3.7 and Python 3.10 to test matrix
- Introduce Python 3.7 and Python 3.10 to test matrix
- Embed flake8 config into `pyproject.toml` once they support it ([see](https://github.com/PyCQA/flake8/issues/234))

## Licensing

Expand Down
7 changes: 2 additions & 5 deletions my_module/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
@click.command('my_module')
@click.option('--number-a', '-a', type=click.INT, default=2)
@click.option('--number-b', '-b', type=click.INT, default=2)
def main(
number_a: int,
number_b: int
) -> None:
def main(number_a: int, number_b: int) -> None:
"""Enter main application."""
print('Executed from command line...')
print(f'2 + 2 equals {add_two_numbers(number_a, number_b)}')
print(f'{number_a} + {number_b} equals {add_two_numbers(number_a, number_b)}')


if __name__ == '__main__':
Expand Down
78 changes: 77 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "my_module"
version = "0.0.6"
version = "0.0.7"
description = ""
license = "Apache 2.0"
authors = ["Basti Tee <basti.tee@posteo.de>"]
Expand Down Expand Up @@ -38,6 +38,7 @@ rope = "^1.0.0"
twine = "^4.0.0"
mypy = "^0.950"
typing-extensions = "^4.2.0"
black = "^22.3.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -62,10 +63,5 @@ warn_unreachable = true
[tool.pytest]
addopts = "-p no:warnings"

[tool.flake8]
# Q003 Change outer quotes to avoid escaping inner quotes
# W503 line break before binary operator (preferred way)
ignore = "Q003,W503"
# flake8-use-fstring
percent-greedy = 0
format-greedy = 2
[tool.black]
skip-string-normalization = true
11 changes: 4 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@


class TestUtils: # noqa: D101

@pytest.mark.parametrize('number_left, number_right', [
(None, 1), (1, None), (None, None)
])
@pytest.mark.parametrize(
'number_left, number_right', [(None, 1), (1, None), (None, None)]
)
def test_add_two_numbers_no_input(
self,
number_left: int,
number_right: int
self, number_left: int, number_right: int
) -> None:
"""Basic input validation."""
with pytest.raises(ValueError):
Expand Down