Skip to content

Commit a8d113b

Browse files
authored
Merge pull request pappasam#291 from pappasam/ruff-and-nox
Disparate dev tools -> ruff + nox
2 parents 55a8a51 + 0924cca commit a8d113b

16 files changed

+215
-416
lines changed

.github/workflows/testing.yaml

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,71 @@
11
name: Testing
2-
32
on:
43
push:
54
branches:
65
- main
76
pull_request:
8-
97
jobs:
108
lint:
119
runs-on: ubuntu-latest
1210
steps:
1311
- name: Checkout
1412
uses: actions/checkout@v2
15-
16-
- name: Select Python 3.9
13+
- name: Select Python 3.11
1714
uses: actions/setup-python@v2
1815
with:
19-
python-version: 3.9
16+
python-version: 3.11
2017
architecture: x64
21-
2218
- name: Install Dependencies
2319
run: |
2420
python -m pip install -U pip
2521
python -m pip install wheel
2622
python -m pip install poetry
2723
poetry install
28-
29-
- name: Run black formatter check
30-
run: poetry run black --extend-exclude test_data --check --diff jedi_language_server tests
31-
32-
- name: Run docformatter check
33-
run: poetry run docformatter --exclude test_data --check --recursive jedi_language_server tests
34-
35-
- name: Run isort check
36-
run: poetry run isort --check jedi_language_server tests/lsp_tests tests/lsp_test_client
37-
38-
- name: Run mypy check
39-
run: poetry run mypy jedi_language_server
40-
41-
- name: Run pylint
42-
run: poetry run pylint jedi_language_server tests
43-
24+
- name: Run linting
25+
run: poetry run nox -s lint
26+
- name: Run static type checking
27+
run: poetry run nox -s typecheck
4428
tests:
4529
needs: [lint]
4630
runs-on: ${{ matrix.os }}
4731
strategy:
4832
matrix:
4933
os: [ubuntu-latest, windows-latest]
50-
python-version: ["3.8", "3.9", "3.10", "3.11"]
34+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
5135
steps:
5236
- name: Checkout
5337
uses: actions/checkout@v2
54-
5538
- name: Setup, Python ${{ matrix.python-version }}
5639
uses: actions/setup-python@v2
5740
with:
5841
python-version: ${{ matrix.python-version }}
5942
architecture: x64
60-
6143
- name: Install Dependencies
6244
run: |
6345
python -m pip install -U pip
6446
python -m pip install wheel
6547
python -m pip install poetry
6648
poetry install
67-
6849
- name: Run Tests
69-
run: poetry run pytest tests
70-
50+
run: poetry run nox -s tests
7151
coverage:
7252
needs: [lint]
7353
runs-on: windows-latest
7454
steps:
7555
- name: Checkout
7656
uses: actions/checkout@v2
77-
78-
- name: Select Python 3.9
57+
- name: Select Python 3.11
7958
uses: actions/setup-python@v2
8059
with:
81-
python-version: 3.9
60+
python-version: 3.11
8261
architecture: x64
83-
8462
- name: Install Dependencies
8563
run: |
8664
python -m pip install -U pip
8765
python -m pip install wheel
8866
python -m pip install poetry
8967
poetry install
90-
9168
- name: Run Coverage
9269
env:
9370
WITH_COVERAGE: true
94-
run: poetry run pytest --cov=jedi_language_server --cov-report=term-missing tests
71+
run: poetry run nox -s coverage

.pre-commit-config.yaml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,12 @@ fail_fast: true
22
repos:
33
- repo: local
44
hooks:
5-
- id: black
6-
name: black
7-
entry: poetry run black --check --diff
8-
language: system
9-
types: [python]
10-
exclude: ^tests/test_data/
11-
- repo: local
12-
hooks:
13-
- id: docformatter
14-
name: docformatter
15-
entry: poetry run docformatter --check
16-
language: system
17-
types: [python]
18-
- repo: local
19-
hooks:
20-
- id: isort
21-
name: isort
22-
entry: poetry run isort --check
5+
- id: lint
6+
name: lint
7+
entry: poetry run nox -s lint
238
language: system
249
types: [python]
10+
pass_filenames: false
2511
exclude: ^tests/test_data/
2612
- repo: local
2713
hooks:
@@ -33,17 +19,10 @@ repos:
3319
exclude: ^poetry.lock
3420
- repo: local
3521
hooks:
36-
- id: pylint
37-
name: PyLint
38-
entry: poetry run pylint
39-
language: system
40-
types: [python]
41-
exclude: ^tests/test_data/
42-
- repo: local
43-
hooks:
44-
- id: mypy
45-
name: Mypy
46-
entry: poetry run mypy
22+
- id: typecheck
23+
name: typecheck
24+
entry: poetry run nox -s typecheck
4725
language: system
4826
types: [python]
27+
pass_filenames: false
4928
exclude: ^tests/

Makefile

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
.PHONY: help
2-
help: ## Print this help menu
2+
help: ## Print this help menu
33
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
44
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
55

66
.PHONY: require
77
require: ## Check that prerequisites are installed.
88
@if ! command -v python3 > /dev/null; then \
9-
printf "\033[1m\033[31mERROR\033[0m: python3 not installed\n" >&2 ; \
10-
exit 1; \
11-
fi
9+
printf "\033[1m\033[31mERROR\033[0m: python3 not installed\n" >&2 ; \
10+
exit 1; \
11+
fi
1212
@if ! python3 -c "import sys; sys.exit(sys.version_info < (3,8))"; then \
13-
printf "\033[1m\033[31mERROR\033[0m: python 3.8+ required\n" >&2 ; \
14-
exit 1; \
15-
fi
13+
printf "\033[1m\033[31mERROR\033[0m: python 3.8+ required\n" >&2 ; \
14+
exit 1; \
15+
fi
1616
@if ! command -v poetry > /dev/null; then \
17-
printf "\033[1m\033[31mERROR\033[0m: poetry not installed.\n" >&2 ; \
18-
printf "Please install with 'python3 -mpip install --user poetry'\n" >&2 ; \
19-
exit 1; \
20-
fi
17+
printf "\033[1m\033[31mERROR\033[0m: poetry not installed.\n" >&2 ; \
18+
printf "Please install with 'python3 -mpip install --user poetry'\n" >&2 ; \
19+
exit 1; \
20+
fi
2121

