Skip to content

Commit 0882712

Browse files
authored
Merge pull request #8 from Cielquan/feature/tests-tox-precommit
Feature/tests tox precommit
2 parents 48e74ab + 38af60a commit 0882712

15 files changed

+904
-114
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
* commit-msg-jira-hook version:
2+
* Python version:
3+
* Operating System:
4+
* [ ] I check open and closed issues.
5+
6+
### Description
7+
8+
Describe what you were trying to get done.
9+
Tell us what happened, what went wrong, and what you expected to happen.
10+
11+
### What I Did
12+
13+
```
14+
Paste the command(s) you ran and the output.
15+
If there was a crash, please include the traceback here.
16+
```

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ version.py
118118

119119
# Local backup dir
120120
.backupfiles
121+
122+
# poetry lockfile
123+
poetry.lock

.pre-commit-config.yaml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
minimum_pre_commit_version: "1.15"
2+
default_stages: [commit, push]
3+
4+
repos:
5+
#: code unspecific out-of-the-box hooks
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v2.5.0
8+
hooks:
9+
- id: no-commit-to-branch
10+
args: [--branch, staging, --branch, master, --pattern, release/.*]
11+
- id: check-case-conflict
12+
- id: name-tests-test
13+
args: ["--django"]
14+
- id: check-json
15+
- id: pretty-format-json
16+
args: ["--indent=4", "--autofix"]
17+
- id: check-toml
18+
- id: check-yaml
19+
- id: detect-private-key
20+
- id: trailing-whitespace
21+
stages: [commit, push]
22+
- id: end-of-file-fixer
23+
stages: [commit, push]
24+
25+
#: several python code regex hooks
26+
- repo: https://github.com/pre-commit/pygrep-hooks
27+
rev: v1.5.1
28+
hooks:
29+
- id: python-no-log-warn
30+
- id: python-no-eval
31+
32+
#: pyupgrade - upgrade old python syntax to new
33+
- repo: https://github.com/asottile/pyupgrade
34+
rev: v2.4.1
35+
hooks:
36+
- id: pyupgrade
37+
args: [--py36-plus]
38+
39+
#: seed-isort-config - fill isort's known_third_party config
40+
- repo: https://github.com/asottile/seed-isort-config
41+
rev: v2.1.1
42+
hooks:
43+
- id: seed-isort-config
44+
args: [--application-directories, "src:."]
45+
46+
#: isort - sort imports
47+
- repo: https://github.com/timothycrosley/isort
48+
rev: 4.3.21
49+
hooks:
50+
- id: isort
51+
args: [--apply, --recursive]
52+
additional_dependencies: [toml>=0.10.1]
53+
54+
#: blacken-docs - black for python code in docs
55+
- repo: https://github.com/asottile/blacken-docs
56+
rev: v1.7.0
57+
hooks:
58+
- id: blacken-docs
59+
additional_dependencies: [black==19.10b0]
60+
61+
#: black - python formatter
62+
- repo: https://github.com/psf/black
63+
rev: 19.10b0
64+
hooks:
65+
- id: black
66+
args: [--safe]
67+
68+
# TODO: 16.04.2020: Currently bandit is unusable with pre-commit .. wait for fix .. remove in tox then
69+
# #: bandit - python code security analyzer
70+
# - repo: https://github.com/PyCQA/bandit
71+
# rev: 1.6.2
72+
# hooks:
73+
# - id: bandit
74+
# args: ["--exclude ./.tox/*,./venv/*,./.eggs/*,./tests/*"]
75+
76+
#: flake8 - python linter
77+
- repo: https://gitlab.com/pycqa/flake8
78+
rev: 3.8.1
79+
hooks:
80+
- id: flake8
81+
args: [
82+
--count,
83+
--statistics,
84+
"--extend-exclude=*venv*/,*.egg,build/",
85+
--extend-ignore=E203,
86+
--max-line-length=88,
87+
--max-complexity=20,
88+
--pytest-fixture-no-parentheses,
89+
"--format=${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s",
90+
]
91+
additional_dependencies:
92+
#: Colored output - needs custom format
93+
- "flake8-colors"
94+
#: Check for python builtins being used as variables or parameters.
95+
#: A001-A002
96+
- "flake8-builtins==1.5.2"
97+
#: Finding likely bugs and design problems
98+
#: B001-B014 | B301-B306 | B901-B903,B950
99+
- "flake8-bugbear==20.1.4"
100+
#: Write better list/set/dict comprehensions
101+
#: C400-C416
102+
- "flake8-comprehensions==3.2.2"
103+
#: Check docstrings with PEP257
104+
#: D100-D107 | D200-D215 | D300-D302 | D400-D417
105+
# TODO: 16.04.2020: Wait for https://github.com/PyCQA/pydocstyle/pull/446 to fix problem with noqa before module docstrings
106+
# - "flake8-docstrings==1.5.0"
107+
#: Find dead/out-commented code
108+
#: E800
109+
- "flake8-eradicate==0.3.0"
110+
#: Validate (lack of) logging format strings
111+
#: G001-G004, G010 | G100 | G200-G202
112+
- "flake8-logging-format==0.6.0"
113+
#: Find line breaks with '\'
114+
#: N400
115+
- "flake8-broken-line==0.2.0"
116+
#: Check your code against PEP 8 naming conventions
117+
#: N801-N807, N811-N817
118+
- "pep8-naming==0.10.0"
119+
#: Find mutable default assignments in func/class definitions
120+
#: M511
121+
- "flake8-mutable==1.2.0"
122+
#: Check common style issues or inconsistencies with pytest-based tests
123+
#: PT001-PT019
124+
- "flake8-pytest-style==1.1.1"
125+
#: Check if typing imports are properly guarded
126+
#: TYP001 - TYP006
127+
- "flake8-typing-imports==1.9.0"
128+
#: Find strings with leading 'u'
129+
#: UPS
130+
- "flake8-no-u-prefixed-strings==0.2"
131+
#: Make more readable variables names
132+
#: VNE001-VNE003
133+
- "flake8-variables-names==0.0.3"
134+
#: Checks for misuse of sys.version or sys.version_info (Py 3.10 / 4.0 coming)
135+
#: YTT101-YTT103 | YTT201-YTT204 | YTT301-YTT303
136+
- "flake8-2020==1.6.0"
137+
138+
139+
#: Hooks managed via tox `pre-commit` venv
140+
- repo: local
141+
hooks:
142+
#: pylint - python linter
143+
- id: pylint
144+
name: pylint
145+
entry: ./.pre_commit_tool_runner pylint pre-commit,dev
146+
language: system
147+
types: [python]
148+
#: mypy - python type checker
149+
- id: mypy
150+
args: ["--warn-unused-ignores"] # , --scripts-are-modules, --ignore-missing-imports]
151+
name: mypy
152+
entry: ./.pre_commit_tool_runner mypy pre-commit,dev
153+
language: system
154+
types: [python]
155+
156+
157+
#: Meta hooks
158+
- repo: meta
159+
hooks:
160+
- id: identity
161+
stages: [manual]
162+
- id: check-hooks-apply
163+
stages: [manual]
164+
- id: check-useless-excludes
165+
stages: [manual]

