Skip to content

Add docstrings step to calkit-run workflow; run Python scripts via uv#185

Open
Copilot wants to merge 15 commits into
mainfrom
copilot/add-docstrings-step-to-calkit-run
Open

Add docstrings step to calkit-run workflow; run Python scripts via uv#185
Copilot wants to merge 15 commits into
mainfrom
copilot/add-docstrings-step-to-calkit-run

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

dev/docs/add_docstrings.py existed to stamp Sphinx-compatible docstrings onto .m files but was never wired into CI. Additionally, the workflow used actions/setup-python + pip install for two lightweight Python scripts that uv can handle directly.

Changes

  • New step: Run dev/docs/add_docstrings.py after checkout; any modified .m files are saved alongside pipeline outputs in the calkit save step
  • Removed actions/setup-python and pip install ruamel.yaml steps — both scripts now run via uv run with Python 3.12 pinned via astral-sh/setup-uv:
    • uv run python dev/docs/add_docstrings.py (stdlib-only)
    • uv run --with ruamel.yaml python mdocean/analysis/update_calkit.py (ruamel.yaml resolved on-the-fly)
  • calkit save extended to include *.m files and a fork PR guard (skips save/push for fork PRs)
  • Fixed incorrect parameter and return names in autogenerated docstring for contourx.m (XX_data, YY_data, ZZ_data, water depth (m)h_fig)
  • Bumped version to v1.1.21 and added changelog entry

Copilot AI and others added 2 commits April 6, 2026 07:26
Agent-Logs-Url: https://github.com/symbiotic-engineering/MDOcean/sessions/08b57ff7-b66b-4abc-abac-89ada4866851

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>
@rebeccamccabe rebeccamccabe marked this pull request as ready for review April 10, 2026 05:31
Copilot AI review requested due to automatic review settings April 10, 2026 05:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the Calkit CI workflow to automatically apply MATLAB Sphinx docstring stamping and to run lightweight Python utilities via uv instead of a pre-installed Python + pip setup.

Changes:

  • Adds a workflow step to run dev/docs/add_docstrings.py and auto-commit/push resulting .m docstring updates.
  • Replaces direct python execution with uv run (including on-the-fly install of ruamel.yaml) for mdocean/analysis/update_calkit.py.
  • Removes actions/setup-python and pip install ruamel.yaml steps from the workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/calkit-run.yml Outdated
Comment on lines +57 to +60
- name: Add docstrings to .m files
run: |
uv run python dev/docs/add_docstrings.py
if git diff --quiet; then

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

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

