Skip to content

Commit 3800504

Browse files
authored
A bunch of pre-commit and CI upgrade. (#412)
* safe ruff fixes * some unsafe fixes * Tweak ignored rules * more unsafe fixes * more ruff fixes * Fix all newer issues after pre-commit upgrade
1 parent ac3faeb commit 3800504

18 files changed

+69
-53
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
os: [ubuntu-latest, windows-latest, macos-latest]
31-
python-version: ["3.8", "3.12"]
31+
python-version: ["3.8", "3.12", "3.13"]
3232
include:
3333
- os: windows-latest
3434
python-version: "3.9"
@@ -41,6 +41,9 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v4
4343
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
44+
- name: Lint
45+
run: |
46+
hatch run typing:test
4447
- name: Test
4548
run: |
4649
hatch run cov:test

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.5.0
7+
rev: v5.0.0
88
hooks:
99
- id: check-case-conflict
1010
- id: check-ast
@@ -21,12 +21,12 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.4
24+
rev: 0.31.2
2525
hooks:
2626
- id: check-github-workflows
2727

2828
- repo: https://github.com/executablebooks/mdformat
29-
rev: 0.7.17
29+
rev: 0.7.22
3030
hooks:
3131
- id: mdformat
3232
additional_dependencies:
@@ -39,22 +39,22 @@ repos:
3939
types_or: [yaml, html, json]
4040

4141
- repo: https://github.com/adamchainz/blacken-docs
42-
rev: "1.16.0"
42+
rev: "1.19.1"
4343
hooks:
4444
- id: blacken-docs
4545
additional_dependencies: [black==23.7.0]
4646

4747
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: "v1.8.0"
48+
rev: "v1.15.0"
4949
hooks:
5050
- id: mypy
5151
files: jupyter_core
5252
stages: [manual]
53-
args: ["--install-types", "--non-interactive"]
54-
additional_dependencies: ["traitlets>=5.13", "platformdirs>=3.11"]
53+
additional_dependencies:
54+
["traitlets>=5.13", "platformdirs>=3.11", "argcomplete"]
5555

5656
- repo: https://github.com/codespell-project/codespell
57-
rev: "v2.2.6"
57+
rev: "v2.4.1"
5858
hooks:
5959
- id: codespell
6060
args: ["-L", "re-use"]
@@ -67,7 +67,7 @@ repos:
6767
- id: rst-inline-touching-normal
6868

6969
- repo: https://github.com/astral-sh/ruff-pre-commit
70-
rev: v0.2.0
70+
rev: v0.9.7
7171
hooks:
7272
- id: ruff
7373
types_or: [python, jupyter]
@@ -76,7 +76,7 @@ repos:
7676
types_or: [python, jupyter]
7777

7878
- repo: https://github.com/scientific-python/cookie
79-
rev: "2024.01.24"
79+
rev: "2025.01.22"
8080
hooks:
8181
- id: sp-repo-review
8282
additional_dependencies: ["repo-review[cli]"]

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ We now make the assumption that if we are running in a virtual environment, we s
339339

340340
#### Migrate to Standard Platform Directories
341341

342-
In version 5, we introduce a `JUPYTER_PLATFORM_DIRS` environment variable to opt in to using more appropriate platform-specific directories. We raise a deprecation warning if the variable is not set. In version 6, `JUPYTER_PLATFORM_DIRS` will be opt-out. In version 7, we will remove the environment variable checks and old directory logic.
342+
In version 5, we introduce a `JUPYTER_PLATFORM_DIRS` environment variable to opt in to using more appropriate platform-specific directories. We raise a deprecation warning if the variable is not set. In version 6, `JUPYTER_PLATFORM_DIRS` will be opt-out. In version 7, we will remove the environment variable checks and old directory logic.
343343

344344
#### Drop Support for Python 3.7
345345

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
# built documents.
7070
#
7171
# The short X.Y version.
72-
version = "%d.%d" % version_info[:2] # type:ignore[str-format]
72+
major, minor = version_info[:2]
73+
version = f"{major}.{minor}"
7374
# The full version, including alpha/beta/rc tags.
7475
release = __version__
7576

jupyter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Launch the root jupyter command"""
2+
23
from __future__ import annotations
34

45
if __name__ == "__main__":

jupyter_core/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Launch the root jupyter command"""
2+
23
from __future__ import annotations
34

45
from .command import main

jupyter_core/application.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def _config_file_name_default(self) -> str:
133133

134134
def write_default_config(self) -> None:
135135
"""Write our default config to a .py config file"""
136+
config_file: str
136137
if self.config_file:
137138
config_file = self.config_file
138139
else:
@@ -142,7 +143,7 @@ def write_default_config(self) -> None:
142143
answer = ""
143144

144145
def ask() -> str:
145-
prompt = "Overwrite %s with default config? [y/N]" % config_file
146+
prompt = f"Overwrite {config_file!r} with default config? [y/N]"
146147
try:
147148
return input(prompt).lower() or "n"
148149
except KeyboardInterrupt:
@@ -157,7 +158,7 @@ def ask() -> str:
157158
return
158159

159160
config_text = self.generate_config_file()
160-
print("Writing default config to: %s" % config_file)
161+
print("Writing default config to: {config_file!r}")
161162
ensure_dir_exists(Path(config_file).parent.resolve(), 0o700)
162163
with Path.open(Path(config_file), mode="w", encoding="utf-8") as f:
163164
f.write(config_text)

jupyter_core/command.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ class JupyterParser(argparse.ArgumentParser):
2828
"""A Jupyter argument parser."""
2929

3030
@property
31-
def epilog(self) -> str | None:
31+
def epilog(self) -> str:
3232
"""Add subcommands to epilog on request
3333
3434
Avoids searching PATH for subcommands unless help output is requested.
3535
"""
36-
return "Available subcommands: %s" % " ".join(list_subcommands())
36+
subcommands: str = " ".join(list_subcommands())
37+
return f"Available subcommands: {subcommands}"
3738

3839
@epilog.setter
3940
def epilog(self, x: Any) -> None:
@@ -42,7 +43,7 @@ def epilog(self, x: Any) -> None:
4243
def argcomplete(self) -> None:
4344
"""Trigger auto-completion, if enabled"""
4445
try:
45-
import argcomplete # type: ignore[import-not-found]
46+
import argcomplete
4647

4748
argcomplete.autocomplete(self)
4849
except ImportError:
@@ -119,7 +120,8 @@ def _execvp(cmd: str, argv: list[str]) -> None:
119120
# so rely on shutil.which
120121
cmd_path = which(cmd)
121122
if cmd_path is None:
122-
raise OSError("%r not found" % cmd, errno.ENOENT)
123+
msg = f"{cmd!r} not found"
124+
raise OSError(msg, errno.ENOENT)
123125
p = Popen([cmd_path] + argv[1:]) # noqa: S603
124126
# Don't raise KeyboardInterrupt in the parent process.
125127
# Set this after spawning, to avoid subprocess inheriting handler.
@@ -377,7 +379,7 @@ def main() -> None:
377379

378380
for name in sorted(data):
379381
path = data[name]
380-
print("%s:" % name)
382+
print(f"{name}:")
381383
for p in path:
382384
print(" " + p)
383385
return

jupyter_core/paths.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def jupyter_data_dir() -> str:
174174

175175
if sys.platform == "darwin":
176176
return str(Path(home, "Library", "Jupyter"))
177-
if sys.platform == "win32":
177+
if sys.platform == "win32": # type: ignore[unreachable]
178178
appdata = os.environ.get("APPDATA", None)
179179
if appdata:
180180
return str(Path(appdata, "jupyter").resolve())
@@ -292,18 +292,17 @@ def jupyter_path(*subdirs: str) -> list[str]:
292292
SYSTEM_CONFIG_PATH = platformdirs.site_config_dir(
293293
APPNAME, appauthor=False, multipath=True
294294
).split(os.pathsep)
295+
elif os.name == "nt":
296+
programdata = os.environ.get("PROGRAMDATA", None)
297+
if programdata:
298+
SYSTEM_CONFIG_PATH = [str(Path(programdata, "jupyter"))]
299+
else: # PROGRAMDATA is not defined by default on XP.
300+
SYSTEM_CONFIG_PATH = []
295301
else:
296-
if os.name == "nt":
297-
programdata = os.environ.get("PROGRAMDATA", None)
298-
if programdata: # noqa: SIM108
299-
SYSTEM_CONFIG_PATH = [str(Path(programdata, "jupyter"))]
300-
else: # PROGRAMDATA is not defined by default on XP.
301-
SYSTEM_CONFIG_PATH = []
302-
else:
303-
SYSTEM_CONFIG_PATH = [
304-
"/usr/local/etc/jupyter",
305-
"/etc/jupyter",
306-
]
302+
SYSTEM_CONFIG_PATH = [
303+
"/usr/local/etc/jupyter",
304+
"/etc/jupyter",
305+
]
307306
ENV_CONFIG_PATH: list[str] = [str(Path(sys.prefix, "etc", "jupyter"))]
308307

309308

@@ -986,7 +985,7 @@ def secure_write(fname: str, binary: bool = False) -> Iterator[Any]:
986985
else:
987986
# Python on windows does not respect the group and public bits for chmod, so we need
988987
# to take additional steps to secure the contents.
989-
# Touch file pre-emptively to avoid editing permissions in open files in Windows
988+
# Touch file preemptively to avoid editing permissions in open files in Windows
990989
fd = os.open(fname, open_flag, 0o0600)
991990
os.close(fd)
992991
open_flag = os.O_WRONLY | os.O_TRUNC

jupyter_core/troubleshoot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
display environment information that is frequently
44
used to troubleshoot installations of Jupyter or IPython
55
"""
6+
67
from __future__ import annotations
78

89
import os
@@ -68,17 +69,17 @@ def main() -> None:
6869
print(f"\t{directory}")
6970

7071
print("\nsys.executable:")
71-
print(f'\t{environment_data["sys_exe"]}')
72+
print(f"\t{environment_data['sys_exe']}")
7273

7374
print("\nsys.version:")
7475
if "\n" in environment_data["sys_version"]:
7576
for data in environment_data["sys_version"].split("\n"):
7677
print(f"\t{data}")
7778
else:
78-
print(f'\t{environment_data["sys_version"]}')
79+
print(f"\t{environment_data['sys_version']}")
7980

8081
print("\nplatform.platform():")
81-
print(f'\t{environment_data["platform"]}')
82+
print(f"\t{environment_data['platform']}")
8283

8384
if environment_data["which"]:
8485
print("\nwhich -a jupyter:")

0 commit comments

Comments
 (0)