Skip to content

Commit 770cd3e

Browse files
authored
Adopt ruff and use less pre-commit (#1114)
1 parent 7b8008e commit 770cd3e

Some content is hidden

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

59 files changed

+537
-503
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
version: 2
22
updates:
3-
# Set update schedule for GitHub Actions
3+
# GitHub Actions
44
- package-ecosystem: "github-actions"
55
directory: "/"
66
schedule:
7-
# Check for updates to GitHub Actions every weekday
7+
interval: "weekly"
8+
# Python
9+
- package-ecosystem: "pip"
10+
directory: "/"
11+
schedule:
812
interval: "weekly"

.github/workflows/python-tests.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,28 @@ jobs:
5151
pip install codecov coverage[toml]
5252
codecov
5353
54-
pre_commit:
55-
name: pre-commit
54+
test_docs:
55+
name: Test Docs
5656
runs-on: ubuntu-latest
5757
steps:
5858
- uses: actions/checkout@v3
5959
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
60-
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
60+
- run: hatch run docs:build
6161

62-
test_docs:
63-
name: Test Docs
62+
test_lint:
63+
name: Test Lint
6464
runs-on: ubuntu-latest
6565
steps:
6666
- uses: actions/checkout@v3
6767
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
68-
- run: hatch run docs:build
68+
- name: Run Linters
69+
run: |
70+
hatch run typing:test
71+
hatch run lint:style
72+
pipx run 'validate-pyproject[all]' pyproject.toml
73+
pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst
74+
npm install -g eslint
75+
eslint .
6976
7077
test_examples:
7178
name: Test Examples
@@ -157,8 +164,8 @@ jobs:
157164
if: always()
158165
needs:
159166
- build
160-
- pre_commit
161167
- test_docs
168+
- test_lint
162169
- test_minimum_versions
163170
- test_prereleases
164171
- check_links

.pre-commit-config.yaml

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
default_language_version:
2-
node: system
1+
ci:
2+
autoupdate_schedule: monthly
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -18,64 +18,23 @@ repos:
1818
- id: check-builtin-literals
1919
- id: trailing-whitespace
2020

21-
- repo: https://github.com/psf/black
22-
rev: 22.10.0
23-
hooks:
24-
- id: black
25-
26-
- repo: https://github.com/PyCQA/isort
27-
rev: 5.10.1
28-
hooks:
29-
- id: isort
30-
files: \.py$
31-
32-
- repo: https://github.com/pre-commit/mirrors-mypy
33-
rev: v0.991
34-
hooks:
35-
- id: mypy
36-
additional_dependencies: [types-requests]
37-
38-
- repo: https://github.com/abravalheri/validate-pyproject
39-
rev: v0.10.1
21+
- repo: https://github.com/python-jsonschema/check-jsonschema
22+
rev: 0.19.2
4023
hooks:
41-
- id: validate-pyproject
42-
stages: [manual]
24+
- id: check-github-workflows
4325

4426
- repo: https://github.com/executablebooks/mdformat
4527
rev: 0.7.16
4628
hooks:
4729
- id: mdformat
4830

49-
- repo: https://github.com/asottile/pyupgrade
50-
rev: v3.3.0
51-
hooks:
52-
- id: pyupgrade
53-
args: [--py38-plus]
54-
55-
- repo: https://github.com/PyCQA/doc8
56-
rev: v1.0.0
57-
hooks:
58-
- id: doc8
59-
args: [--max-line-length=200]
60-
exclude: docs/source/other/full-config.rst
61-
stages: [manual]
62-
63-
- repo: https://github.com/john-hen/Flake8-pyproject
64-
rev: 1.2.2
65-
hooks:
66-
- id: Flake8-pyproject
67-
alias: flake8
68-
additional_dependencies:
69-
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
70-
stages: [manual]
71-
72-
- repo: https://github.com/pre-commit/mirrors-eslint
73-
rev: v8.29.0
31+
- repo: https://github.com/psf/black
32+
rev: 22.10.0
7433
hooks:
75-
- id: eslint
76-
stages: [manual]
34+
- id: black
7735

78-
- repo: https://github.com/python-jsonschema/check-jsonschema
79-
rev: 0.19.2
36+
- repo: https://github.com/charliermarsh/ruff-pre-commit
37+
rev: v0.0.165
8038
hooks:
81-
- id: check-github-workflows
39+
- id: ruff
40+
args: ["--fix"]

CONTRIBUTING.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ from any directory in your system with::
3838
jupyter server
3939

4040

41-
Code Styling
42-
-----------------------------
41+
Code Styling and Quality Checks
42+
-------------------------------
4343
`jupyter_server` has adopted automatic code formatting so you shouldn't
4444
need to worry too much about your code style.
4545
As long as your code is valid,
@@ -69,6 +69,11 @@ yourself after that.
6969
Some of the hooks only run on CI by default, but you can invoke them by
7070
running with the ``--hook-stage manual`` argument.
7171

72+
There are three hatch scripts that can be run locally as well:
73+
``hatch run lint:style`` will check styling. ``hatch run lint:fmt``
74+
will attempt to auto-format files. ``hatch run typing:test`` will
75+
run the type checker.
76+
7277
Troubleshooting the Installation
7378
--------------------------------
7479

docs/source/conf.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
14+
import logging
1415
import os
1516
import os.path as osp
1617
import shutil
@@ -27,26 +28,28 @@
2728
# documentation root, use os.path.abspath to make it absolute, like shown here.
2829

2930
# DEBUG for RTD
30-
print("DEBUG:: sys.path")
31-
print("================")
31+
log = logging.getLogger(__name__)
32+
info = log.info
33+
info("DEBUG:: sys.path")
34+
info("================")
3235
for item in sys.path:
33-
print(item)
36+
info(item)
3437

3538
# add repo root to sys.path
3639
# here = root/docs/source
3740
here = os.path.abspath(os.path.dirname(__file__))
3841
repo_root = os.path.dirname(os.path.dirname(here))
3942
sys.path.insert(0, repo_root)
4043

41-
print("repo_root")
42-
print("=====================")
43-
print(repo_root)
44+
info("repo_root")
45+
info("=====================")
46+
info(repo_root)
4447

4548
# DEBUG for post insert on RTD
46-
print("DEBUG:: Post insert to sys.path")
47-
print("===============================")
49+
info("DEBUG:: Post insert to sys.path")
50+
info("===============================")
4851
for item in sys.path:
49-
print(item)
52+
info(item)
5053

5154
# Check if docs are being built by ReadTheDocs
5255
# If so, generate a config.rst file and populate it with documentation about
@@ -57,7 +60,7 @@
5760
# Readthedocs doesn't run our Makefile, so we do this to force it to generate
5861
# the config docs.
5962
with open("../autogen_config.py") as f:
60-
exec(compile(f.read(), "../autogen_config.py", "exec"), {})
63+
exec(compile(f.read(), "../autogen_config.py", "exec"), {}) # noqa
6164

6265
# -- General configuration ------------------------------------------------
6366

@@ -112,7 +115,7 @@
112115
__version__ = version("jupyter_server")
113116
# The short X.Y version.
114117
version_parsed = parse_version(__version__)
115-
version = f"{version_parsed.major}.{version_parsed.minor}" # type:ignore[assignment]
118+
version = f"{version_parsed.major}.{version_parsed.minor}" # type:ignore
116119

117120
# The language for content autogenerated by Sphinx. Refer to documentation
118121
# for a list of supported languages.

examples/simple/setup.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from jupyter_packaging import create_cmdclass
3+
from jupyter_packaging import create_cmdclass # type:ignore
44
from setuptools import setup
55

66
VERSION = "0.0.1"
@@ -32,29 +32,29 @@ def add_data_files(path):
3232

3333
cmdclass = create_cmdclass(data_files_spec=get_data_files())
3434

35-
setup_args = dict(
36-
name="jupyter_server_example",
37-
version=VERSION,
38-
description="Jupyter Server Example",
39-
long_description=open("README.md").read(),
40-
python_requires=">=3.8",
41-
install_requires=[
35+
setup_args = {
36+
"name": "jupyter_server_example",
37+
"version": VERSION,
38+
"description": "Jupyter Server Example",
39+
"long_description": open("README.md").read(),
40+
"python_requires": ">=3.8",
41+
"install_requires": [
4242
"jupyter_server",
4343
"jinja2",
4444
],
45-
extras_require={
45+
"extras_require": {
4646
"test": ["pytest", "pytest-asyncio"],
4747
},
48-
include_package_data=True,
49-
cmdclass=cmdclass,
50-
entry_points={
48+
"include_package_data": True,
49+
"cmdclass": cmdclass,
50+
"entry_points": {
5151
"console_scripts": [
5252
"jupyter-simple-ext1 = simple_ext1.application:main",
5353
"jupyter-simple-ext11 = simple_ext11.application:main",
5454
"jupyter-simple-ext2 = simple_ext2.application:main",
5555
]
5656
},
57-
)
57+
}
5858

5959

6060
if __name__ == "__main__":

examples/simple/simple_ext1/application.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class SimpleApp1(ExtensionAppJinjaMixin, ExtensionApp):
3434
# Local path to templates directory.
3535
template_paths = [DEFAULT_TEMPLATE_FILES_PATH]
3636

37-
configA = Unicode("", config=True, help="Config A example.")
37+
configA = Unicode("", config=True, help="Config A example.") # noqa
3838

39-
configB = Unicode("", config=True, help="Config B example.")
39+
configB = Unicode("", config=True, help="Config B example.") # noqa
4040

41-
configC = Unicode("", config=True, help="Config C example.")
41+
configC = Unicode("", config=True, help="Config C example.") # noqa
4242

4343
def initialize_handlers(self):
4444
self.handlers.extend(

examples/simple/simple_ext1/handlers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from jupyter_server.auth import authorized
22
from jupyter_server.base.handlers import JupyterHandler
3-
from jupyter_server.extension.handler import (
4-
ExtensionHandlerJinjaMixin,
5-
ExtensionHandlerMixin,
6-
)
3+
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin, ExtensionHandlerMixin
74
from jupyter_server.utils import url_escape
85

96

examples/simple/simple_ext11/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from simple_ext1.application import SimpleApp1
3+
from simple_ext1.application import SimpleApp1 # type:ignore
44
from traitlets import Bool, Unicode, observe
55

66
from jupyter_server.serverapp import aliases, flags

examples/simple/simple_ext2/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SimpleApp2(ExtensionAppJinjaMixin, ExtensionApp):
2727
# Local path to templates directory.
2828
template_paths = [DEFAULT_TEMPLATE_FILES_PATH]
2929

30-
configD = Unicode("", config=True, help="Config D example.")
30+
configD = Unicode("", config=True, help="Config D example.") # noqa
3131

3232
def initialize_handlers(self):
3333
self.handlers.extend(

0 commit comments

Comments
 (0)