uv run python ... relies on a python executable being available on the self-hosted runner, but this workflow no longer installs/chooses a Python version (it removed actions/setup-python). If the runner image changes or lacks Python, this step will fail and the workflow becomes non-reproducible across runners. Consider explicitly selecting/installing a Python version (e.g., via uv's Python management or re-adding setup-python) so uv run has a guaranteed interpreter.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback use uv python mgmt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in commit 97d09d6. Added python-version: "3.12" to the astral-sh/setup-uv@v7 step — uv will install and pin Python 3.12 on the runner, guaranteeing a consistent interpreter for both uv run invocations (the docstrings step and update_calkit.py).

Comment thread .github/workflows/calkit-run.yml Outdated
Comment on lines +62 to +64
else
git add mdocean/
git commit -m "Add autogenerated docstrings to .m files [skip ci]"

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

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

git add mdocean/ stages the entire directory, which can accidentally include unrelated modifications (e.g., file permission/line-ending churn on self-hosted runners or other generated artifacts if anything else touched mdocean/). To reduce the risk of committing unintended changes, stage only the expected .m docstring updates (or only tracked changes) rather than the whole tree.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Already addressed in commit 5c10afe. git add mdocean/ was replaced with git add -u -- '*.m', which stages only tracked .m file modifications and ignores any other changes in the directory.

Comment thread .github/workflows/calkit-run.yml Outdated
Comment on lines +64 to +66
git commit -m "Add autogenerated docstrings to .m files [skip ci]"
git push
fi

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

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

This step unconditionally git pushes during a pull_request workflow run. That can fail (and fail the whole job) on non-fast-forward updates if the branch moves while the job is running, and it will not work for fork PRs (no permission / branch not in the base repo). Consider guarding the commit/push so it only runs for same-repo PRs, and add push error handling (e.g., pull/rebase + retry, or fall back to creating a new branch as done later in the workflow).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in commit 5c10afe:

  • Staging narrowed: changed git add mdocean/git add -u -- '*.m' so only tracked .m file changes are staged (not the whole directory tree).
  • Fork PR guard: the commit/push block now checks github.event.pull_request.head.repo.full_name != github.repository and skips the push for fork PRs.
  • Push error handling: added git pull --rebase before pushing; if the rebase fails, falls back to creating a new branch (docstrings-<run_number>-<run_id>) and pushing there — mirroring the pattern already used in the calkit save step.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't duplicate this branching logic, just remove the add/commit/push from this step entirely and add *.m as an input to the calkit save below, and put the if not fork logic in that step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in commit a0e58dc:

  • "Add docstrings to .m files" step now just runs uv run python dev/docs/add_docstrings.py — all commit/push logic removed.
  • '*.m' added to the calkit save file list so docstring changes are committed with the pipeline outputs.
  • Fork PR guard added at the top of calkit save (skips save/push for fork PRs).

Comment thread .github/workflows/calkit-run.yml
…ull --rebase retry

Agent-Logs-Url: https://github.com/symbiotic-engineering/MDOcean/sessions/3dd0a364-c68b-4765-9248-f7827c479e19

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>
…for uv run steps

Agent-Logs-Url: https://github.com/symbiotic-engineering/MDOcean/sessions/6d07ea9c-f939-4dc2-bdeb-15e7d5a15c29

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>
Comment thread .github/workflows/calkit-run.yml Outdated
Comment on lines +64 to +66
git commit -m "Add autogenerated docstrings to .m files [skip ci]"
git push
fi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't duplicate this branching logic, just remove the add/commit/push from this step entirely and add *.m as an input to the calkit save below, and put the if not fork logic in that step.

…n calkit save

Agent-Logs-Url: https://github.com/symbiotic-engineering/MDOcean/sessions/040712ef-0a07-426a-bf74-541b9c73bbb8

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>
Comment thread mdocean/plots/util/contourx.m Outdated
function [C,h] = contourx(X,Y,Z,varargin)
% Function contourx
%
% :param X: Design variable vector

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

incorrect X and h

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit d80c641 — updated :param X::param X_data:, :param Y::param Y_data:, :param Z::param Z_data:, and :returns: water depth (m):returns: h_fig.

Comment thread results/Wecsim/end.json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

wecsim errors changing is not expected just due to docstring additions, it must indicate that the wecsim stage on main was stale? maybe if the last-merged PR had a conflict so pushed to a different branch?

@rebeccamccabe

Copy link
Copy Markdown
Collaborator

@copilot merge main into this branch and resolve merge conflicts by checking out theirs for all conflicted files. You may have to pull/fetch main first to ensure it is the most updated version. Ensure it is a proper merge commit with two parents, not a regular commit. Then, bump mdocean/version.py and add an entry to the changelog summarizing this PR.

Copilot AI and others added 2 commits April 15, 2026 01:11
Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>
….1.21

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>

Copilot AI commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot merge main into this branch and resolve merge conflicts by checking out theirs for all conflicted files. You may have to pull/fetch main first to ensure it is the most updated version. Ensure...

Done in commit 960bdd7:

  • Merged main (v1.1.20) into this branch as a proper two-parent merge commit; conflicts in data/result files resolved by checking out theirs.
  • Bumped mdocean/__version__.py to 1.1.21.
  • Added v1.1.21 entry to CHANGELOG.md summarizing the CI changes in this PR.

@rebeccamccabe

Copy link
Copy Markdown
Collaborator

Pipeline completed successfully. Need to resolve merge conflicts using theirs and do a manual dvc commit to enforce that the stages don’t get unnecessarily rerun.

@rebeccamccabe

Copy link
Copy Markdown
Collaborator

@copilot add a feature to the Calkit run.yaml github actions workflow where ‘calkit dvc commit stagenames’ followed by “git add dvc.lock *.m” and “git commit-m “Update docstrings and force-commit dvc stages” is run for stage names where they were clean (‘Calkit status stagename’ was not stale) before running the docstring generation, but they are dirty (Calkit status showing as stale) after adding the doc strings. If a given stage was dirty before adding doc strings then it should not be dvc committed.

… newly stale stages

Agent-Logs-Url: https://github.com/symbiotic-engineering/MDOcean/sessions/2b5f2492-8c47-49ee-9c56-d1c7fd1d6dbf

Co-authored-by: rebeccamccabe <32020426+rebeccamccabe@users.noreply.github.com>

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a feature to the Calkit run.yaml github actions workflow where ‘calkit dvc commit stagenames’ followed by “git add dvc.lock *.m” and “git commit-m “Update docstrings and force...

Applied in commit 4cca5c6. The "Add docstrings to .m files" step now:

  1. Captures which stages are already stale (dvc status --json | jq -r 'keys[]') before running add_docstrings.py
  2. Runs uv run python dev/docs/add_docstrings.py
  3. Captures stale stages after
  4. Computes the set difference — stages that were clean before but stale after (i.e., newly dirtied only by docstrings)
  5. For that set: runs calkit dvc commit <stages>, then git add dvc.lock '*.m' and git commit -m "Update docstrings and force-commit dvc stages" (skipped if the staged diff is empty)

Stages that were already dirty before docstring generation are excluded from the force-commit.

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.

3 participants