-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[MAINT] Automatic SPEC0 dependency version management #13451
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
Conversation
|
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. |
|
xref to a couple things that (1) this might break (?) and (2) might have some code you could steal: pre-commit hooks that parse
|
| # 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:
mne-python/tools/hooks/sync_dependencies.py
Lines 36 to 49 in 3cfac64
| 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) |
|
@drammock Have pushed some changes to have the formatting better reflect what there is currently. For this messing with the pre-commit hooks and making changes after they have been run, is there a way that this action changing pyproject.toml could re-trigger those hooks? |
You can always Or really you can let the action push to a branch and make a PR, and as soon as that happens |
drammock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few things I noticed when skimming the script
Co-authored-by: Daniel McCloy <[email protected]>
|
@larsoner Have pushed changes to run on One last thing on my mind: should release date comments like this be removed now that we're automating? Lines 26 to 27 in d008a47
There are also comments for packages we're not automating (e.g., for |
Either way is fine by me. I actually think it would be cool to add comments like this on lines that your action updates. It should be easy enough with your code, right?
I think we should add |
|
... I looked at also you can push with |
Co-authored-by: Eric Larson <[email protected]>
Yeah, I can work on this. Not to make things too complex, but would a drop date also be worthwhile?
Sorry I was mistaken, |
So like something like this to indicate the next point and its release date? That seems informative, yeah 👍 |
|
@tsbinns just let me know when you push the above change and the changelog entry. I'll test running the script locally, merge, and then Sound good? |
|
@larsoner Sounds good! Have pushed a changelog now. Will ping you once the auto comment is working and once I've changed the schedule. |
|
It's a good job I went back to update the comments, because I realised the logic for finding minimum versions was flawed. I was taking the earliest minor version within those 2 years, not the latest version at 2 years prior. That is now fixed. The only thing that changed was where before I also made it so the comments are automatically updated. They look like this: and in cases with no new version available: Now in cases where the unpatched version was yanked (e.g., |
| dependencies._value[idx] = _add_date_comment( | ||
| dependencies._value[idx], min_ver_release, next_ver, next_ver_release | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not ideal that I have to manipulate private attrs of the toml data to add the comments, but there doesn't seem to be a way to do so otherwise. Even with tomlkit-extras this isn't supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tomlkit docs seem to suggest that this should work
| dependencies._value[idx] = _add_date_comment( | |
| dependencies._value[idx], min_ver_release, next_ver, next_ver_release | |
| ) | |
| dependencies.value[idx].comment(code_to_generate_comment_string_here) |
did you try that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so dependencies.value[idx].comment("some comment") updates the comment properties of the item in that index, but this doesn't propagate to dependencies._value, which is what is used to write back to the file. Could be a bug? Skimming the issues/PRs for tomlkit I haven't seen this raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems buggish, yeah, but I'd have to dig into their code/API to be sure. I guess leave it for now, unless you find it deeply unsatisfying and can't sleep without knowing the answer 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really a bug. xref: python-poetry/tomlkit#340 (comment)
TL;DR: private methods are the way to go, I can find any substantive improvement over what you've already got here.
|
@larsoner I think this is ready now! |
| dependencies._value[idx] = _add_date_comment( | ||
| dependencies._value[idx], min_ver_release, next_ver, next_ver_release | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tomlkit docs seem to suggest that this should work
| dependencies._value[idx] = _add_date_comment( | |
| dependencies._value[idx], min_ver_release, next_ver, next_ver_release | |
| ) | |
| dependencies.value[idx].comment(code_to_generate_comment_string_here) |
did you try that?
|
Okay let's try it! 🤞 |
* upstream/main: ENH: Add encoding parameter to Nihon Kohden reader (mne-tools#13458) [MAINT] Automatic SPEC0 dependency version management (mne-tools#13451)
* upstream/main: (23 commits) ENH: Add on_missing for combine_channels (mne-tools#13463) Bump the actions group with 2 updates (mne-tools#13464) Move development dependencies into a dependency group (no more extra) (mne-tools#13452) ENH: add on_missing for rename_channels (mne-tools#13456) add advisory board to website (mne-tools#13462) ENH: Support Nihon Kohden EEG-1200A V01.00 (mne-tools#13448) MAINT: Update dependency specifiers (mne-tools#13459) ENH: Add encoding parameter to Nihon Kohden reader (mne-tools#13458) [MAINT] Automatic SPEC0 dependency version management (mne-tools#13451) FIX: Read Nihon Kohden annotation file accurately (mne-tools#13251) MAINT: Restore edfio git install (mne-tools#13421) Support preload=False for the new EEGLAB single .set format (mne-tools#13096) [pre-commit.ci] pre-commit autoupdate (mne-tools#13453) MAINT: Restore PySide6 6.10.0 testing (mne-tools#13446) MAINT: Auth [skip azp] [skip actions] MAINT: Deploy [circle deploy] [skip azp] [skip actions] Bump github/codeql-action from 3 to 4 in the actions group (mne-tools#13442) ENH: Dont constrain fiducial clicks to mesh vertices (mne-tools#13445) Use timezone-aware ISO 8601 for website timestamp (mne-tools#13347) [pre-commit.ci] pre-commit autoupdate (mne-tools#13443) ...
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
tomlkitrather than the built-intomllibdue to requiring writing capabilities.The specifier parsing using the
packagingtools works really nicely, but unfortunately spaces are not preserved, e.g.,numpy >= 1.26becomesnumpy>=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).