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
5 changes: 5 additions & 0 deletions .github/workflows/release_constructor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ jobs:
"check_placeholders.py" \
.tools/python/check_placeholders.py \
python .tools/python/check_placeholders.py
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"merge_requirements.py --check" \
.tools/python/merge_requirements.py \
python .tools/python/merge_requirements.py --source-dir notebooks --output requirements.txt --check


- name: Commit updated versioned files
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/update_on_notebook_change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'notebooks/**/*.ipynb'
- 'notebooks/notebook_latest_versions.yaml'
- 'notebooks/**/requirements.yaml'
- 'requirements_overrides.yaml'
workflow_dispatch:

# One run of this workflow at a time per branch. The src workflow has its own group: the two can run at the same time,
Expand Down Expand Up @@ -45,6 +46,7 @@ jobs:
notebooks/**/*.ipynb
notebooks/notebook_latest_versions.yaml
notebooks/**/requirements.yaml
requirements_overrides.yaml

- name: Syncronize notebook versions
if: contains(steps.changed-files.outputs.all_changed_files, '.ipynb') || contains(steps.changed-files.outputs.all_changed_files, 'notebook_latest_versions.yaml')
Expand Down Expand Up @@ -92,7 +94,7 @@ jobs:
python .tools/python/bump_notebook_README.py

- name: Run merge script
if: github.event_name == 'workflow_dispatch' || contains(steps.changed-files.outputs.all_changed_files, 'requirements.yaml')
if: github.event_name == 'workflow_dispatch' || contains(steps.changed-files.outputs.all_changed_files, 'requirements.yaml') || contains(steps.changed-files.outputs.all_changed_files, 'requirements_overrides.yaml')
run: |
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
Expand Down
20 changes: 19 additions & 1 deletion .template_sync/manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
template_version: 0.1.26
template_version: 0.1.32
migrations:
- from: 0.0.0
to: 0.0.1
Expand Down Expand Up @@ -84,3 +84,21 @@ migrations:
- from: 0.1.25
to: 0.1.26
script: migrations/v0_1_25_to_v0_1_26.py
- from: 0.1.26
to: 0.1.27
script: migrations/v0_1_26_to_v0_1_27.py
- from: 0.1.27
to: 0.1.28
script: migrations/v0_1_27_to_v0_1_28.py
- from: 0.1.28
to: 0.1.29
script: migrations/v0_1_28_to_v0_1_29.py
- from: 0.1.29
to: 0.1.30
script: migrations/v0_1_29_to_v0_1_30.py
- from: 0.1.30
to: 0.1.31
script: migrations/v0_1_30_to_v0_1_31.py
- from: 0.1.31
to: 0.1.32
script: migrations/v0_1_31_to_v0_1_32.py
99 changes: 99 additions & 0 deletions .template_sync/migrations/v0_1_26_to_v0_1_27.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""Template 0.1.26 -> 0.1.27: an app can say which napari, Fiji or QuPath plugin version its tools need (host_requirements).

Design note: https://github.com/CellMigrationLab/LabConstrictor/blob/main/.tools/docs/migration_0_1_27.md
Proposal: https://github.com/CellMigrationLab/LabConstrictor-Tools/issues/155

The App Centre schema gained an optional field, host_requirements. The template's copy of the schema rejects fields it does not
know, so without this migration an app that adds the field fails its "Check App Centre manifest" workflow. What this changes in an
app repository (each step is independent, idempotent and never deletes anything):

1. .tools/schema/labconstrictor-app.schema.json: replaced by the template's copy (the template owns it; it must equal the App Centre's
schema). A missing schema is not created: the app has no manifest check to update.
2. .tools/docs/app_manifest.md: the section "Plugin versions your tools need (optional)" goes before "## The automatic check". A page
that already has the section is unchanged; a page without that heading gets it before its Previous / Home / Next links, or at
its end. Line endings are kept.

