Skip to content

chore: update pre-commit hooks #421

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

Merged
merged 8 commits into from
May 26, 2025
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
15 changes: 14 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ jobs:
python-version: "3.10"
steps:
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: install hatch
run: |
pip install --upgrade pip pipx
if [[ "${{ matrix.python-version }}" == "3.8" ]]; then
PIPX_HOME=$HOME/.pipx_home
mkdir $PIPX_HOME
fi
pipx install hatch

- name: Test
run: |
hatch run cov:test
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.31.3
rev: 0.33.0
hooks:
- id: check-github-workflows

Expand Down Expand Up @@ -67,7 +67,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
rev: v0.11.11
hooks:
- id: ruff
types_or: [python, jupyter]
Expand All @@ -76,7 +76,7 @@ repos:
types_or: [python, jupyter]

- repo: https://github.com/scientific-python/cookie
rev: "2025.01.22"
rev: "2025.05.02"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 2 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ build:
os: ubuntu-22.04
tools:
python: "3.12"
sphinx:
configuration: docs/conf.py
7 changes: 4 additions & 3 deletions jupyter_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ def list_subcommands() -> list[str]:
# construct a set of `('foo', 'bar') from `jupyter-foo-bar`
for d in _path_with_self():
try:
names = os.listdir(d)
bin_paths = list(Path(d).iterdir())
except OSError:
continue
for name in names:
for path in bin_paths:
name = path.name
if name.startswith("jupyter-"):
if sys.platform.startswith("win"):
# remove file-extension on Windows
name = os.path.splitext(name)[0] # noqa: PTH122, PLW2901
name = path.stem
subcommand_tuples.add(tuple(name.split("-")[1:]))
# build a set of subcommand strings, excluding subcommands whose parents are defined
subcommands = set()
Expand Down
21 changes: 12 additions & 9 deletions jupyter_core/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ def get_ipython_dir() -> str:
def migrate_dir(src: str, dst: str) -> bool:
"""Migrate a directory from src to dst"""
log = get_logger()
if not os.listdir(src):
src_path = Path(src)
dst_path = Path(dst)
if not any(src_path.iterdir()):
log.debug("No files in %s", src)
return False
if Path(dst).exists():
if os.listdir(dst):
if dst_path.exists():
if any(dst_path.iterdir()):
# already exists, non-empty
log.debug("%s already exists", dst)
return False
Path(dst).rmdir()
dst_path.rmdir()
log.info("Copying %s -> %s", src, dst)
ensure_dir_exists(Path(dst).parent)
ensure_dir_exists(dst_path.parent)
shutil.copytree(src, dst, symlinks=True)
return True

Expand All @@ -107,19 +109,20 @@ def migrate_file(src: str | Path, dst: str | Path, substitutions: Any = None) ->
substitutions is an optional dict of {regex: replacement} for performing replacements on the file.
"""
log = get_logger()
if Path(dst).exists():
dst_path = Path(dst)
if dst_path.exists():
# already exists
log.debug("%s already exists", dst)
return False
log.info("Copying %s -> %s", src, dst)
ensure_dir_exists(Path(dst).parent)
ensure_dir_exists(dst_path.parent)
shutil.copy(src, dst)
if substitutions:
with Path.open(Path(dst), encoding="utf-8") as f:
with dst_path.open() as f:
text = f.read()
for pat, replacement in substitutions.items():
text = pat.sub(replacement, text)
with Path.open(Path(dst), "w", encoding="utf-8") as f:
with dst_path.open("w") as f:
f.write(text)
return True

Expand Down
Loading