Skip to content

Commit 23150c0

Browse files
chore: update pre-commit hooks (#421)
With extra updates to address linter changes, keep supporting Python 3.8 on CI
1 parent cb20468 commit 23150c0

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ jobs:
4040
python-version: "3.10"
4141
steps:
4242
- uses: actions/checkout@v4
43-
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
43+
- uses: actions/setup-python@v5
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
cache: pip
47+
48+
- name: install hatch
49+
run: |
50+
pip install --upgrade pip pipx
51+
if [[ "${{ matrix.python-version }}" == "3.8" ]]; then
52+
PIPX_HOME=$HOME/.pipx_home
53+
mkdir $PIPX_HOME
54+
fi
55+
pipx install hatch
56+
4457
- name: Test
4558
run: |
4659
hatch run cov:test

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: trailing-whitespace
2222

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

@@ -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.9.10
70+
rev: v0.11.11
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: "2025.01.22"
79+
rev: "2025.05.02"
8080
hooks:
8181
- id: sp-repo-review
8282
additional_dependencies: ["repo-review[cli]"]

.readthedocs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ build:
1010
os: ubuntu-22.04
1111
tools:
1212
python: "3.12"
13+
sphinx:
14+
configuration: docs/conf.py

jupyter_core/command.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ def list_subcommands() -> list[str]:
9292
# construct a set of `('foo', 'bar') from `jupyter-foo-bar`
9393
for d in _path_with_self():
9494
try:
95-
names = os.listdir(d)
95+
bin_paths = list(Path(d).iterdir())
9696
except OSError:
9797
continue
98-
for name in names:
98+
for path in bin_paths:
99+
name = path.name
99100
if name.startswith("jupyter-"):
100101
if sys.platform.startswith("win"):
101102
# remove file-extension on Windows
102-
name = os.path.splitext(name)[0] # noqa: PTH122, PLW2901
103+
name = path.stem
103104
subcommand_tuples.add(tuple(name.split("-")[1:]))
104105
# build a set of subcommand strings, excluding subcommands whose parents are defined
105106
subcommands = set()

jupyter_core/migrate.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,19 @@ def get_ipython_dir() -> str:
8686
def migrate_dir(src: str, dst: str) -> bool:
8787
"""Migrate a directory from src to dst"""
8888
log = get_logger()
89-
if not os.listdir(src):
89+
src_path = Path(src)
90+
dst_path = Path(dst)
91+
if not any(src_path.iterdir()):
9092
log.debug("No files in %s", src)
9193
return False
92-
if Path(dst).exists():
93-
if os.listdir(dst):
94+
if dst_path.exists():
95+
if any(dst_path.iterdir()):
9496
# already exists, non-empty
9597
log.debug("%s already exists", dst)
9698
return False
97-
Path(dst).rmdir()
99+
dst_path.rmdir()
98100
log.info("Copying %s -> %s", src, dst)
99-
ensure_dir_exists(Path(dst).parent)
101+
ensure_dir_exists(dst_path.parent)
100102
shutil.copytree(src, dst, symlinks=True)
101103
return True
102104

@@ -107,19 +109,20 @@ def migrate_file(src: str | Path, dst: str | Path, substitutions: Any = None) ->
107109
substitutions is an optional dict of {regex: replacement} for performing replacements on the file.
108110
"""
109111
log = get_logger()
110-
if Path(dst).exists():
112+
dst_path = Path(dst)
113+
if dst_path.exists():
111114
# already exists
112115
log.debug("%s already exists", dst)
113116
return False
114117
log.info("Copying %s -> %s", src, dst)
115-
ensure_dir_exists(Path(dst).parent)
118+
ensure_dir_exists(dst_path.parent)
116119
shutil.copy(src, dst)
117120
if substitutions:
118-
with Path.open(Path(dst), encoding="utf-8") as f:
121+
with dst_path.open() as f:
119122
text = f.read()
120123
for pat, replacement in substitutions.items():
121124
text = pat.sub(replacement, text)
122-
with Path.open(Path(dst), "w", encoding="utf-8") as f:
125+
with dst_path.open("w") as f:
123126
f.write(text)
124127
return True
125128

0 commit comments

Comments
 (0)