2222
.PHONY: setup
23-
setup: require .setup_complete ## Set up the local development environment
23+
setup: require .setup_complete ## Set up the local development environment
2424

25-
.setup_complete: poetry.lock ## Internal helper to run the setup.
25+
.setup_complete: poetry.lock ## Internal helper to run the setup.
2626
poetry install
2727
poetry run pre-commit install
2828
touch .setup_complete
2929

30-
.PHONY: test
31-
test: setup ## Run the tests, but only for current Python version
32-
poetry run black --extend-exclude test_data --check --diff jedi_language_server tests
33-
poetry run docformatter --exclude test_data --check --recursive jedi_language_server tests
34-
poetry run isort --check jedi_language_server tests/lsp_tests tests/lsp_test_client
35-
poetry run mypy jedi_language_server
36-
poetry run pylint jedi_language_server tests
37-
poetry run pytest tests
30+
.PHONY: fix
31+
fix: ## Fix all files in-place
32+
poetry run nox -s $@
33+
34+
.PHONY: lint
35+
lint: ## Run linters on all files
36+
poetry run nox -s $@
37+
38+
.PHONY: typecheck
39+
typecheck: ## Run static type checks
40+
poetry run nox -s $@
41+
42+
.PHONY: tests
43+
tests: ## Run unit tests
44+
poetry run nox -s $@
3845

3946
.PHONY: publish
40-
publish: setup ## Build & publish the new version
47+
publish: ## Build & publish the new version
4148
poetry build
4249
poetry publish
4350

44-
.PHONY: format
45-
format: setup ## Autoformat all files in the repo. WARNING: changes files in-place
46-
poetry run black jedi_language_server tests
47-
poetry run isort jedi_language_server tests
48-
poetry run docformatter --recursive --in-place jedi_language_server tests
49-
50-
.PHONY: clean
51+
.PHONY: clean
5152
clean: ## Remove local development environment
5253
if poetry env list | grep -q Activated; then \
53-
poetry env remove python3; \
54-
fi
54+
poetry env remove python3; \
55+
fi
5556
rm -f .setup_complete

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,18 @@ cd jedi-language-server
503503
make setup
504504
```
505505

506+
### Automatically format files
507+
508+
```bash
509+
make fix
510+
```
511+
506512
### Run tests
507513

508514
```bash
509-
make test
515+
make lint
516+
make typecheck
517+
make tests
510518
```
511519

512520
## Inspiration

jedi_language_server/initialization_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def structure(cls: type) -> Any:
149149
**{
150150
a.name: override(rename=convert_class_keys(a.name))
151151
for a in fields(cls)
152-
}
152+
},
153153
)
154154

155155

jedi_language_server/text_edit_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,14 @@ class Opcode(NamedTuple):
141141

142142

143143
def get_opcodes(old: str, new: str) -> List[Opcode]:
144-
"""Obtain typed opcodes from two files (old and new)"""
144+
"""Obtain typed opcodes from two files (old and new)."""
145145
diff = difflib.SequenceMatcher(a=old, b=new)
146146
return [Opcode(*opcode) for opcode in diff.get_opcodes()]
147147

148148

149149
# pylint: disable=too-few-public-methods
150150
class PositionLookup:
151-
"""Data structure to convert a byte offset in a file to a line number and
152-
character."""
151+
"""Data structure to convert byte offset file to line number and character."""
153152

154153
def __init__(self, code: str) -> None:
155154
# Create a list saying at what offset in the file each line starts.
@@ -160,8 +159,7 @@ def __init__(self, code: str) -> None:
160159
offset += len(line)
161160

162161
def get(self, offset: int) -> Position:
163-
"""Get the position in the file that corresponds to the given
164-
offset."""
162+
"""Get the position in the file that corresponds to the given offset."""
165163
line = bisect_right(self.line_starts, offset) - 1
166164
character = offset - self.line_starts[line]
167165
return Position(line=line, character=character)

noxfile.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Configure nox."""
2+
3+
import nox
4+
5+
NOX_SESSION = nox.session(python=False)
6+
7+
8+
@NOX_SESSION
9+
def fix(session: nox.Session):
10+
"""Fix files inplace."""
11+
session.run("ruff", "format", "-s", ".")
12+
session.run("ruff", "check", "-se", "--fix", ".")
13+
14+
15+
@NOX_SESSION
16+
def lint(session: nox.Session):
17+
"""Check file formatting that only have to do with formatting."""
18+
session.run("ruff", "format", "--check", ".")
19+
session.run("ruff", "check", ".")
20+
21+
22+
@NOX_SESSION
23+
def typecheck(session: nox.Session):
24+
session.run("mypy", "jedi_language_server")
25+
26+
27+
@NOX_SESSION
28+
def tests(session: nox.Session):
29+
session.run("pytest", "tests")
30+
31+
32+
@NOX_SESSION
33+
def coverage(session: nox.Session):
34+
session.run(
35+
"pytest",
36+
"--cov",
37+
"jedi_language_server",
38+
"--cov-report",
39+
"term-missing",
40+
"tests",
41+
)

0 commit comments

Comments
 (0)