Skip to content

Commit 933c310

Browse files
committed
Add pre-commit hooks
1 parent ec1e39c commit 933c310

File tree

8 files changed

+93
-52
lines changed

8 files changed

+93
-52
lines changed

.github/workflows/python.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ jobs:
2020
python-version: ${{ matrix.python-version }}
2121
- name: Install dependencies
2222
run: python -m pip install -e .[dev]
23-
- name: Flake8 lint
24-
run: flake8 .
25-
- name: Black lint
26-
run: black --diff --check .
27-
- name: isort lint
28-
run: isort --check --diff .
29-
- name: MyPy lint
30-
run: mypy .
31-
- name: Test
23+
- name: pre-commit checks
24+
uses: pre-commit/action@v2.0.2
25+
- name: Tests
3226
run: pytest -v tests/

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
- repo: https://github.com/PyCQA/isort
3+
rev: 5.10.1
4+
hooks:
5+
- id: isort
6+
- repo: https://github.com/psf/black
7+
rev: 21.11b1
8+
hooks:
9+
- id: black
10+
exclude: fixtures
11+
args: [--check, --config=pyproject.toml]
12+
- repo: https://gitlab.com/pycqa/flake8
13+
rev: 3.9.2
14+
hooks:
15+
- id: flake8
16+
- repo: https://github.com/pre-commit/mirrors-mypy
17+
rev: v0.910-1
18+
hooks:
19+
- id: mypy
20+
additional_dependencies: [black, types-pkg_resources, types-setuptools, types-toml]
21+
- repo: https://github.com/pre-commit/pre-commit-hooks
22+
rev: v4.0.1
23+
hooks:
24+
- id: check-merge-conflict
25+
- id: debug-statements
26+
- repo: https://github.com/executablebooks/mdformat
27+
rev: 0.7.10
28+
hooks:
29+
- id: mdformat
30+
additional_dependencies:
31+
- mdformat-gfm

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
### Issues Closed
44

