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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
- name: Deploy to GitHub Pages
run: |
git fetch origin gh-pages --depth=1
mike deploy --push --update-aliases ${{ env.VERSION }} latest
invoke mike-deploy --version ${{ env.VERSION }} --push-to-origin true

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The workflow passes --push-to-origin true as a string, but the mike_deploy function expects push_to_origin to be a bool. Invoke will interpret the string "true" as a truthy value and convert it to boolean True, so this should work. However, for clarity and explicitness, consider passing it without the value (as a flag) like --push-to-origin since the parameter defaults to False. Alternatively, if you want to be explicit, the current approach works but relies on invoke's automatic type conversion.

Suggested change
invoke mike-deploy --version ${{ env.VERSION }} --push-to-origin true
invoke mike-deploy --version ${{ env.VERSION }} --push-to-origin

Copilot uses AI. Check for mistakes.
65 changes: 64 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from invoke.collection import Collection

from invoke.tasks import task
from compas_invocations2 import build
from compas_invocations2 import style
from compas_invocations2 import tests
Expand All @@ -10,6 +10,68 @@
from compas_pb.invocations import proto_docs


def _patch_versions_info():

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The _patch_versions_info function lacks a docstring explaining what it does, why it's needed, and the side effects of monkey-patching. This is particularly important for a function that modifies third-party library behavior at runtime. A docstring would help future maintainers understand the purpose and implications of this patch.

Suggested change
def _patch_versions_info():
def _patch_versions_info():
"""Monkey-patch ``mike.versions.VersionInfo`` to preserve unknown JSON fields.
This project stores additional metadata in ``versions.json`` which is not
supported by mike's built-in :class:`~mike.versions.VersionInfo` model.
By default, mike discards unknown fields on load and rewrites the file
on dump, which would remove this extra metadata and break the version
selector of existing Sphinx sites that rely on it.
This helper replaces :meth:`VersionInfo.from_json` and
:meth:`VersionInfo.to_json` at runtime so that:
* unknown keys encountered during ``from_json`` are stored on the instance
(via ``external_attrs``), and
* those keys are merged back into the output of ``to_json``.
Notes
-----
This is a process-wide monkey-patch: once applied, all subsequent uses of
:class:`mike.versions.VersionInfo` in the current process will use the
patched serialization methods. Call this function before invoking any
mike commands that load or write ``versions.json`` (for example,
inside the ``mike_deploy`` task).
"""

Copilot uses AI. Check for mistakes.
# our `versions.json` contains some fields which aren't supported by mike's
# VersionInfo class. Unfortunately mike overwrites the entire content everytime which breaks the version selector of the old Sphinx sites.

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

Typo in comment: "everytime" should be "every time" (two words).

Suggested change
# VersionInfo class. Unfortunately mike overwrites the entire content everytime which breaks the version selector of the old Sphinx sites.
# VersionInfo class. Unfortunately mike overwrites the entire content every time which breaks the version selector of the old Sphinx sites.

Copilot uses AI. Check for mistakes.
# Here we monkey-patch the class to preserve unknown fields during load/dump.
from mike.versions import VersionInfo

@classmethod
def patched_from_json(cls, data: dict):
instance = cls(
data.pop("version"),
data.pop("title"),
data.pop("aliases"),
data.pop("properties", None),
)
instance.external_attrs = data
return instance

def patched_to_json(self):
data = {
"version": str(self.version),
"title": self.title,
"aliases": list(self.aliases),
}
if self.properties:
data["properties"] = self.properties
if getattr(self, "external_attrs", None):
data.update(self.external_attrs)
return data

VersionInfo.from_json = patched_from_json
VersionInfo.to_json = patched_to_json
Comment on lines +42 to +43

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The monkey-patch modifies the VersionInfo class globally for the entire process. If this function is called multiple times, the patching will occur multiple times, which is redundant but should not cause issues. However, consider adding a guard to prevent redundant patching, or document that this is intentional behavior. This would make the code more defensive and clearer about its intent.

Copilot uses AI. Check for mistakes.


@task(help={"version": "The library version for which the documentation is to be deployed (e.g., '1.0.0')", "push_to_origin": "Whether to push the changes to the origin remote"})
def mike_deploy(ctx, version: str, push_to_origin: bool = False):

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The mike_deploy task lacks a docstring describing its purpose, parameters, and usage. According to the coding guidelines, public API functions and classes should have numpy style docstrings. While this is an invoke task and not strictly a public API function, it's part of the public interface exposed to developers. Adding a docstring would improve usability, especially since this task performs a non-trivial operation (monkey-patching).

Copilot generated this review using guidance from repository custom instructions.
from mike import driver
from argparse import Namespace

_patch_versions_info()

args = Namespace(
version=version,
title=version,
aliases=["latest"],
update_aliases=True,
push=push_to_origin,
branch="gh-pages",
remote="origin",
message=None,
config_file=None,
allow_empty=False,
deploy_prefix=None,
ignore_remote_status=False,
alias_type="symlink",
template=None,
set_props=None,
quiet=False,
)

driver.deploy(None, args)

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The driver.deploy(None, args) call passes None as the first argument. This should be verified to ensure it's the correct usage of the mike driver API. If None represents a missing configuration or context, it might be worth adding a comment explaining why this is acceptable or if there's a better value to pass.

Copilot uses AI. Check for mistakes.


ns = Collection(
style.check,
style.lint,
Expand All @@ -23,6 +85,7 @@
generate_proto_classes,
create_class_assets,
proto_docs,
mike_deploy,
)

ns.configure(
Expand Down
Loading