Skip to content

Commit e2ff699

Browse files
authored
Merge pull request #42 from claui/format-check
Add task for format checks
2 parents 88aa99d + 9acd92a commit e2ff699

9 files changed

Lines changed: 45 additions & 21 deletions

File tree

{{ cookiecutter.pypi_package_name }}/.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
- name: Run linter
5959
run: poetry run poe linter
6060

61+
- name: Check for formatting style violations not covered by the linter
62+
run: poetry run poe formatcheck
63+
6164
- name: Run unit tests
6265
run: poetry run poe tests
6366

{{ cookiecutter.pypi_package_name }}/CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ To execute the linter, run:
147147
poetry run poe linter
148148
```
149149

150+
### Running the code formatting style check
151+
152+
To check the code base for formatting style violations that are not
153+
covered by the linter, run:
154+
155+
```shell
156+
poetry run poe formatcheck
157+
```
158+
150159
### Running the static type check
151160

152161
To execute the static type check, run:

{{ cookiecutter.pypi_package_name }}/doc/sphinx/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'deflist',
4343
]
4444

45+
4546
def skip_module(app, what, name, obj, skip, options):
4647
if what != 'module':
4748
return skip

{{ cookiecutter.pypi_package_name }}/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mypy = ">=1.8"
5050
poethepoet = ">=0.24"
5151
pylint = ">=3.0"
5252
pytest = "*"
53+
ruff = "*"
5354
{%- if cookiecutter.include_executable == "y" %}
5455
types-colorama = "*"
5556
{%- endif %}
@@ -83,6 +84,8 @@ doc.shell = """
8384
sphinx-build -qW -b man doc/sphinx build/man
8485
"""
8586
doc.help = "Generate documentation"
87+
formatcheck.cmd = "ruff format --check"
88+
formatcheck.help = "Check for formatting style violations not covered by the linter"
8689
{% if cookiecutter.include_executable == "y" -%}
8790
hello.script = "{{ cookiecutter.python_package_name }}.cli:hello"
8891
hello.help = "Run hello"

{{ cookiecutter.pypi_package_name }}/tests/test_{{ cookiecutter.first_module_name }}.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ def test_hello({{ cookiecutter.first_module_name }}: {{ cookiecutter.first_modul
1515

1616

1717
def test_hello_with_author_name({{ cookiecutter.first_module_name }}: {{ cookiecutter.first_module_name.capitalize() }}) -> None:
18-
assert {{ cookiecutter.first_module_name }}.hello('{{ cookiecutter.author_full_name }}') \
19-
== 'Hello, {{ cookiecutter.author_full_name }}!'
18+
assert (
19+
{{ cookiecutter.first_module_name }}.hello('{{ cookiecutter.author_full_name }}') == 'Hello, {{ cookiecutter.author_full_name }}!'
20+
)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Run the command line interface by default."""
22

3-
43
from {{ cookiecutter.python_package_name }} import cli
54

65
cli.run()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Custom error types."""
22
{% if cookiecutter.include_executable == "y" %}
3+
34
class CliError(Exception):
45
"""An user-facing error message."""
56
{% endif -%}

{{ cookiecutter.pypi_package_name }}/{{ cookiecutter.python_package_name }}/version.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ def version() -> Optional[str]:
2626
with open(PYPROJECT_TOML, encoding='utf-8') as pyproject_toml:
2727
# Parse manually due to Debian 11 missing a `tomli` package
2828
version_lines = (
29-
line for line in pyproject_toml
30-
if line.startswith('version '))
31-
return next(version_lines).split('=')[1].strip("'\"\n ")
29+
line
30+
for line in pyproject_toml
31+
if line.startswith('version ')
32+
)
33+
return next(version_lines).split('=')[1].strip('\'"\n ')
3234

3335
with suppress(FileNotFoundError):
3436
return importlib.metadata.version(
35-
__package__ or __name__.split('.', maxsplit=1)[0])
37+
__package__ or __name__.split('.', maxsplit=1)[0]
38+
)
3639

3740
return None

{{ cookiecutter.pypi_package_name }}/{{ cookiecutter.python_package_name }}/{{ cookiecutter.first_module_name }}.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,32 @@ class {{ cookiecutter.first_module_name.capitalize() }}:
2626
The default value is: `/path/to/qux`
2727
"""
2828

29-
def __init__(self,
29+
def __init__(
30+
self,
3031
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
31-
foobar: str | None=None,
32+
foobar: str | None = None,
3233
{%- else -%}
33-
foobar: Optional[str]=None,
34+
foobar: Optional[str] = None,
3435
{%- endif %}
35-
qux: str='/path/to/qux',
36+
qux: str = '/path/to/qux',
3637
) -> None:
37-
if (merged_foobar := foobar or os.environ.get('FOOBAR', None)) is None:
38+
if (
39+
merged_foobar := foobar or os.environ.get('FOOBAR', None)
40+
) is None:
3841
{% if cookiecutter.include_executable == "y" -%}
39-
raise CliError('The `--foobar` switch must be given if ' +
40-
'no `FOOBAR` environment variable is defined.')
42+
raise CliError(
43+
'The `--foobar` switch must be given if '
44+
+ 'no `FOOBAR` environment variable is defined.'
45+
)
4146
{%- else -%}
42-
raise ValueError('The `foobar` argument must be given if ' +
43-
'no `FOOBAR` environment variable is defined.')
47+
raise ValueError(
48+
'The `foobar` argument must be given if '
49+
+ 'no `FOOBAR` environment variable is defined.'
50+
)
4451
{%- endif %}
4552
self._foobar = merged_foobar
4653
self._qux = qux
4754

48-
4955
def hello(self, name: str = 'world') -> str: # pylint: disable=no-self-use
5056
"""Says hello to someone.
5157
@@ -63,12 +69,10 @@ def hello(self, name: str = 'world') -> str: # pylint: disable=no-self-use
6369
logger.debug('Printing name: %s', name)
6470
return f'Hello, {name}!'
6571

66-
6772
def off(self) -> None: # pylint: disable=no-self-use
6873
"""Disables {{ cookiecutter.project_title }}."""
6974
logger.info('Disabling {{ cookiecutter.project_title }}')
7075

71-
7276
def on(self) -> None: # pylint: disable=no-self-use
7377
"""Enables {{ cookiecutter.project_title }}."""
7478
logger.info('Enabling {{ cookiecutter.project_title }}')
@@ -77,9 +81,9 @@ def on(self) -> None: # pylint: disable=no-self-use
7781
def hello(
7882
name: str = 'world',
7983
{% if cookiecutter.use_alternative_union_syntax == "y" -%}
80-
foobar: str | None=None,
84+
foobar: str | None = None,
8185
{%- else -%}
82-
foobar: Optional[str]=None,
86+
foobar: Optional[str] = None,
8387
{%- endif %}
8488
qux: str = '/path/to/qux',
8589
) -> str:

0 commit comments

Comments
 (0)