.pre_commit_tool_runner

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
"""Script to call executables in `tox` envs
3+
4+
The script takes two mandatory arguments:
5+
1. the executable to call like e.g. `pylint`
6+
2. a string with comma separated `tox` envs to check for the executable
7+
8+
All other arguments after are passed to the tool on call.
9+
10+
The script considers OS and calls the tool accordingly.
11+
"""
12+
import subprocess
13+
import sys
14+
15+
from pathlib import Path
16+
17+
18+
def main():
19+
"""Call given `tool` form given `tox` env"""
20+
tool = sys.argv[1]
21+
22+
if sys.platform == "win32":
23+
exe = Path("Scripts/" + tool + ".exe")
24+
else:
25+
exe = Path("bin/" + tool)
26+
27+
tox = Path(".tox")
28+
envs = sys.argv[2].split(",")
29+
30+
cmd = None
31+
for env in envs:
32+
path = Path(tox / env / exe)
33+
if path.is_file():
34+
cmd = (str(path), *sys.argv[3:])
35+
36+
if cmd is None:
37+
print(
38+
"No '{}' executable found. Make sure one of the "
39+
"following `tox` envs is accessible: {}".format(tool, envs)
40+
)
41+
return 1
42+
43+
return subprocess.call(cmd)
44+
45+
46+
if __name__ == "__main__":
47+
sys.exit(main())

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: python
2+
python:
3+
- "3.6"
4+
- "3.7"
5+
- "3.8"
6+
7+
notifications:
8+
email: false
9+
10+
install:
11+
- pip install -U tox-travis coverage codecov
12+
13+
script:
14+
- tox
15+
16+
after_success: coverage combine && codecov

