Skip to content

Commit

Permalink
Merge pull request #8 from Cielquan/feature/tests-tox-precommit
Browse files Browse the repository at this point in the history
Feature/tests tox precommit
  • Loading branch information
Cielquan authored May 22, 2020
2 parents 48e74ab + 38af60a commit 0882712
Show file tree
Hide file tree
Showing 15 changed files with 904 additions and 114 deletions.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
* commit-msg-jira-hook version:
* Python version:
* Operating System:
* [ ] I check open and closed issues.

### Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

### What I Did

```
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
```
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ version.py

# Local backup dir
.backupfiles

# poetry lockfile
poetry.lock
165 changes: 165 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
minimum_pre_commit_version: "1.15"
default_stages: [commit, push]

repos:
#: code unspecific out-of-the-box hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: no-commit-to-branch
args: [--branch, staging, --branch, master, --pattern, release/.*]
- id: check-case-conflict
- id: name-tests-test
args: ["--django"]
- id: check-json
- id: pretty-format-json
args: ["--indent=4", "--autofix"]
- id: check-toml
- id: check-yaml
- id: detect-private-key
- id: trailing-whitespace
stages: [commit, push]
- id: end-of-file-fixer
stages: [commit, push]

#: several python code regex hooks
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.5.1
hooks:
- id: python-no-log-warn
- id: python-no-eval

#: pyupgrade - upgrade old python syntax to new
- repo: https://github.com/asottile/pyupgrade
rev: v2.4.1
hooks:
- id: pyupgrade
args: [--py36-plus]

#: seed-isort-config - fill isort's known_third_party config
- repo: https://github.com/asottile/seed-isort-config
rev: v2.1.1
hooks:
- id: seed-isort-config
args: [--application-directories, "src:."]

#: isort - sort imports
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
hooks:
- id: isort
args: [--apply, --recursive]
additional_dependencies: [toml>=0.10.1]

#: blacken-docs - black for python code in docs
- repo: https://github.com/asottile/blacken-docs
rev: v1.7.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.10b0]

#: black - python formatter
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
args: [--safe]

# TODO: 16.04.2020: Currently bandit is unusable with pre-commit .. wait for fix .. remove in tox then
# #: bandit - python code security analyzer
# - repo: https://github.com/PyCQA/bandit
# rev: 1.6.2
# hooks:
# - id: bandit
# args: ["--exclude ./.tox/*,./venv/*,./.eggs/*,./tests/*"]

#: flake8 - python linter
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.1
hooks:
- id: flake8
args: [
--count,
--statistics,
"--extend-exclude=*venv*/,*.egg,build/",
--extend-ignore=E203,
--max-line-length=88,
--max-complexity=20,
--pytest-fixture-no-parentheses,
"--format=${cyan}%(path)s${reset}:${yellow_bold}%(row)d${reset}:${green_bold}%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s",
]
additional_dependencies:
#: Colored output - needs custom format
- "flake8-colors"
#: Check for python builtins being used as variables or parameters.
#: A001-A002
- "flake8-builtins==1.5.2"
#: Finding likely bugs and design problems
#: B001-B014 | B301-B306 | B901-B903,B950
- "flake8-bugbear==20.1.4"
#: Write better list/set/dict comprehensions
#: C400-C416
- "flake8-comprehensions==3.2.2"
#: Check docstrings with PEP257
#: D100-D107 | D200-D215 | D300-D302 | D400-D417
# TODO: 16.04.2020: Wait for https://github.com/PyCQA/pydocstyle/pull/446 to fix problem with noqa before module docstrings
# - "flake8-docstrings==1.5.0"
#: Find dead/out-commented code
#: E800
- "flake8-eradicate==0.3.0"
#: Validate (lack of) logging format strings
#: G001-G004, G010 | G100 | G200-G202
- "flake8-logging-format==0.6.0"
#: Find line breaks with '\'
#: N400
- "flake8-broken-line==0.2.0"
#: Check your code against PEP 8 naming conventions
#: N801-N807, N811-N817
- "pep8-naming==0.10.0"
#: Find mutable default assignments in func/class definitions
#: M511
- "flake8-mutable==1.2.0"
#: Check common style issues or inconsistencies with pytest-based tests
#: PT001-PT019
- "flake8-pytest-style==1.1.1"
#: Check if typing imports are properly guarded
#: TYP001 - TYP006
- "flake8-typing-imports==1.9.0"
#: Find strings with leading 'u'
#: UPS
- "flake8-no-u-prefixed-strings==0.2"
#: Make more readable variables names
#: VNE001-VNE003
- "flake8-variables-names==0.0.3"
#: Checks for misuse of sys.version or sys.version_info (Py 3.10 / 4.0 coming)
#: YTT101-YTT103 | YTT201-YTT204 | YTT301-YTT303
- "flake8-2020==1.6.0"


