Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 5f40d4b

Browse files
committed
feat: allow choosing local poetry python hooks
This integrates better with IDE and with automated dependency updates via Dependabot or similar. @moduon MT-83
1 parent 06ef055 commit 5f40d4b

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

copier.yml

+14
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@ _envops:
1414
# This template is just a complement, so we better use a different default answers file
1515
_answers_file: .copier-answers.autopretty.yml
1616

17+
# Add --dev dependencies for poetry env
18+
_tasks:
19+
- "{% if python and poetry_local_hooks %}poetry add --dev autoflake pyupgrade black
20+
blacken-docs isort flake8 flake8-bugbear pydocstyle[toml]{% else %}true{% endif %}"
21+
1722
# Questions
1823
python:
1924
default: true
2025
type: bool
2126
help: Will your project use Python 3.6 or later?
2227

28+
poetry_local_hooks:
29+
default: false
30+
type: bool
31+
when: "{{ python }}"
32+
help: Do you prefer to run local hooks prefixed with `poetry run`?
33+
34+
In this case, you are supposed to maintain these dependencies locally using `poetry
35+
add --dev`. Provides better integration with IDEs and Dependabot.
36+
2337
js:
2438
default: true
2539
type: bool

src/.pre-commit-config.yaml.jinja

+82
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,86 @@ repos:
3333
- --fix
3434
{%- endif %}
3535
{%- if python %}
36+
{%- if poetry_local_hooks %}
37+
{# These hooks are copied from their respective origins in the next section,
38+
but configured to be executed with `poetry run`, to get better integration #}
39+
- repo: local
40+
hooks:
41+
- id: autoflake
42+
name: autoflake
43+
entry: poetry run autoflake
44+
language: python
45+
types: [python]
46+
require_serial: true
47+
args:
48+
- --in-place
49+
- --expand-star-imports
50+
- --ignore-init-module-imports
51+
- --remove-all-unused-imports
52+
- --remove-duplicate-keys
53+
- --remove-unused-variables
54+
- id: pyupgrade
55+
name: pyupgrade
56+
description: Automatically upgrade syntax for newer versions.
57+
entry: poetry run pyupgrade
58+
language: python
59+
types: [python]
60+
- id: black
61+
name: black
62+
description: "Black: The uncompromising Python code formatter"
63+
entry: poetry run black
64+
language: python
65+
minimum_pre_commit_version: 2.9.2
66+
require_serial: true
67+
types_or: [python, pyi]
68+
- id: blacken-docs
69+
name: blacken-docs
70+
description: Run `black` on python code blocks in documentation files
71+
entry: poetry run blacken-docs
72+
language: python
73+
language_version: python3
74+
files: '\.(rst|md|markdown|py|tex)$'
75+
- id: isort
76+
name: isort
77+
entry: poetry run isort
78+
require_serial: true
79+
language: python
80+
language_version: python3
81+
types_or: [cython, pyi, python]
82+
minimum_pre_commit_version: '2.9.2'
83+
args:
84+
- --filter-files
85+
- --settings=.
86+
- &flake8
87+
id: flake8
88+
name: flake8 except __init__.py
89+
description: '`flake8` is a command-line utility for enforcing style consistency across Python projects.'
90+
entry: poetry run flake8
91+
language: python
92+
types: [python]
93+
require_serial: true
94+
exclude: /__init__\.py$
95+
- <<: *flake8
96+
name: flake8 for __init__.py
97+
args:
98+
# ignore unused imports in __init__.py
99+
- --extend-ignore=F401
100+
files: /__init__\.py$
101+
- id: pydocstyle
102+
name: pydocstyle
103+
description: pydocstyle is a static analysis tool for checking compliance with Python docstring conventions.
104+
entry: poetry run pydocstyle
105+
language: python
106+
types: [python]
107+
- id: poetry-check
108+
name: poetry-check
109+
description: run poetry check to validate config
110+
entry: poetry check
111+
language: python
112+
language_version: python3
113+
pass_filenames: false
114+
files: ^pyproject.toml$
115+
{%- else %}
36116
- repo: https://github.com/myint/autoflake
37117
rev: v1.4
38118
hooks:
@@ -83,6 +163,8 @@ repos:
83163
rev: 6.1.1
84164
hooks:
85165
- id: pydocstyle
166+
additional_dependencies: [".[toml]"]
167+
{%- endif %}
86168
{%- endif %}
87169
{%- if terraform %}
88170
- repo: https://github.com/aquasecurity/tfsec

0 commit comments

Comments
 (0)