diff --git a/.gitignore b/.gitignore index bfae77c..2075a3b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ docs/assets/images/ previews/ docs/use/ docs/build/ +docs/connect/ docs/assets/hubs/ docs/assets/hosts/ docs/demo/ diff --git a/AGENTS.md b/AGENTS.md index e13bc64..a718990 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,14 +11,14 @@ A static site made with Zensical (Material-compatible, `mkdocs.yml`), published | Home | `/` | `pages_site.page_home` and `pages_home` (comic row, tiles), text in `data/site.yaml` | | App Centre and one page per app | `/apps/`, `/apps//` | `pages_apps`, from the snapshot (`build/snapshot.json`) | | Docs (front page) | `/guides/` | `hubs.write_docs_home` | -| Use / Build pages (picture cards) | `/use/`, `/build/` | `hubs`, from `data/hubs.yaml` | +| Use / Build / Connect pages (picture cards) | `/use/`, `/build/`, `/connect/` | `hubs`, from `data/hubs.yaml` | | Every guide | `/guides//` | `guides` (the sources are below) | | Ecosystem | `/ecosystem/` | `pages_site.page_ecosystem`, from `projects` and `related` (`pages_related`) | | Submit | `/submit/` | `pages_site.page_submit`, from `content/submit.md` | | How it works | `/how-it-works/` | `pages_how`, from `data/how-it-works.yaml` (five steps, one shown at a time by `content/how/how.js`; `how.css`) | | Demo | `/demo/` | `pages_demo`, from `data/demo.yaml`, `content/demo/` (windows, the macOS installer, script, style, images, `example.json`); home tile in `pages_site.page_home`, link in the Use hub | -Navigation: the top menu is Home, Apps, **Demo**, **How it works**, Ecosystem, **Docs**, Submit your app (the green button) (`mkdocs.yml` `nav`); the footer is in `overrides/main.html`. Every guide page and the Use/Build pages show the **same docs sidebar** (both tracks, collapsible, the current section open; on phones it folds into a "Docs menu" drawer) and highlight *Docs* in the menu. A guide belongs to a track, **use** or **build**; its crumb and pager stay inside the track. +Navigation: the top menu is Home, Apps, **Demo**, **How it works**, Ecosystem, **Docs**, Submit your app (the green button) (`mkdocs.yml` `nav`); the footer is in `overrides/main.html`. Every guide page and the Use/Build/Connect pages show the **same docs sidebar** (all three tracks, collapsible, the current section open; on phones it folds into a "Docs menu" drawer) and highlight *Docs* in the menu. A guide belongs to a track: **use** (people who use apps), **build** (people who turn notebooks into apps) or **connect** (people who make an app's tools run in napari, Fiji and QuPath, and the reference those plugins follow); its crumb and pager stay inside the track. ## Sources of truth @@ -36,24 +36,33 @@ Every topic is written on exactly one page, its owner. Every other page (READMEs | Install and use the Fiji plugin | LabConstrictor-Fiji `docs/user-guide.md` | `/guides/fiji/` | | Install and use the QuPath extension | LabConstrictor-QuPath `docs/user-guide.md` | `/guides/qupath/` | | What works where | LabConstrictor-Tools `docs/CAPABILITIES.md` | `/guides/capabilities/` | +| Expose an app's tools (the template side) | template `.tools/docs/tools_bridge.md` | `/guides/tools-bridge/` | | Write tools for an app | LabConstrictor-Tools `docs/AUTHORING.md` | `/guides/writing-tools/` | +| Tool markers (every marker a tool can use) | LabConstrictor-Tools `docs/MANIFEST.md` | `/guides/tool-markers/` | +| What each host does with each feature | LabConstrictor-Tools `docs/HOST_FEATURES.md` | `/guides/host-features/` | +| Technical reference of a plugin | that repository's `docs/REFERENCE.md` | `/guides/napari-reference/`, `/guides/fiji-reference/`, `/guides/qupath-reference/` | +| Install `labconstrictor-tools` by hand, check an installed app | LabConstrictor-Tools `docs/INSTALL.md` | `/guides/tools-install/` | +| Shared installs, security, troubleshooting, releases and tags | LabConstrictor-Tools `docs/OPERATIONS.md` | `/guides/tools-operations/` | | Publish the plugins and apps | LabConstrictor-Tools `docs/PUBLISHING.md` | `/guides/publishing/` | -| Technical reference of a plugin | that repository's `docs/REFERENCE.md` | GitHub only (developers) | +| Where each part lives | LabConstrictor-Tools `docs/REPOSITORIES.md` | `/guides/repositories/` | +| How the template registers an app's tools | LabConstrictor-Tools `docs/LABCONSTRICTOR_INTEGRATION.md` | `/guides/template-registration/` | +| The protocol between a plugin and an app (schema, compatibility, app hosts, host requirements) | LabConstrictor-Tools `docs/PROTOCOL.md` | `/guides/protocol/` | +| Maintainers' material (tests, regression ledger, conformance data, specifications, UI audits) | each repository's `docs/` | GitHub only | | What an app does and how to use it | the app's README and `labconstrictor-app.yaml` | `/apps//` | Rules agreed with the project lead: - A plugin's README gives one install line and links to its guide on this site. - Version numbers (for example a plugin's release or a supported program version) appear only in the owner guide. -- LabConstrictor-Tools' own docs site (cellmigrationlab.github.io/LabConstrictor-Tools/) is developer reference only; pages for users live only on this site. +- Every page a reader needs, users and tool authors alike, is on this site (track connect holds the developer reference). LabConstrictor-Tools' own docs site (cellmigrationlab.github.io/LabConstrictor-Tools/) is for maintainers; a link to one of its pages from an imported guide becomes the page here when that page is imported. - On this site, a hand-written page (`content/`, `data/`) never repeats a plugin's install steps, menu paths or version numbers: it links to the owner guide (the demo's program table does this with `guide:` in `data/demo.yaml`). - **Guides to build an app (track build)**: the template repository, `.tools/docs` (order and groups: its README), imported at build time. A template page that is really for users is placed in track use with `template: ` in `data/guides.yaml` (now `notebook_usage.md` and `troubleshooting_installed_app.md`); the build stops if the template drops it. -- **Guides kept next to the code they describe**: `docs/user-guide.md` in LabConstrictor-napari, LabConstrictor-Fiji, LabConstrictor-QuPath and LabConstrictor-Tools (which also gives `CAPABILITIES.md`, and, in the build track, `AUTHORING.md` and `PUBLISHING.md`), listed in `data/guides.yaml` as `{slug, repo, path}`. `scripts/fetch_guides.py` downloads them; the title is the first heading; GitHub alerts (`> [!WARNING]`) become admonitions; links and pictures must be absolute. To add a module, add one line. +- **Guides kept next to the code they describe**: `docs/user-guide.md` in LabConstrictor-napari, LabConstrictor-Fiji, LabConstrictor-QuPath and LabConstrictor-Tools (which also gives `CAPABILITIES.md`, and, in the build track, `AUTHORING.md` and `PUBLISHING.md`), listed in `data/guides.yaml` as `{slug, repo, path}`. `scripts/fetch_guides.py` downloads them; the title is the first heading; GitHub alerts (`> [!WARNING]`) become admonitions; relative links and pictures are resolved against the file's place in its repository (`sources.resolve_relative`): a link to a file that is also imported becomes that page, any other becomes the file on GitHub, a picture its raw address. To add a module, add one line. - **Menu titles** of template and repository guides are the page's own first heading (without a leading emoji), so a page and its menu entry never disagree. - **Ecosystem cards**: each project's `docs/labconstrictor-project.yaml` (checked against `schema/labconstrictor-project.schema.json`); `data/ecosystem.yaml` lists the repositories and headings. The template's card is inline there because its repository is copied into every app. Each card leads to the project's guide on this site (the first guide `data/guides.yaml` lists for that repository, or the one a `guide:` key in `data/ecosystem.yaml` names) and keeps a GitHub badge in its footer, plus an Open link when the project is hosted (a web app). A card with no guide leads to its repository or hosted address. - **Apps**: `registry/__.yaml` is a pointer (`repo`, `repo_id`, `owner_id`, `added`) plus optional curation: `featured` (home page), `section: testing` (listed apart under "Testing and maintenance", with a Testing badge). Everything an app says about itself is `labconstrictor-app.yaml` in its repository, checked against `schema/labconstrictor-app.schema.json`. Host chips on an app page ("napari plugin", plus the stage when it is not Available, read from the plugin's own project file) link to the matching guide. -- **Use / Build pictures and cards**: `data/hubs.yaml`; every picture is `doc_source:` (the template's `doc_source` branch) or `repo` + `path` (fetched), and needs alt text. A card marked `live_card` shows a real app card. +- **Use / Build / Connect pictures and cards**: `data/hubs.yaml`; every picture is `doc_source:` (the template's `doc_source` branch) or `repo` + `path` (fetched), and needs alt text. A card marked `live_card` shows a real app card. - **Install guide**: the template's `.tools/docs/install.md` (generic, for every app), placed in track use with `template: install.md`. App pages only link to it; the OS tile's short hint lines are in `pages_apps.os_tile`. - **Citation**: `citation:` in `data/site.yaml` is a deliberate copy of the "Citation" section of the template README (`citation.check_template_readme` stops the build if the README loses the DOI); an app page cites only what its manifest `doi` says. - **Facts on an app page** (`inputs`, `outputs`, `limitations`, `status`) come only from the app's manifest; the site never infers them. `completeness.missing` turns recommended facts that are absent into warnings in `build/problems.md`. @@ -63,7 +72,7 @@ Rules agreed with the project lead: - **Demo numbers and images**: `content/demo/example.json` and the `.webp` files are generated by `tools/demo_assets/make_demo_assets.py` (it runs the released NucleiSky code offline on the maintainers' images; provenance and licence in `content/demo/README.md`). Never edit them by hand; the site build only reads them. - **Moved addresses**: `data/redirects.yaml` (old -> new, both with a trailing slash) writes a small redirect page at the old address; the build stops if the old address is a real page or the new one does not exist. Add a line whenever a page is renamed, including a template doc renamed in the template. - The logo and the comic come from the template's `doc_source` branch. -- **Generated and git-ignored**: `docs/index.md`, `docs/apps/`, `docs/guides/`, `docs/use/`, `docs/build/`, `docs/ecosystem.md`, `docs/submit.md`, `docs/demo/`, `docs/assets/demo/`, `docs/llms.txt`, `docs/assets/{icons,shots,docs-img,images,hubs}/`, `build/`, `site/`. +- **Generated and git-ignored**: `docs/index.md`, `docs/apps/`, `docs/guides/`, `docs/use/`, `docs/build/`, `docs/connect/`, `docs/ecosystem.md`, `docs/submit.md`, `docs/demo/`, `docs/assets/demo/`, `docs/llms.txt`, `docs/assets/{icons,shots,docs-img,images,hubs}/`, `build/`, `site/`. - The site is indexable because `extra.listed` is `true` in `mkdocs.yml` (`false` would put noindex on every page, make `robots.txt` disallow all and empty the sitemap). `site_url` is the address everything follows. ## Design @@ -103,7 +112,7 @@ The one deliberate exception is per-app: an app that cannot be resolved is left - Every new behaviour gets a test in `tests/`, including its failure case. - **One look per role** (DESIGN.md, "The design system"): sizes are the `--fs-*` tokens only (`tests/test_design_system.py` fails on any other `font-size`), boxes use `--pad-box` and `--radius-box`; shared looks are defined in the "roles" section at the end of `lc.css`, not per part. - Escape app-written text (`text.esc`); never render it as HTML or Markdown. -- Preserve public addresses (`/apps//`, `/guides//`, `/use/`, `/build/`, `/ecosystem/`, `/submit/`) unless a redirect is added. +- Preserve public addresses (`/apps//`, `/guides//`, `/use/`, `/build/`, `/connect/`, `/ecosystem/`, `/submit/`) unless a redirect is added. ## Before you push diff --git a/content/guides/help.md b/content/guides/help.md index 335c366..42e0b47 100644 --- a/content/guides/help.md +++ b/content/guides/help.md @@ -23,3 +23,4 @@ Each guide ends with a section called *If something does not work*: [napari](../ |---|---| | A workflow run failed in the Actions tab of your repository | [Check the status of GitHub workflows](../workflow-status/index.md#2-how-to-debug-a-failure) | | A problem while setting up your repository | [Troubleshooting repository setup](../troubleshooting/index.md) | +| Your app's tools do not appear in napari, Fiji or QuPath, or a tool fails there | [Shared installs, security and troubleshooting](../tools-operations/index.md) | diff --git a/content/guides/using-apps.md b/content/guides/using-apps.md index 7e1cf49..972e1d7 100644 --- a/content/guides/using-apps.md +++ b/content/guides/using-apps.md @@ -12,6 +12,10 @@ Want to see the idea first? The [interactive demo](../../demo/index.md) lets you Look for an example in the app's documentation (the **Documentation** or **README** link on its page in the [App Centre](../../apps/index.md)). If it has one, run it first and compare with the result it describes. +## Use it in napari, Fiji or QuPath + +Some apps also declare **tools**: analyses you can run from napari, Fiji or QuPath on the image you have open, with a form for the settings and the results drawn on the image. An app's page in the [App Centre](../../apps/index.md) shows which programs it works in. Install the plugin for your program once; [Use apps inside napari, Fiji and QuPath](../image-software/index.md) explains how. + ## Keep your results Where a notebook writes its results is set in that notebook. Note the folder it names before you close JupyterLab, and copy what you want to keep. diff --git a/data/guides.yaml b/data/guides.yaml index 1db5ff1..78a25a7 100644 --- a/data/guides.yaml +++ b/data/guides.yaml @@ -1,10 +1,13 @@ -# Guides for people who use apps ("Use an app" track), in sidebar order; a section with `track: build` goes at the end of the "Build an app" track. The guides for people who build apps -# are imported from LabConstrictor/.tools/docs ("Build an app" track) and never copied here. +# The guides of the three tracks, in sidebar order. Each section belongs to a track: "use" (the default: people who use apps), +# "build" (shown after the template's own guides, which are imported from LabConstrictor/.tools/docs and never copied here) or +# "connect" (people who make an app's tools run in napari, Fiji and QuPath, and the reference those plugins follow). # file: hand-written here, in content/guides/ (this repository is the only place it exists) # repo/path: kept in another repository (a user guide next to the code it describes); fetched at build time by -# scripts/fetch_guides.py, titled by its first '# Heading'. Adding a module = adding one line here. -# template: a page of the template's docs that is for users, shown here; title and text stay in the template +# scripts/fetch_guides.py, titled by its first '# Heading'. Adding a module = adding one line here. Its relative links are +# resolved: to the page here when the file it names is imported too, otherwise to the file on GitHub. +# template: a page of the template's docs, shown in this section instead of the template's; title and text stay in the template # (the build stops if the template no longer has it) +# Pages for the people who maintain the plugins (test ledgers, conformance data, specifications, UI audits) stay in their repositories. # Guides a first-time reader must be able to follow to the end: scripts/check_site.py warns when one lacks "What you need" (or # "Before you start"), "Check that it worked" or "If something does not work". critical: [install, initialise-repository, notebook-requirements, notebook-upload, executable-creation] @@ -26,8 +29,28 @@ sections: - title: Connect to a microscope items: - {slug: microscope, repo: CellMigrationLab/NucleiSky, path: docs/smart_microscopy/smart_microscopy.md} - - title: Tools for napari, Fiji and QuPath - track: build # shown at the end of the "Build an app" track, after the template's guides + - title: Start here + track: connect items: + - {template: tools_bridge.md} - {slug: writing-tools, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/AUTHORING.md} + - title: Reference for tool authors + track: connect + items: + - {slug: tool-markers, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/MANIFEST.md} + - {slug: host-features, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/HOST_FEATURES.md} + - {slug: napari-reference, repo: CellMigrationLab/LabConstrictor-napari, path: docs/REFERENCE.md} + - {slug: fiji-reference, repo: CellMigrationLab/LabConstrictor-Fiji, path: docs/REFERENCE.md} + - {slug: qupath-reference, repo: CellMigrationLab/LabConstrictor-QuPath, path: docs/REFERENCE.md} + - title: Install, troubleshoot and publish + track: connect + items: + - {slug: tools-install, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/INSTALL.md} + - {slug: tools-operations, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/OPERATIONS.md} - {slug: publishing, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/PUBLISHING.md} + - title: How it fits together + track: connect + items: + - {slug: repositories, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/REPOSITORIES.md} + - {slug: template-registration, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/LABCONSTRICTOR_INTEGRATION.md} + - {slug: protocol, repo: CellMigrationLab/LabConstrictor-Tools, path: docs/PROTOCOL.md} diff --git a/data/hubs.yaml b/data/hubs.yaml index af6d0a9..3e0a7a2 100644 --- a/data/hubs.yaml +++ b/data/hubs.yaml @@ -1,10 +1,11 @@ -# The two hub pages: /use/ (people who use apps) and /build/ (people who make them). +# The hub pages: /use/ (people who use apps), /build/ (people who make them) and /connect/ (people who make an app's tools +# run in napari, Fiji and QuPath). # Every picture is `doc_source: ` or `repo` + `path` (a file kept in # another repository, fetched by scripts/fetch_guides.py). Every picture needs an `alt`. Keep each claim true of # what the template builds today; the guides they link to are the proof. docs: title: Docs - lead: Use an app someone built, or build your own. + lead: Use an app someone built, build your own, or connect it to napari, Fiji and QuPath. use: title: Use an app lead: Install an app on your computer, open it, and, for apps that declare tools, try them in napari, Fiji or QuPath. @@ -73,8 +74,8 @@ build: live_card: true - title: It can reach napari, Fiji and QuPath text: An app's declared tools can run in those programs through their plugins. - href: guides/image-software/ - link: Use apps in your image software + href: connect/ + link: Connect an app image: {repo: CellMigrationLab/LabConstrictor-Tools, path: docs/img/F2_fiji_form_top.png} alt: Fiji with a dialog generated from a tool's declaration, next to an image of bright spots. flow_title: The five steps @@ -84,3 +85,25 @@ build: text: A quick overview, one step at a time, from a notebook to an app that people can install. href: how-it-works/ link: How LabConstrictor works +connect: + title: Connect an app + lead: Declare your app's analyses once, in Python, and they run in napari, Fiji and QuPath through their plugins, with a form, results drawn on the image and a table. + cards: + - title: Declare a tool, get a form + text: A typed Python function becomes a tool. Each plugin builds the form from its declaration, so you write no interface code. + href: guides/writing-tools/ + link: Write tools + image: {repo: CellMigrationLab/LabConstrictor-Tools, path: docs/img/N4_napari_result.png} + alt: napari with the LabConstrictor tools panel open on NucleiSky's Relocalize 2D tool, a form of images, pixel sizes and segmentation settings, with the result of the run under the Run button. + - title: One menu entry in each program + text: The plugins list every installed app that declares tools. Each program's guide says what it does with each kind of input and result. + href: guides/host-features/ + link: What each host does + image: {repo: CellMigrationLab/LabConstrictor-Tools, path: docs/img/F0_fiji_menu.png} + alt: "Fiji's Plugins menu with the LabConstrictor entry open on LabConstrictor Tools." + - title: Errors people can act on + text: A tool that fails reports a sentence, a code and the run record, so the person, or you, can see what went wrong. + href: guides/tools-operations/ + link: Troubleshoot + image: {repo: CellMigrationLab/LabConstrictor-Tools, path: docs/img/F8_fiji_error_dialog.png} + alt: "A Fiji error dialog for a failed run: the message cannot read fake.tif, not a TIFF file, then the last lines of the worker, the run record and the log file." diff --git a/docs/assets/stylesheets/lc.css b/docs/assets/stylesheets/lc.css index efe7156..9401ff9 100644 --- a/docs/assets/stylesheets/lc.css +++ b/docs/assets/stylesheets/lc.css @@ -137,6 +137,8 @@ body { background: var(--lc-bg); color: var(--lc-fg); font-family: var(--lc-sans .lc-hero__art::before { content: ""; position: absolute; inset: -6%; border-radius: 50%; background: var(--lc-orange-soft); } .lc-hero__art img { position: relative; display: block; width: 100%; height: auto; } .lc-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1.8rem; } +.lc-choices--three { grid-template-columns: repeat(3, minmax(0, 1fr)); } +@media (max-width: 60rem) { .lc-choices--three { grid-template-columns: 1fr; } } .md-typeset .lc-choice { display: flex; flex-direction: column; gap: .35rem; padding: 1.1rem 1.2rem; border: 1px solid var(--lc-line); border-top: 4px solid var(--lc-accent); border-radius: .6rem; background: #fff; color: var(--lc-fg); text-decoration: none; transition: transform .15s, box-shadow .15s; } .md-typeset .lc-choice--make { border-top-color: var(--lc-orange); } .md-typeset .lc-choice:hover { transform: translateY(-2px); box-shadow: 0 .7rem 1.6rem rgba(16, 33, 26, .12); color: var(--lc-fg); } @@ -307,9 +309,9 @@ a.lc-badge { text-decoration: none; } a.lc-badge:hover { filter: brightness(.95); text-decoration: underline; } [dir] .md-typeset .lc-feature__shot > a > img { height: 100%; } [dir] .md-typeset .lc-feature__shot--wide > a > img { height: auto; } -.lc-guides--two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem; margin-top: 2.2rem; } -.lc-guides--two section > h2 { margin-top: 0; } -@media (max-width: 44rem) { .lc-guides--two { grid-template-columns: 1fr; } } +.lc-guides--tracks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2rem; margin-top: 2.2rem; } +.lc-guides--tracks section > h2 { margin-top: 0; } +@media (max-width: 60rem) { .lc-guides--tracks { grid-template-columns: 1fr; } } .lc-docs__nav .lc-docs__track a { padding: 0; border: 0; } .lc-edit { margin: 2rem 0 0; font-size: var(--fs-sm); } diff --git a/scripts/check_site.py b/scripts/check_site.py index a7461c1..2a7ade7 100644 --- a/scripts/check_site.py +++ b/scripts/check_site.py @@ -200,11 +200,12 @@ def search_index_problems() -> list[str]: texts = {e["location"]: e["text"] for e in entries} hubs = load_yaml(DATA / "hubs.yaml") found = [] - for track in ("use", "build"): + for track in ("use", "build", "connect"): + if track + "/" not in texts: + found.append(f"search.json has no entry for the {track} hub") + continue for card in hubs[track]["cards"]: - if track + "/" not in texts: - found.append(f"search.json has no entry for the {track} hub") - elif card["text"][:40] in texts[track + "/"]: + if card["text"][:40] in texts[track + "/"]: found.append(f"search.json: the text of the {track} hub card {card['title']!r} is searchable (data-search-exclude is not honoured)") return found diff --git a/scripts/lcsite/guides.py b/scripts/lcsite/guides.py index f3d223c..722168c 100644 --- a/scripts/lcsite/guides.py +++ b/scripts/lcsite/guides.py @@ -137,7 +137,8 @@ def side(item: dict | None, cls: str, label: str) -> str: HOSTS_BY_SLUG = hosts.load() # a guide named after a host (napari, fiji, qupath) shows that program's logo -TRACKS = {"use": "Use an app", "build": "Build an app"} # the two audiences; every guide section belongs to one +TRACKS = {"use": "Use an app", "build": "Build an app", "connect": "Connect an app"} # the three audiences; every guide section belongs to one +# connect: people who make an app's tools run in napari, Fiji and QuPath (tool authors), and the reference those hosts follow def nav_for(sections: list[dict]) -> list[dict]: @@ -176,7 +177,7 @@ def guide_lists(nav: list[dict], track: str) -> str: def write_source_guide(g: dict, nav: list[dict], tail: str, pages: dict[tuple[str, str], str]) -> None: """guides//index.md from a guide kept in another repository (fetched by scripts/fetch_guides.py).""" where = f"{g['repo']}/{g['path']}" - text = sources.read(g["repo"], g["path"]) + text = sources.resolve_relative(sources.read(g["repo"], g["path"]), g["repo"], g["path"]) sources.check_links(text, where) text = gfm.lists(localise(sources.admonitions(sources.site_links(text, pages)))) p = Page(f"guides/{g['slug']}/index.md", **guide_meta(nav, g["slug"]), description=describe(text, where), @@ -185,13 +186,16 @@ def write_source_guide(g: dict, nav: list[dict], tail: str, pages: dict[tuple[st p.write() -def write_template_guide(g: dict, docs_dir: Path, doc_source: Path, nav: list[dict], known: set[str], tail: str) -> None: - """guides//index.md from one page of the template's .tools/docs.""" +def write_template_guide(g: dict, template: tuple, nav: list[dict], tail: str, pages: dict[tuple[str, str], str]) -> None: + """guides//index.md from one page of the template's .tools/docs (`template`: its docs folder, the doc_source checkout and + the names of its listed pages). A link to a page imported from another repository becomes that page here.""" + docs_dir, doc_source, known = template src = docs_dir / g["file"] if not src.is_file(): fail(f"README of the template lists {g['file']}, which does not exist") text = NAV_BLOCK.sub("", src.read_text(encoding="utf-8")) - text = gfm.lists(localise(copy_images(rewrite_links(own_repo_paths(text), known), doc_source, g["file"]))) + text = sources.site_links(sources.docs_site_to_files(rewrite_links(own_repo_paths(text), known), TEMPLATE_REPO.split("/")[0]), pages) + text = gfm.lists(localise(copy_images(text, doc_source, g["file"]))) edit = f"https://github.com/{TEMPLATE_REPO}/edit/main/.tools/docs/{g['file']}" p = Page(f"guides/{g['slug']}/index.md", **guide_meta(nav, g["slug"]), description=describe(text, g["file"]), edit_url=edit) p.add(text.strip(), "", tail) @@ -201,7 +205,7 @@ def write_template_guide(g: dict, docs_dir: Path, doc_source: Path, nav: list[di def write_guide(g: dict, nav: list[dict], tail: str, template: tuple, pages: dict[tuple[str, str], str]) -> None: """Write one guide from wherever it lives: the template, another repository or this repository.""" if g["from_template"]: - write_template_guide(g, template[0], template[1], nav, template[2], tail) + write_template_guide(g, template, nav, tail, pages) elif "repo" in g: write_source_guide(g, nav, tail, pages) else: @@ -243,7 +247,7 @@ def claim_template_pages(own: list[dict], theirs: list[dict]) -> None: def read_sections(docs_dir: Path) -> tuple[list[dict], list[dict]]: - """Our own sections (data/guides.yaml, track "use" unless a section says `track: build`) and the template's (its docs README, track "build"), each guide + """Our own sections (data/guides.yaml, track "use" unless a section names another track) and the template's (its docs README, track "build"), each guide with its slug and where it comes from. Guides kept in other repositories are titled by their first heading.""" own = load_yaml(DATA / "guides.yaml")["sections"] theirs = parse_index((docs_dir / "README.md").read_text(encoding="utf-8")) @@ -262,7 +266,8 @@ def read_sections(docs_dir: Path) -> tuple[list[dict], list[dict]]: def build(template_dir: Path, doc_source: Path) -> list[dict]: - """Write guides/: our own sections (data/guides.yaml, track "use"), then the template's .tools/docs as track "build". + """Write guides/: our own "use" sections, the template's .tools/docs as track "build" (then our own "build" sections), and our own + "connect" sections (data/guides.yaml). Returns the sidebar sections (title, track, items) for the hub pages.""" docs_dir = template_dir / ".tools" / "docs" if not docs_dir.is_dir(): @@ -274,7 +279,8 @@ def build(template_dir: Path, doc_source: Path) -> list[dict]: clash = {g["slug"] for s in own for g in s["items"] if not g["from_template"]} & {g["slug"] for s in theirs for g in s["items"]} if clash: fail(f"guide address used twice (data/guides.yaml and the template): {sorted(clash)}") - sections = [s for s in own if s["track"] == "use"] + [s for s in theirs if s["items"]] + [s for s in own if s["track"] == "build"] + sections = ([s for s in own if s["track"] == "use"] + [s for s in theirs if s["items"]] + + [s for s in own if s["track"] == "build"] + [s for s in own if s["track"] == "connect"]) title_template_pages(sections, docs_dir) warn_unlisted(docs_dir, theirs, own) nav = nav_for(sections) diff --git a/scripts/lcsite/hubs.py b/scripts/lcsite/hubs.py index a4dba42..994b481 100644 --- a/scripts/lcsite/hubs.py +++ b/scripts/lcsite/hubs.py @@ -1,4 +1,4 @@ -"""The two hub pages, /use/ and /build/: cards with a picture, then every guide of the track.""" +"""The hub pages, /use/, /build/ and /connect/: cards with a picture, then every guide of the track.""" from pathlib import Path @@ -114,18 +114,18 @@ def write_hub(track: str, hub: dict, nav: list[dict], doc_source: Path, apps: li def write_docs_home(hubs: dict, nav: list[dict]) -> None: """guides/index.md: the front page of the docs (menu entry "Docs"): one card per track, then every guide.""" - p = Page("guides/index.md", title="Docs", description="Guides for using LabConstrictor apps and for building your own.", + p = Page("guides/index.md", title="Docs", description="Guides for using LabConstrictor apps, building your own, and connecting them to napari, Fiji and QuPath.", guide_nav=nav, guide_id="", docs_home=True, menu="guides/", edit_url=f"{REPO}/edit/main/data/hubs.yaml") cards = "".join(f'{esc(hubs[t]["title"])}' f'{esc(hubs[t]["lead"])}Go to {esc(hubs[t]["title"])}' for t in TRACKS) p.add(f'