#: Hooks managed via tox `pre-commit` venv
- repo: local
hooks:
#: pylint - python linter
- id: pylint
name: pylint
entry: ./.pre_commit_tool_runner pylint pre-commit,dev
language: system
types: [python]
#: mypy - python type checker
- id: mypy
args: ["--warn-unused-ignores"] # , --scripts-are-modules, --ignore-missing-imports]
name: mypy
entry: ./.pre_commit_tool_runner mypy pre-commit,dev
language: system
types: [python]


#: Meta hooks
- repo: meta
hooks:
- id: identity
stages: [manual]
- id: check-hooks-apply
stages: [manual]
- id: check-useless-excludes
stages: [manual]
47 changes: 47 additions & 0 deletions .pre_commit_tool_runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""Script to call executables in `tox` envs
The script takes two mandatory arguments:
1. the executable to call like e.g. `pylint`
2. a string with comma separated `tox` envs to check for the executable
All other arguments after are passed to the tool on call.
The script considers OS and calls the tool accordingly.
"""
import subprocess
import sys

from pathlib import Path


def main():
"""Call given `tool` form given `tox` env"""
tool = sys.argv[1]

if sys.platform == "win32":
exe = Path("Scripts/" + tool + ".exe")
else:
exe = Path("bin/" + tool)

tox = Path(".tox")
envs = sys.argv[2].split(",")

cmd = None
for env in envs:
path = Path(tox / env / exe)
if path.is_file():
cmd = (str(path), *sys.argv[3:])

if cmd is None:
print(
"No '{}' executable found. Make sure one of the "
"following `tox` envs is accessible: {}".format(tool, envs)
)
return 1

return subprocess.call(cmd)


if __name__ == "__main__":
sys.exit(main())
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python
python:
- "3.6"
- "3.7"
- "3.8"

notifications:
email: false

install:
- pip install -U tox-travis coverage codecov

script:
- tox

after_success: coverage combine && codecov
79 changes: 42 additions & 37 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,72 @@ commit-msg-jira-hook Change Log
Version numbers follow the `SemVer <https://semver.org/>`__ principle.
See the `tags on this repository <https://github.com/Cielquan/commit-msg-jira-hook/tags>`__ for all available versions.

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

Miscellaneous
~~~~~~~~~~~~~

.. _changelog_060:
- Added `pytest` tests with 100% coverage
`#3 <https://github.com/cielquan/commit-msg-jira-hook/issues/3>`_
- Added cielquan's default `pre-commit` config
`#4 <https://github.com/cielquan/commit-msg-jira-hook/issues/4>`_
- Added test automation with `tox`
`#5 <https://github.com/cielquan/commit-msg-jira-hook/issues/5>`_
- Added CI config to run `tox` in a pipeline
`#6 <https://github.com/cielquan/commit-msg-jira-hook/issues/6>`_
- Added `towncrier` for changelog updates
`#7 <https://github.com/cielquan/commit-msg-jira-hook/issues/7>`_

Release 0.6.0
-------------
*Released: 19.05.2020*

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


.. _changelog_050:
.. note::
Release notes below were written by hand prior usage of ``towncrier``.

Release 0.5.0
-------------
*Released: 11.05.2020*

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

- Switched from ``setuptools`` to ``poetry``
- Updated Readme

.. _changelog_040:

Release 0.4.0
-------------
*Released: 25.04.2020*
v0.5.0 (11.05.2020)
-------------------

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


.. _changelog_030:
v0.4.0 (25.04.2020)
-------------------

Release 0.3.0
-------------
*Released: 05.03.2020*
- Rewrote script as click command
- Updated Readme

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

v0.3.0 (05.03.2020)
-------------------

.. _changelog_020:
- Improved output for missing keys in ini files
- Fixed CHANGELOG.rst

Release 0.2.0
-------------
*Released: 06.02.2020*

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

- Split content of jira.ini file into two files

.. _changelog__010:

Release 0.1.0
-------------
*Released: 05.02.2020*
v0.1.0 (05.02.2020)
-------------------

- Initial release
6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

Loading

0 comments on commit 0882712

Please sign in to comment.