Skip to content

Commit

Permalink
Merge pull request #291 from pappasam/ruff-and-nox
Browse files Browse the repository at this point in the history
Disparate dev tools -> ruff + nox
  • Loading branch information
pappasam authored Oct 28, 2023
2 parents 55a8a51 + 0924cca commit a8d113b
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 416 deletions.
45 changes: 11 additions & 34 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -1,94 +1,71 @@
name: Testing

on:
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Select Python 3.9
- name: Select Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install
- name: Run black formatter check
run: poetry run black --extend-exclude test_data --check --diff jedi_language_server tests

- name: Run docformatter check
run: poetry run docformatter --exclude test_data --check --recursive jedi_language_server tests

- name: Run isort check
run: poetry run isort --check jedi_language_server tests/lsp_tests tests/lsp_test_client

- name: Run mypy check
run: poetry run mypy jedi_language_server

- name: Run pylint
run: poetry run pylint jedi_language_server tests

- name: Run linting
run: poetry run nox -s lint
- name: Run static type checking
run: poetry run nox -s typecheck
tests:
needs: [lint]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup, Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install
- name: Run Tests
run: poetry run pytest tests

run: poetry run nox -s tests
coverage:
needs: [lint]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Select Python 3.9
- name: Select Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
architecture: x64

- name: Install Dependencies
run: |
python -m pip install -U pip
python -m pip install wheel
python -m pip install poetry
poetry install
- name: Run Coverage
env:
WITH_COVERAGE: true
run: poetry run pytest --cov=jedi_language_server --cov-report=term-missing tests
run: poetry run nox -s coverage
37 changes: 8 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@ fail_fast: true
repos:
- repo: local
hooks:
- id: black
name: black
entry: poetry run black --check --diff
language: system
types: [python]
exclude: ^tests/test_data/
- repo: local
hooks:
- id: docformatter
name: docformatter
entry: poetry run docformatter --check
language: system
types: [python]
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort --check
- id: lint
name: lint
entry: poetry run nox -s lint
language: system
types: [python]
pass_filenames: false
exclude: ^tests/test_data/
- repo: local
hooks:
Expand All @@ -33,17 +19,10 @@ repos:
exclude: ^poetry.lock
- repo: local
hooks:
- id: pylint
name: PyLint
entry: poetry run pylint
language: system
types: [python]
exclude: ^tests/test_data/
- repo: local
hooks:
- id: mypy
name: Mypy
entry: poetry run mypy
- id: typecheck
name: typecheck
entry: poetry run nox -s typecheck
language: system
types: [python]
pass_filenames: false
exclude: ^tests/
63 changes: 32 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
.PHONY: help
help: ## Print this help menu
help: ## Print this help menu
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: require
require: ## Check that prerequisites are installed.
@if ! command -v python3 > /dev/null; then \
printf "\033[1m\033[31mERROR\033[0m: python3 not installed\n" >&2 ; \
exit 1; \
fi
printf "\033[1m\033[31mERROR\033[0m: python3 not installed\n" >&2 ; \
exit 1; \
fi
@if ! python3 -c "import sys; sys.exit(sys.version_info < (3,8))"; then \
printf "\033[1m\033[31mERROR\033[0m: python 3.8+ required\n" >&2 ; \
exit 1; \
fi
printf "\033[1m\033[31mERROR\033[0m: python 3.8+ required\n" >&2 ; \
exit 1; \
fi
@if ! command -v poetry > /dev/null; then \
printf "\033[1m\033[31mERROR\033[0m: poetry not installed.\n" >&2 ; \
printf "Please install with 'python3 -mpip install --user poetry'\n" >&2 ; \
exit 1; \
fi
printf "\033[1m\033[31mERROR\033[0m: poetry not installed.\n" >&2 ; \
printf "Please install with 'python3 -mpip install --user poetry'\n" >&2 ; \
exit 1; \
fi

.PHONY: setup
setup: require .setup_complete ## Set up the local development environment
setup: require .setup_complete ## Set up the local development environment

.setup_complete: poetry.lock ## Internal helper to run the setup.
.setup_complete: poetry.lock ## Internal helper to run the setup.
poetry install
poetry run pre-commit install
touch .setup_complete

.PHONY: test
test: setup ## Run the tests, but only for current Python version
poetry run black --extend-exclude test_data --check --diff jedi_language_server tests
poetry run docformatter --exclude test_data --check --recursive jedi_language_server tests
poetry run isort --check jedi_language_server tests/lsp_tests tests/lsp_test_client
poetry run mypy jedi_language_server
poetry run pylint jedi_language_server tests
poetry run pytest tests
.PHONY: fix
fix: ## Fix all files in-place
poetry run nox -s $@

.PHONY: lint
lint: ## Run linters on all files
poetry run nox -s $@

.PHONY: typecheck
typecheck: ## Run static type checks
poetry run nox -s $@

.PHONY: tests
tests: ## Run unit tests
poetry run nox -s $@

.PHONY: publish
publish: setup ## Build & publish the new version
publish: ## Build & publish the new version
poetry build
poetry publish

.PHONY: format
format: setup ## Autoformat all files in the repo. WARNING: changes files in-place
poetry run black jedi_language_server tests
poetry run isort jedi_language_server tests
poetry run docformatter --recursive --in-place jedi_language_server tests

.PHONY: clean
.PHONY: clean
clean: ## Remove local development environment
if poetry env list | grep -q Activated; then \
poetry env remove python3; \
fi
poetry env remove python3; \
fi
rm -f .setup_complete
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,18 @@ cd jedi-language-server
make setup
```

### Automatically format files

```bash
make fix
```

### Run tests

```bash
make test
make lint
make typecheck
make tests
```

## Inspiration
Expand Down
2 changes: 1 addition & 1 deletion jedi_language_server/initialization_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def structure(cls: type) -> Any:
**{
a.name: override(rename=convert_class_keys(a.name))
for a in fields(cls)
}
},
)


Expand Down
8 changes: 3 additions & 5 deletions jedi_language_server/text_edit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ class Opcode(NamedTuple):


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


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

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

def get(self, offset: int) -> Position:
"""Get the position in the file that corresponds to the given
offset."""
"""Get the position in the file that corresponds to the given offset."""
line = bisect_right(self.line_starts, offset) - 1
character = offset - self.line_starts[line]
return Position(line=line, character=character)
41 changes: 41 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Configure nox."""

import nox

NOX_SESSION = nox.session(python=False)


@NOX_SESSION
def fix(session: nox.Session):
"""Fix files inplace."""
session.run("ruff", "format", "-s", ".")
session.run("ruff", "check", "-se", "--fix", ".")


@NOX_SESSION
def lint(session: nox.Session):
"""Check file formatting that only have to do with formatting."""
session.run("ruff", "format", "--check", ".")
session.run("ruff", "check", ".")


@NOX_SESSION
def typecheck(session: nox.Session):
session.run("mypy", "jedi_language_server")


@NOX_SESSION
def tests(session: nox.Session):
session.run("pytest", "tests")


@NOX_SESSION
def coverage(session: nox.Session):
session.run(
"pytest",
"--cov",
"jedi_language_server",
"--cov-report",
"term-missing",
"tests",
)
Loading

0 comments on commit a8d113b

Please sign in to comment.