Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ruff and address lint #66

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: 2
updates:
# Set update schedule for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
11 changes: 8 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ jobs:
pip install codecov coverage[toml]
codecov

pre_commit:
test_lint:
name: Test Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml

test_minimum_versions:
name: Test Minimum Versions
Expand Down Expand Up @@ -116,7 +121,7 @@ jobs:
if: always()
needs:
- build
- pre_commit
- test_lint
- test_minimum_versions
- test_prereleases
- check_links
Expand Down
63 changes: 15 additions & 48 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -15,61 +18,25 @@ repos:
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
args: ["--config-file", "pyproject.toml"]
additional_dependencies: [pytest, tornado, traitlets, jupyter_client, jupyter_server]
stages: [manual]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: validate-pyproject
stages: [manual]
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]
stages: [manual]

- repo: https://github.com/john-hen/Flake8-pyproject
rev: 1.2.2
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: Flake8-pyproject
alias: flake8
additional_dependencies:
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]
- id: black

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-github-workflows
- id: ruff
args: ["--fix"]
2 changes: 1 addition & 1 deletion jupyter_server_synchronizer/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Build up version_info tuple for backwards compatibility
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
match = re.match(pattern, __version__)
assert match is not None
assert match is not None # noqa
parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
if match["rest"]:
parts.append(match["rest"])
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server_synchronizer/kernel_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def row_to_record(self, row: sqlite3.Row) -> KernelRecord:
items = {field: row[field] for field in self._table_columns}
return self.kernel_record_class(**items) # type:ignore[no-any-return]

def list(self) -> List[KernelRecord]:
def list(self) -> List[KernelRecord]: # noqa
self.cursor.execute(f"SELECT * FROM {self._table_name}")
rows = self.cursor.fetchall()
return [self.row_to_record(row) for row in rows]
Expand Down
14 changes: 7 additions & 7 deletions jupyter_server_synchronizer/kernel_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from jupyter_client.manager import KernelManager


class KernelRecordConflict(Exception):
class KernelRecordConflict(Exception): # noqa
"""An exception raised when trying to merge two
kernels that have conflicting data.
"""
Expand Down Expand Up @@ -58,18 +58,18 @@ def get_identifier_fields(cls):
def get_identifier_values(self):
"""The values of all identifiers."""
identifier_values = []
for id in self.get_identifier_fields():
if id.endswith("_id"):
identifier_values.append(getattr(self, id))
for id_ in self.get_identifier_fields():
if id_.endswith("_id"):
identifier_values.append(getattr(self, id_))
return identifier_values

def get_active_identifiers(self):
"""Return a dictionary of all identifiers that are not None."""
identifiers = {}
for id in self.get_identifier_fields():
val = getattr(self, id)
for id_ in self.get_identifier_fields():
val = getattr(self, id_)
if val is not None:
identifiers[id] = val
identifiers[id_] = val
return identifiers

def get_active_fields(self):
Expand Down
5 changes: 1 addition & 4 deletions jupyter_server_synchronizer/manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import asyncio
import uuid

from jupyter_server.services.sessions.sessionmanager import (
KernelSessionRecordList,
SessionManager,
)
from jupyter_server.services.sessions.sessionmanager import KernelSessionRecordList, SessionManager
from traitlets import Bool, Float, Instance, Type, default

from .gateway import fetch_gateway_kernels
Expand Down
66 changes: 49 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ test = [
"pytest-jupyter[server]>=0.4.1",
"pytest>=7.0",
]
lint = [
"black[jupyter]>=22.6.0",
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff>=0.0.156"
]
typing = ["mypy>=0.990"]

[tool.hatch.version]
path = "jupyter_server_synchronizer/_version.py"
Expand All @@ -65,6 +72,25 @@ dependencies = ["coverage", "pytest-cov"]
test = "python -m pytest -vv --cov jupyter_server_synchronizer --cov-branch --cov-report term-missing:skip-covered {args}"
nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["typing", "test"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:jupyter_server_synchronizer tests}"

[tool.hatch.envs.lint]
features = ["lint"]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
"mdformat --check {args:*.md}"
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"mdformat {args:*.md}"
]

[tool.jupyter-releaser.options]
post-version-spec = "dev"

Expand Down Expand Up @@ -105,23 +131,29 @@ warn_redundant_casts = true
warn_return_any = true
warn_unused_ignores = true

[tool.flake8]
ignore = "E501, W503, E402"
builtins = "c, get_config"
exclude = [
".cache",
".github",
"docs",
"setup.py",
[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py37"]

[tool.ruff]
target-version = "py37"
line-length = 100
select = [
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
"UP", "W", "YTT",
]
enable-extensions = "G"
extend-ignore = [
"G001", "G002", "G004", "G200", "G201", "G202",
# black adds spaces around ':'
"E203",
ignore = [
# FBT002 Boolean default value in function definition
"FBT002", "FBT003",
]
per-file-ignores = [
# B011: Do not call assert False since python -O removes these calls
# F841 local variable 'foo' is assigned to but never used
"tests/*: B011", "F841",
unfixable = [
# Don't touch print statements
"T201",
# Don't touch noqa lines
"RUF100",
]

[tool.ruff.per-file-ignores]
# S101 Use of `assert` detected
"tests/*" = ["S101"]
2 changes: 1 addition & 1 deletion tests/test_kernel_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_database_is_created(jp_environ, jp_runtime_dir):
path = jp_runtime_dir / "jupyter-session.db"
table = KernelTable(database_filepath=str(path))
con = table.connection
_ = table.connection
assert path.exists()


Expand Down