Skip to content

Commit f168671

Browse files
authored
Add pre-commit config and apply changes (#54)
- Add .pre-commit-config.yaml with initial config. - Add python black pre-commit config - Apply pre-commit code changes - Add information to CONTRIBUTING.md - Add pre-commit to build requirements - Run pre-commit during travis CI build - Use a travis build matrix to control when pre-commit runs in the CI process. Use explicit include to only run pre-commit on Python 3.9.
1 parent 217555a commit f168671

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+658
-388
lines changed

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-case-conflict
8+
- id: check-yaml
9+
- id: requirements-txt-fixer
10+
- id: mixed-line-ending
11+
- id: no-commit-to-branch
12+
args: [--branch, master]
13+
- repo: https://github.com/psf/black
14+
rev: 22.6.0
15+
hooks:
16+
- id: black

.travis.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
dist: xenial
22
language: python
3-
python:
4-
- '3.4'
5-
- '3.5'
6-
- '3.6'
7-
- '3.7'
8-
- '3.8'
9-
- '3.9'
3+
jobs:
4+
include:
5+
- python: '3.4'
6+
env: RUN_PRE_COMMIT=0
7+
- python: '3.5'
8+
env: RUN_PRE_COMMIT=0
9+
- python: '3.6'
10+
env: RUN_PRE_COMMIT=0
11+
- python: '3.7'
12+
env: RUN_PRE_COMMIT=0
13+
- python: '3.8'
14+
env: RUN_PRE_COMMIT=0
15+
- python: '3.9'
16+
env: RUN_PRE_COMMIT=1
1017
install:
1118
- pip install -U setuptools pip -r build-requirements.txt
1219
script:
20+
- if [[ $RUN_PRE_COMMIT = 1 ]]; then
21+
pip install -U pre-commit==2.12.1 &&
22+
pre-commit install &&
23+
pre-commit run --all;
24+
fi
1325
- pytest --doctest-modules --cov=anybadge --cov-report html:htmlcov anybadge tests
1426
before_deploy:
1527
- sed -i "s/^version = .*/version = __version__ = \"$TRAVIS_TAG\"/" anybadge.py
@@ -23,4 +35,4 @@ deploy:
2335
on:
2436
tags: true
2537
all_branches: true
26-
python: '3.9'
38+
python: '3.9'

CONTRIBUTING.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ I love your input! I want to make contributing to this project as easy and trans
88
- Becoming a maintainer
99

1010
## I use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow), so all code changes happen through pull requests
11-
Pull requests are the best way to propose changes to the codebase (I use
11+
Pull requests are the best way to propose changes to the codebase (I use
1212
[Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow)). I actively welcome your pull requests:
1313

1414
1. Fork the repo and create your branch from `master`
@@ -20,7 +20,7 @@ Pull requests are the best way to propose changes to the codebase (I use
2020

2121
## Any contributions you make will be under the MIT Software License
2222
When you submit code changes, your submissions are understood to be under the same
23-
[MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers
23+
[MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers
2424
if that's a concern.
2525

2626
## Report bugs using Github's [issues](https://github.com/jongracecox/anybadge/issues)
@@ -48,6 +48,42 @@ By contributing, you agree that your contributions will be licensed under its MI
4848

4949
# Technical stuff
5050

51+
## Pre-commit
52+
This projects makes use of [pre-commit](https://pre-commit.com) to add some safety checks and create consistency
53+
in the project code. When committing changes to this project, please first [install pre-commit](https://pre-commit.com/#install),
54+
then activate it for this project:
55+
56+
```bash
57+
pip install pre-commit
58+
pre-commit install
59+
```
60+
61+
After installing pre-commit to your project (with `pre-commit install`), committing to the project will trigger a series
62+
of checks, and fixers. This process may reject your commit or make changes to your code to bring it into line with the
63+
project standards. For example, [Python black](https://github.com/psf/black) will be used to reformat any code. When
64+
changes are made by these pre-commit hooks you will need to re-add and commit those changes in order for pre-commit to
65+
pass.
66+
67+
Here is some example output from pre-commit:
68+
69+
```
70+
trim trailing whitespace.................................................Failed
71+
- hook id: trailing-whitespace
72+
- exit code: 1
73+
- files were modified by this hook
74+
75+
Fixing tests/test_anybadge.py
76+
77+
fix end of files.........................................................Failed
78+
- hook id: end-of-file-fixer
79+
- exit code: 1
80+
- files were modified by this hook
81+
82+
Fixing examples/color_teal.svg
83+
```
84+
85+
This shows that two files were updated by hooks, and need to be re-added (with `git add`) before trying to commit again.
86+
5187
## Documentation
5288
The `README.md` file contains a table showing example badges for the different built-in colors. If you modify the
5389
appearance of badges, or the available colors please update the table using the following code:

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
* [ ] Add CI test for Docker image
88
* [ ] Add CI to push server to Docker hub
99
* [ ] Support common badge server URL structure
10-
* [ ] Documentation for all docker bits
10+
* [ ] Documentation for all docker bits

anybadge/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Package information
77
version = __version__ = "0.0.0"
8-
__version_info__ = tuple(re.split('[.-]', __version__))
8+
__version_info__ = tuple(re.split("[.-]", __version__))
99
__title__ = "anybadge"
1010
__summary__ = "A simple, flexible badge generator."
1111
__uri__ = "https://github.com/jongracecox/anybadge"

0 commit comments

Comments
 (0)