5-
* [Issue 3](https://github.com/python-lsp/python-lsp-black/issues/3) - Update README and add RELEASE instructions
6-
* [Issue 2](https://github.com/python-lsp/python-lsp-black/issues/2) - Release v1.0.0
5+
- [Issue 3](https://github.com/python-lsp/python-lsp-black/issues/3) - Update README and add RELEASE instructions
6+
- [Issue 2](https://github.com/python-lsp/python-lsp-black/issues/2) - Release v1.0.0
77

88
In this release 2 issues were closed.
99

1010
### Pull Requests Merged
1111

12-
* [PR 1](https://github.com/python-lsp/python-lsp-black/pull/1) - PR: Python LSP server migration, by [@andfoy](https://github.com/andfoy)
12+
- [PR 1](https://github.com/python-lsp/python-lsp-black/pull/1) - PR: Python LSP server migration, by [@andfoy](https://github.com/andfoy)
1313

1414
In this release 1 pull request was closed.

MAINTENANCE.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
The following are instructions to maintain python-lsp-black
2+
23
1. Releases are tracked using Github milestones, which can be created and closed
3-
under the `Issues > Milestones` page: https://github.com/python-lsp/python-lsp-black/milestones.
4-
2. If a issue will be fixed as part of a particular release, then its milestone
5-
should be the release-corresponding one.
6-
3. Please make sure that PRs are also tracked under a specific milestone.
7-
4. Please follow the [RELEASE.md](./RELEASE.md) file when making a release.
4+
under the `Issues > Milestones` page: https://github.com/python-lsp/python-lsp-black/milestones.
5+
1. If a issue will be fixed as part of a particular release, then its milestone
6+
should be the release-corresponding one.
7+
1. Please make sure that PRs are also tracked under a specific milestone.
8+
1. Please follow the [RELEASE.md](./RELEASE.md) file when making a release.

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
lint: flake8 black-check isort-check mypy
2-
3-
flake8:
4-
flake8 .
1+
lint:
2+
pre-commit run -a
53

64
black:
7-
black .
5+
pre-commit run -a black
86

9-
black-check:
10-
black --diff --check .
7+
flake8:
8+
pre-commit run -a flake8
119

1210
isort:
13-
isort .
11+
pre-commit run -a isort
1412

15-
isort-check:
16-
isort --check-only .
13+
markdown:
14+
pre-commit run -a mdformat
1715

1816
mypy:
19-
mypy .
17+
pre-commit run -a mypy
2018

2119
test:
2220
pytest -v .

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![PyPI](https://img.shields.io/pypi/v/pyls-black.svg)](https://pypi.org/project/python-lsp-black) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
44
[![Python](https://github.com/python-lsp/python-lsp-black/actions/workflows/python.yml/badge.svg)](https://github.com/python-lsp/python-lsp-black/actions/workflows/python.yml)
55

6-
76
> [Black](https://github.com/ambv/black) plugin for the [Python LSP Server](https://github.com/python-lsp/python-lsp-server).
87
98
## Install
@@ -18,11 +17,11 @@ pip install python-lsp-black
1817

1918
To avoid unexpected results you should make sure `yapf` and `autopep8` are not installed.
2019

21-
* `python-lsp-black` can either format an entire file or just the selected text.
22-
* The code will only be formatted if it is syntactically valid Python.
23-
* Text selections are treated as if they were a separate Python file.
20+
- `python-lsp-black` can either format an entire file or just the selected text.
21+
- The code will only be formatted if it is syntactically valid Python.
22+
- Text selections are treated as if they were a separate Python file.
2423
Unfortunately this means you can't format an indented block of code.
25-
* `python-lsp-black` will use your project's [pyproject.toml](https://github.com/ambv/black#pyprojecttoml) if it has one.
24+
- `python-lsp-black` will use your project's [pyproject.toml](https://github.com/ambv/black#pyprojecttoml) if it has one.
2625

2726
# Development
2827

@@ -34,14 +33,30 @@ python -m venv .venv
3433
pip install -e .[dev]
3534
```
3635

36+
This project uses [pre-commit](https://pre-commit.com/) hooks to control code quality,
37+
install them to run them when creating a git commit, thus avoiding seeing errors when you
38+
create a pull request:
39+
40+
```shell
41+
pre-commit install
42+
```
43+
3744
To run tests:
3845

3946
```shell
4047
make test
4148
```
4249

43-
To run linters (flake8, black, isort, mypy...)
50+
To run linters:
51+
52+
```shell
53+
make lint # just a shortcut to pre-commit run -a
54+
make <linter_name> # black, flake8, isort, markdown, mypy
55+
```
56+
57+
To upgrade the version of the pre-commit hooks:
4458

4559
```shell
46-
make lint
60+
pre-commit autoupdate
61+
# check and git commit changes to .pre-commit-config.yaml
4762
```

RELEASE.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
To release a new version of python-lsp-black:
2+
23
1. git fetch upstream && git checkout upstream/master
3-
2. Close milestone on GitHub
4-
3. git clean -xfdi
5-
4. Update CHANGELOG.md with loghub: `loghub python-lsp/python-lsp-black --milestone vX.X.X`
6-
5. git add -A && git commit -m "Update Changelog"
7-
6. Update release version in ``setup.cfg`` (set release version, remove '.dev0')
8-
7. git add -A && git commit -m "Release vX.X.X"
9-
8. python setup.py sdist
10-
9. python setup.py bdist_wheel
11-
10. twine check dist/*
12-
11. twine upload dist/*
13-
12. git tag -a vX.X.X -m "Release vX.X.X"
14-
13. Update development version in ``setup.cfg`` (add '.dev0' and increment minor)
15-
14. git add -A && git commit -m "Back to work"
16-
15. git push upstream master
17-
16. git push upstream --tags
18-
17. Draft a new release in GitHub using the new tag.
4+
1. Close milestone on GitHub
5+
1. git clean -xfdi
6+
1. Update CHANGELOG.md with loghub: `loghub python-lsp/python-lsp-black --milestone vX.X.X`
7+
1. git add -A && git commit -m "Update Changelog"
8+
1. Update release version in `setup.cfg` (set release version, remove '.dev0')
9+
1. git add -A && git commit -m "Release vX.X.X"
10+
1. python setup.py sdist
11+
1. python setup.py bdist_wheel
12+
1. twine check dist/\*
13+
1. twine upload dist/\*
14+
1. git tag -a vX.X.X -m "Release vX.X.X"
15+
1. Update development version in `setup.cfg` (add '.dev0' and increment minor)
16+
1. git add -A && git commit -m "Back to work"
17+
1. git push upstream master
18+
1. git push upstream --tags
19+
1. Draft a new release in GitHub using the new tag.

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ python_requires = >= 3.6
2121
pylsp = pylsp_black = pylsp_black.plugin
2222

2323
[options.extras_require]
24-
dev = isort>=5.0; flake8; pytest; mypy; pytest; types-pkg_resources; types-toml
24+
# add any types-* packages to .pre-commit-config.yaml mypy additional_dependencies
25+
dev = isort>=5.0; flake8; pre-commit; pytest; mypy; pytest; types-pkg_resources; types-setuptools; types-toml
2526

2627
[flake8]
2728
max-line-length = 88

0 commit comments

Comments
 (0)