labconstrictor-app.yaml belongs to the app and is never created or changed.
"""
from __future__ import annotations

import re
from pathlib import Path
from typing import Any


DOCS_URL = "https://github.com/CellMigrationLab/LabConstrictor/blob/main/.tools/docs/migration_0_1_27.md"
TAG = "[migration 0.1.27]"
RESOURCE_ROOT = Path(__file__).resolve().parents[1] / "resources" / "v0_1_26_to_v0_1_27"

SCHEMA = Path(".tools/schema/labconstrictor-app.schema.json")
MANIFEST_PAGE = Path(".tools/docs/app_manifest.md")
SECTION = Path(".tools/docs/app_manifest_host_requirements.md")

SECTION_HEADING = "## Plugin versions your tools need (optional)"
ANCHOR = "## The automatic check"
FOOTER = re.compile(r'^---[ \t]*\n(?:[ \t]*\n)*<div align="center">.*?</div>[ \t]*(?:\n|$)', re.MULTILINE | re.DOTALL)


def log(message: str) -> None:
print(f"{TAG} {message}")


def resource_bytes(relative: Path) -> bytes:
return (RESOURCE_ROOT / relative).read_bytes()


def with_section(text_lf: str, section: str) -> str:
"""The page with the section before "## The automatic check", else before its links, else at its end."""
lines = text_lf.split("\n")
for index, line in enumerate(lines):
if line.rstrip() == ANCHOR:
before = "\n".join(lines[:index]).rstrip("\n")
return before + "\n\n" + section.rstrip("\n") + "\n\n" + "\n".join(lines[index:])
footers = list(FOOTER.finditer(text_lf))
if footers:
start = footers[-1].start()
return text_lf[:start].rstrip("\n") + "\n\n" + section.rstrip("\n") + "\n\n" + text_lf[start:]
return text_lf.rstrip("\n") + "\n\n" + section


def update_schema(repo_root: Path) -> str:
path = repo_root / SCHEMA
if not path.is_file():
return "not present in this repository (nothing was created)"
data = resource_bytes(SCHEMA)
if path.read_bytes() == data:
return "unchanged: already the template's copy"
path.write_bytes(data)
return "updated: the template's copy (accepts host_requirements)"


def update_page(repo_root: Path) -> str:
path = repo_root / MANIFEST_PAGE
if not path.is_file():
return "not present in this repository (nothing was created)"
raw = path.read_bytes().decode("utf-8")
newline = "\r\n" if "\r\n" in raw else "\n"
text_lf = raw.replace("\r\n", "\n")
if SECTION_HEADING in (line.rstrip() for line in text_lf.split("\n")):
return "unchanged: already has the section on plugin versions"
section = resource_bytes(SECTION).decode("utf-8").replace("\r\n", "\n")
path.write_bytes(with_section(text_lf, section).replace("\n", newline).encode("utf-8"))
return "updated: added the section on plugin versions"


def migrate(repo_root: Path, context: dict[str, Any]) -> None:
"""Refresh the schema copy and document host_requirements (idempotent, never deletes)."""
_ = context
changed = 0
for name, step in ((SCHEMA, update_schema), (MANIFEST_PAGE, update_page)):
try:
status = step(repo_root)
except (OSError, UnicodeDecodeError) as exc:
status = f"SKIPPED: {exc}; left unchanged. See {DOCS_URL}"
changed += status.startswith("updated")
log(f"{name}: {status}")
if changed:
log(f"done: {changed} file(s) changed. See {DOCS_URL}")
else:
log("done: no repository changes were required.")
97 changes: 97 additions & 0 deletions .template_sync/migrations/v0_1_27_to_v0_1_28.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Template 0.1.27 -> 0.1.28: the installers use LabConstrictor-Tools v0.3.0-alpha.2, which registers an app's host_requirements.

Design note: https://github.com/CellMigrationLab/LabConstrictor/blob/main/.tools/docs/migration_0_1_28.md

Tools v0.3.0-alpha.2 (feature host_requirements_v1, LabConstrictor-Tools #155) copies the `host_requirements:` block of labconstrictor-app.yaml
into the registry entry, so napari, Fiji and QuPath can tell a person with an older plugin to update it. Older Tools ignore the block. What
this changes in an app repository (each step is independent, idempotent and never deletes anything):

1. `LC_TOOLS_PIN` in app/bash_bat_scripts/post_install.sh and post_install.bat moves from `v0.3.0-alpha.1` to `v0.3.0-alpha.2`, ONLY when the
line still holds exactly the old template value. An app with its own pin, a script without a pin line or without the Tools hook stays as it is,
with a note.
2. `.tools/docs/tools_bridge.md`: the tag name `v0.3.0-alpha.1` is replaced by `v0.3.0-alpha.2` (the guide names the pinned tag).

The pin reaches users with the app's next release.
"""
from __future__ import annotations