CHANGELOG.rst

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,72 @@ commit-msg-jira-hook Change Log
55
Version numbers follow the `SemVer <https://semver.org/>`__ principle.
66
See the `tags on this repository <https://github.com/Cielquan/commit-msg-jira-hook/tags>`__ for all available versions.
77

8-
.. note::
9-
Not all commits are linked. Commits are only linked when they match the specific note.
8+
.. towncrier release notes start
109
11-
.. _changelog:
10+
v0.6.1 (2020-05-22)
11+
-------------------
1212

13+
Miscellaneous
14+
~~~~~~~~~~~~~
1315

14-
.. _changelog_060:
16+
- Added `pytest` tests with 100% coverage
17+
`#3 <https://github.com/cielquan/commit-msg-jira-hook/issues/3>`_
18+
- Added cielquan's default `pre-commit` config
19+
`#4 <https://github.com/cielquan/commit-msg-jira-hook/issues/4>`_
20+
- Added test automation with `tox`
21+
`#5 <https://github.com/cielquan/commit-msg-jira-hook/issues/5>`_
22+
- Added CI config to run `tox` in a pipeline
23+
`#6 <https://github.com/cielquan/commit-msg-jira-hook/issues/6>`_
24+
- Added `towncrier` for changelog updates
25+
`#7 <https://github.com/cielquan/commit-msg-jira-hook/issues/7>`_
1526

16-
Release 0.6.0
17-
-------------
18-
*Released: 19.05.2020*
1927

20-
- Switched from ``setuptools`` to ``poetry`` (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/535eb19f6890188f0dccfbd1a89d382fe76e8ca9>`__)
21-
- Updated Readme
28+
----
2229

2330

24-
.. _changelog_050:
31+
.. note::
32+
Release notes below were written by hand prior usage of ``towncrier``.
2533

26-
Release 0.5.0
27-
-------------
28-
*Released: 11.05.2020*
2934

30-
- Added "--verify" switch (issue #1) (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/b33810804b1c409f9d43c624196778c54f9130d2>`__)
31-
- Improved error message for missing tag or tag-number (issue #2) (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/466908305b07deb62b8b2d134f457963bc21c12e>`__)
32-
- Fixed link in changelog for v0.4.0 (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/bac155f73640fdd3f55d9dd035556a125dc843f4>`__)
33-
- Updated Readme
35+
v0.6.0 (19.05.2020)
36+
-------------------
3437

38+
- Switched from ``setuptools`` to ``poetry``
39+
- Updated Readme
3540

36-
.. _changelog_040:
3741

38-
Release 0.4.0
39-
-------------
40-
*Released: 25.04.2020*
42+
v0.5.0 (11.05.2020)
43+
-------------------
4144

42-
- Rewrote script as click command (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/1ccf15e3de7052d3068aad8067904d52d3386a6e>`__)
45+
- Added "--verify" switch
46+
`#1 <https://github.com/Cielquan/commit-msg-jira-hook/issues/1>`_
47+
- Improved error message for missing tag or tag-number
48+
`#2 <https://github.com/Cielquan/commit-msg-jira-hook/issues/2>`_
49+
- Fixed link in changelog for v0.4.0
4350
- Updated Readme
4451

4552

46-
.. _changelog_030:
53+
v0.4.0 (25.04.2020)
54+
-------------------
4755

48-
Release 0.3.0
49-
-------------
50-
*Released: 05.03.2020*
56+
- Rewrote script as click command
57+
- Updated Readme
5158

52-
- Improved output for missing keys in ini files (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/f7661a88d4f6e3483cbc2667f4c502fad248c49a>`__)
53-
- Fixed CHANGELOG.rst
5459

60+
v0.3.0 (05.03.2020)
61+
-------------------
5562

56-
.. _changelog_020:
63+
- Improved output for missing keys in ini files
64+
- Fixed CHANGELOG.rst
5765

58-
Release 0.2.0
59-
-------------
60-
*Released: 06.02.2020*
6166

62-
- Split content of jira.ini file into two files (`commit <https://github.com/Cielquan/commit-msg-jira-hook/commit/137a2a9aa3e1b41bc9cc4201bbc22a612d8df0be>`__)
67+
v0.2.0 (06.02.2020)
68+
-------------------
6369

70+
- Split content of jira.ini file into two files
6471

65-
.. _changelog__010:
6672

67-
Release 0.1.0
68-
-------------
69-
*Released: 05.02.2020*
73+
v0.1.0 (05.02.2020)
74+
-------------------
7075

7176
- Initial release

MANIFEST.in

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)