Skip to content

Conversation

tsbinns
Copy link
Contributor

@tsbinns tsbinns commented Oct 17, 2025

Reference issue (if any)

Fixes #13449

What does this implement/fix?

Adds a script that updates version specifiers for selected dependencies according to SPEC0 compliance.

Also adds a workflow that runs this script on PRs and just pushes the changes. End goal would be for the workflow to run on schedule and create a PR with any changes.

Additional information

Right now is only handling dependencies, not Python versions.

Am using tomlkit rather than the built-in tomllib due to requiring writing capabilities.

The specifier parsing using the packaging tools works really nicely, but unfortunately spaces are not preserved, e.g., numpy >= 1.26 becomes numpy>=1.26. For consistency, the script is applying this formatting to all pinned dependencies, even if they are not being changed. I'm open to changing/refining this.

Had to do some roundabout way to find the target branch to push to, as the zizmor pre-commit check was warning of code injection via template expansion with TARGET_BRANCH="${{ github.head_ref }}".

Also had to update the yamllint rules for the pre-commit check to pass on my Windows machine (had the same issue in MNE-Connectivity before: mne-tools/mne-connectivity#198).

import warnings
from datetime import timedelta

import pandas as pd
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pandas is a bit overkill, I just carried it over from the SPEC0 example scripts. I can refine this once everything's working.

@tsbinns
Copy link
Contributor Author

tsbinns commented Oct 17, 2025

Workflow is failing because the permissions aren't right to push the changes to this PR. I've been reading up on this, but can't seem to figure a solution out without adding a new PAT secret to the repo.

@drammock
Copy link
Member

xref to a couple things that (1) this might break (?) and (2) might have some code you could steal:

pre-commit hooks that parse pyproject.toml (and copy some things from it into other places)

# dependencies
- repo: local
hooks:
- id: update-env-file
name: Copy dependency changes from pyproject.toml to environment.yml
language: python
entry: ./tools/hooks/update_environment_file.py
files: '^(pyproject.toml|tools/hooks/update_environment_file.py)$'
- repo: local
hooks:
- id: dependency-sync
name: Copy core dependencies from pyproject.toml to README.rst
language: python
entry: ./tools/hooks/sync_dependencies.py
files: '^(pyproject.toml|tools/hooks/sync_dependencies.py)$'
additional_dependencies: ["mne==1.10.0"]

In particular, for our README we re-write the pins to look pretty, this could be adapted maybe:

def _prettify_pin(pin):
if pin is None:
return ""
pins = pin.split(",")
replacements = {
"<=": " ≤ ",
">=": " ≥ ",
"<": " < ",
">": " > ",
}
for old, new in replacements.items():
pins = [p.replace(old, new) for p in pins]
pins = reversed(pins)
return ",".join(pins)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automate SPEC0 adherence for dependency version management

2 participants