import re
from pathlib import Path
from typing import Any


DOCS_URL = "https://github.com/CellMigrationLab/LabConstrictor/blob/main/.tools/docs/migration_0_1_28.md"
TAG = "[migration 0.1.28]"
OLD_PIN = "v0.3.0-alpha.1"
NEW_PIN = "v0.3.0-alpha.2"
POST_INSTALL_SH = Path("app/bash_bat_scripts/post_install.sh")
POST_INSTALL_BAT = Path("app/bash_bat_scripts/post_install.bat")
TOOLS_DOC = Path(".tools/docs/tools_bridge.md")
SH_PIN_LINE = re.compile(r'^([ \t]*LC_TOOLS_PIN=")([^"]*)(".*)$')
BAT_PIN_LINE = re.compile(r'^([ \t]*SET "LC_TOOLS_PIN=)([^"]*)(".*)$', re.IGNORECASE)


def log(message: str) -> None:
print(f"{TAG} {message}")


def read(path: Path) -> str:
"""The file's text with its line endings as they are (bytes decoded as UTF-8)."""
return path.read_bytes().decode("utf-8")


def write(path: Path, text: str) -> None:
path.write_bytes(text.encode("utf-8"))


def move_pin(path: Path, pattern: re.Pattern[str]) -> str:
text = read(path)
if "labconstrictor_tools" not in text:
return "has no Tools bridge hook: nothing to move"
lines = text.splitlines(keepends=True)
hits = [(index, match) for index, line in enumerate(lines) if (match := pattern.match(line.rstrip("\r\n")))]
if not hits:
return "has no LC_TOOLS_PIN line (unpinned source or its own Tools source): left as it is"
if len(hits) > 1:
return f"has {len(hits)} LC_TOOLS_PIN lines: left as it is, set the pin by hand to {NEW_PIN}"
index, match = hits[0]
current = match.group(2)
if current == NEW_PIN:
return f"already pins Tools {NEW_PIN}: unchanged"
if current != OLD_PIN:
return f"has its own pin {current}: left as it is (the template pin is now {NEW_PIN})"
ending = lines[index][len(lines[index].rstrip("\r\n")) :]
lines[index] = f"{match.group(1)}{NEW_PIN}{match.group(3)}{ending}"
write(path, "".join(lines))
return f"updated: Tools pin {OLD_PIN} -> {NEW_PIN}"


def refresh_guide(path: Path) -> str:
text = read(path)
if OLD_PIN not in text:
return "does not name the old tag: unchanged"
write(path, text.replace(OLD_PIN, NEW_PIN))
return f"updated: names {NEW_PIN}"


def migrate(repo_root: Path, context: dict[str, Any]) -> None:
"""Move the Tools pin to v0.3.0-alpha.2 and refresh the Tools guide (idempotent, surgical, never raises for a customised file)."""
_ = context
changed = 0
steps = ((POST_INSTALL_SH, lambda p: move_pin(p, SH_PIN_LINE)), (POST_INSTALL_BAT, lambda p: move_pin(p, BAT_PIN_LINE)),
(TOOLS_DOC, refresh_guide))
for relative, step in steps:
path = repo_root / relative
if not path.is_file():
log(f"{relative}: not present in this repository (nothing was created)")
continue
try:
status = step(path)
except (OSError, UnicodeDecodeError) as exc:
status = f"SKIPPED: {exc}; left unchanged. See {DOCS_URL}"
changed += status.startswith("updated")
log(f"{relative}: {status}")
if changed:
log(f"done: {changed} file(s) changed. The pin reaches users with the next release of the app. See {DOCS_URL}")
else:
log("done: no repository changes were required.")
Loading
Loading