{esc(hubs["docs"]["title"])}

{esc(hubs["docs"]["lead"])}

', - f'
{cards}
', notes_html(hubs["use"]), notes_html(hubs["build"]), - '
' + "".join(f'

{esc(TRACKS[t])}

{guide_lists(nav, t)}
' for t in TRACKS) + "
") + f'
{cards}
', notes_html(hubs["use"]), notes_html(hubs["build"]), + '
' + "".join(f'

{esc(TRACKS[t])}

{guide_lists(nav, t)}
' for t in TRACKS) + "
") p.write() def write_all(hubs: dict, nav: list[dict], doc_source: Path, apps: list[dict]) -> None: - """Write both hub pages.""" + """Write the hub pages and the Docs home.""" taken: dict[str, Path] = {} for name, hub in hubs.items(): check_hub(name, hub) diff --git a/scripts/lcsite/sources.py b/scripts/lcsite/sources.py index 959f196..f764444 100644 --- a/scripts/lcsite/sources.py +++ b/scripts/lcsite/sources.py @@ -3,9 +3,12 @@ A guide is one Markdown file kept in the repository it describes (`docs/user-guide.md`). data/guides.yaml lists it as `{slug, repo, path}`; adding a module to the site is adding one such line. `fetch` downloads the files (the only network step for guides); the rest reads them from build/sources/ and works offline. -Anything that cannot be converted (no title, a relative link or picture) stops the build. +A relative link or picture is resolved against the file's place in its repository (a page written for its own repository's docs +site links `PROTOCOL.md`): a link becomes the file on GitHub (and then the site page, when that file is imported too), a picture +its raw address. Anything that cannot be converted (no title, a link that leaves the repository) stops the build. """ +import posixpath import re from pathlib import Path @@ -17,6 +20,11 @@ ALERT = re.compile(r"^> \[!(?PNOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\n(?P(?:>.*\n?)+)", re.M) ALERT_TITLE = re.compile(r"^\*\*(.+?)\.?\*\*\s*") RELATIVE = re.compile(r"!?\[[^\]]*\]\(\s*(?!(?:[a-z][a-z0-9+.-]*:|#|/))([^)\s]+)") +RELATIVE_LINK = re.compile(r"(!?)\[([^\]]*)\]\(\s*(?!(?:[a-z][a-z0-9+.-]*:|#|/))([^)\s#]+)(#[^)\s]*)?\)") +# A repository's own docs site (MkDocs on GitHub Pages: https://.github.io///), linked by pages written before +# this site imported them; read as the page's file in docs/ so that an imported page becomes a site link. +PAGES_SITE = re.compile(r"\]\(https://([\w-]+)\.github\.io/([\w.-]+)/([A-Za-z0-9_-]+)/(#[^)\s]*)?\)") +SITE_REPO = "LabConstrictor-Site" # this site itself: its addresses are pages, not a repository's docs BLOB = re.compile(r"\]\(https://github\.com/([\w.-]+/[\w.-]+)/blob/(?:main|HEAD)/([^)\s#]+)(#[^)\s]*)?\)") KINDS = {"NOTE": "note", "TIP": "tip", "IMPORTANT": "warning", "WARNING": "warning", "CAUTION": "danger"} @@ -76,6 +84,35 @@ def box(m: re.Match) -> str: return ALERT.sub(box, text) +def docs_site_to_files(text: str, owner: str) -> str: + """Links to a docs site of `owner`'s repositories (https://.github.io///) -> that page's file in the repository's + docs/ on GitHub, so that `site_links` turns an imported one into a page here. This site's own addresses are left as they are.""" + def docs_page(m: re.Match) -> str: + """The docs-site address as the file in that repository's docs/ (the owner spelled as the guide list spells it).""" + if m.group(1).lower() != owner.lower() or m.group(2) == SITE_REPO: + return m.group(0) + return f"](https://github.com/{owner}/{m.group(2)}/blob/main/docs/{m.group(3)}.md{m.group(4) or ''})" + return PAGES_SITE.sub(docs_page, text) + + +def resolve_relative(text: str, repo: str, path: str) -> str: + """Relative links and pictures of `repo`/`path` -> absolute GitHub addresses (blob for a link, raw for a picture), and the + docs-site addresses of the same owner -> files (`docs_site_to_files`). A link that leaves the repository stops the build.""" + folder = posixpath.dirname(path) + + def absolute(m: re.Match) -> str: + """The link or picture with an absolute address.""" + bang, label, target, frag = m.group(1), m.group(2), m.group(3), m.group(4) or "" + full = posixpath.normpath(posixpath.join(folder, target)) + if full.startswith(".."): + fail(f"{repo}/{path} links {target}, outside its repository") + if bang: + return f"![{label}](https://raw.githubusercontent.com/{repo}/main/{full})" + return f"[{label}](https://github.com/{repo}/blob/main/{full}{frag})" + + return RELATIVE_LINK.sub(absolute, docs_site_to_files(text, repo.split("/")[0])) + + def check_links(text: str, where: str) -> None: """A guide may only use absolute links and pictures (it is read on GitHub and on the site); a relative one stops the build.""" bad = RELATIVE.findall(text) diff --git a/tests/test_page_text.py b/tests/test_page_text.py index 0d4bbba..8e07b2d 100644 --- a/tests/test_page_text.py +++ b/tests/test_page_text.py @@ -67,11 +67,11 @@ def test_a_card_text_in_the_index_is_reported(self) -> None: card = load_yaml(DATA / "hubs.yaml")["use"]["cards"][0] with tempfile.TemporaryDirectory() as tmp: site = Path(tmp) - (site / "search.json").write_text(json.dumps({"items": [{"location": "use/", "text": card["text"]}, {"location": "build/", "text": "Build an app"}]}), encoding="utf-8") + (site / "search.json").write_text(json.dumps({"items": [{"location": "use/", "text": card["text"]}, {"location": "build/", "text": "Build an app"}, {"location": "connect/", "text": "Connect an app"}]}), encoding="utf-8") old, check_site.SITE = check_site.SITE, site try: found = check_site.search_index_problems() - (site / "search.json").write_text(json.dumps({"items": [{"location": "use/", "text": "Use an app"}, {"location": "build/", "text": "Build an app"}]}), encoding="utf-8") + (site / "search.json").write_text(json.dumps({"items": [{"location": "use/", "text": "Use an app"}, {"location": "build/", "text": "Build an app"}, {"location": "connect/", "text": "Connect an app"}]}), encoding="utf-8") clean = check_site.search_index_problems() finally: check_site.SITE = old diff --git a/tests/test_site.py b/tests/test_site.py index b6909db..164cceb 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -134,21 +134,6 @@ def test_alert_becomes_an_admonition_with_its_title(self) -> None: self.assertIn(" Second paragraph.", out) self.assertTrue(out.endswith("After\n")) - def test_relative_link_or_picture_stops_the_build(self) -> None: - """A relative link or picture would break on the site, so it fails and names the guide.""" - with self.assertRaises(SystemExit) as ctx: - sources.check_links("See [x](other.md) and ![p](shot.png)", "repo/docs/user-guide.md") - self.assertIn("repo/docs/user-guide.md", str(ctx.exception)) - sources.check_links("[ok](https://example.org/a) [here](#top)", "x") - - def test_link_to_an_imported_guide_points_at_the_site_page(self) -> None: - """A link to another imported guide's file on GitHub becomes a site link; other links stay.""" - pages = {("o/r", "docs/user-guide.md"): "r"} - text = "[a](https://github.com/o/r/blob/main/docs/user-guide.md#x) [b](https://github.com/o/r/blob/main/README.md)" - out = sources.site_links(text, pages) - self.assertIn("[a](../r/index.md#x)", out) - self.assertIn("[b](https://github.com/o/r/blob/main/README.md)", out) - def test_title_is_the_first_heading_or_the_build_stops(self) -> None: """The title of a guide is its first '# ' line; a guide without one fails.""" self.assertEqual(sources.title_of("intro\n# The title\n## Part", "x"), "The title") diff --git a/tests/test_sources.py b/tests/test_sources.py new file mode 100644 index 0000000..f7c0cb4 --- /dev/null +++ b/tests/test_sources.py @@ -0,0 +1,57 @@ +"""Guides kept in other repositories: link and picture conversion for the site (lcsite.sources).""" + +import unittest + +from lcsite import sources + + +class SourceLinkTests(unittest.TestCase): + """How a fetched page's links and pictures become site pages or absolute addresses.""" + + def test_relative_link_or_picture_stops_the_build(self) -> None: + """A relative link or picture would break on the site, so it fails and names the guide.""" + with self.assertRaises(SystemExit) as ctx: + sources.check_links("See [x](other.md) and ![p](shot.png)", "repo/docs/user-guide.md") + self.assertIn("repo/docs/user-guide.md", str(ctx.exception)) + sources.check_links("[ok](https://example.org/a) [here](#top)", "x") + + def test_link_to_an_imported_guide_points_at_the_site_page(self) -> None: + """A link to another imported guide's file on GitHub becomes a site link; other links stay.""" + pages = {("o/r", "docs/user-guide.md"): "r"} + text = "[a](https://github.com/o/r/blob/main/docs/user-guide.md#x) [b](https://github.com/o/r/blob/main/README.md)" + out = sources.site_links(text, pages) + self.assertIn("[a](../r/index.md#x)", out) + self.assertIn("[b](https://github.com/o/r/blob/main/README.md)", out) + + def test_relative_links_and_pictures_are_resolved_in_their_repository(self) -> None: + """A page written for its repository's own docs: a relative link becomes the file on GitHub (then the site page when imported), + a picture its raw address; anchors and absolute links stay; the result passes check_links.""" + text = "[p](PROTOCOL.md#rules) [up](../README.md) ![s](img/a.png) [abs](https://x.org/a.md) [here](#top)" + out = sources.resolve_relative(text, "O/r", "docs/MANIFEST.md") + self.assertIn("[p](https://github.com/O/r/blob/main/docs/PROTOCOL.md#rules)", out) + self.assertIn("[up](https://github.com/O/r/blob/main/README.md)", out) + self.assertIn("![s](https://raw.githubusercontent.com/O/r/main/docs/img/a.png)", out) + self.assertIn("[abs](https://x.org/a.md) [here](#top)", out) + sources.check_links(out, "O/r/docs/MANIFEST.md") + self.assertIn("[p](../protocol/index.md#rules)", sources.site_links(out, {("O/r", "docs/PROTOCOL.md"): "protocol"})) + + def test_a_relative_link_out_of_the_repository_stops_the_build(self) -> None: + """A link that climbs above the repository cannot be resolved: the build stops and names the page.""" + with self.assertRaises(SystemExit) as ctx: + sources.resolve_relative("[x](../../elsewhere.md)", "O/r", "docs/MANIFEST.md") + self.assertIn("O/r/docs/MANIFEST.md", str(ctx.exception)) + + def test_a_docs_site_address_becomes_the_page_file(self) -> None: + """https://.github.io/// of the same owner becomes docs/.md (spelled as the guide list spells the owner), + so an imported page links here; this site's own addresses and other owners' sites stay as they are.""" + text = ("[m](https://cellmigrationlab.github.io/LabConstrictor-Tools/MANIFEST/#hosts) " + "[s](https://cellmigrationlab.github.io/LabConstrictor-Site/guides/) [o](https://other.github.io/Repo/PAGE/)") + out = sources.docs_site_to_files(text, "CellMigrationLab") + self.assertIn("[m](https://github.com/CellMigrationLab/LabConstrictor-Tools/blob/main/docs/MANIFEST.md#hosts)", out) + self.assertIn("[s](https://cellmigrationlab.github.io/LabConstrictor-Site/guides/)", out) + self.assertIn("[o](https://other.github.io/Repo/PAGE/)", out) + + + +if __name__ == "__main__": + unittest.main()