Skip to content
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
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ repos:
- id: actionlint
# Disable because of false-positive SC2046
args: ["-shellcheck="]
- repo: local
hooks:
- id: sync-python-version
name: sync python version with pixi.toml
entry: python tools/sync-python-version.py
language: python
files: '(pixi\.toml|pyproject\.toml)$'
pass_filenames: false
1 change: 0 additions & 1 deletion packages/essimaging/.python-version

This file was deleted.

2 changes: 2 additions & 0 deletions packages/essimaging/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
# The min python version should be updated in the root pixi.toml file
# pre-commit will automatically update the following pin
requires-python = ">=3.11"

dynamic = ["version"]
Expand Down
1 change: 0 additions & 1 deletion packages/essreduce/.python-version

This file was deleted.

2 changes: 2 additions & 0 deletions packages/essreduce/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
# The min python version should be updated in the root pixi.toml file
# pre-commit will automatically update the following pin
requires-python = ">=3.11"

dynamic = ["version"]
Expand Down
406 changes: 214 additions & 192 deletions pixi.lock

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions tools/sync-python-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Scipp contributors (https://github.com/scipp)
"""Sync requires-python with pixi.toml.
The Python minor version pinned in pixi.toml (e.g. ``python = "3.12.*"``)
is the single source of truth. This script updates:
* ``requires-python`` in ``packages/*/pyproject.toml``
"""

import re
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
PIXI_TOML = ROOT / "pixi.toml"
PACKAGES = ROOT / "packages"


def python_minor_version_from_pixi() -> str:
text = PIXI_TOML.read_text()
m = re.search(r'^python\s*=\s*"(\d+\.\d+)\.\*"', text, re.MULTILINE)
if not m:
print(f'ERROR: Could not find python = "X.Y.*" in {PIXI_TOML}')
sys.exit(1)
return m.group(1)


def sync_requires_python(version: str) -> bool:
changed = False
expected = f'requires-python = ">={version}"'
pattern = re.compile(r'^requires-python\s*=\s*"[^"]*"', re.MULTILINE)
for pyproject in sorted(PACKAGES.glob("*/pyproject.toml")):
text = pyproject.read_text()
m = pattern.search(text)
if m is None:
continue
if m.group(0) != expected:
new_text = text[: m.start()] + expected + text[m.end() :]
pyproject.write_text(new_text)
print(f"Updated {pyproject.relative_to(ROOT)}")
changed = True
return changed


def main() -> int:
version = python_minor_version_from_pixi()
changed = sync_requires_python(version)
if changed:
print(
f'Files updated to match python = "{version}.*" from pixi.toml. '
"Please stage the changes."
)
return 1
return 0


if __name__ == "__main__":
sys.exit(main())