Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 4373ecc6f4d857be4d05a63dafe2304ab3f4f81a authored by Petr Kungurtsev on 05 July 2022, 09:43:19 UTC, committed by GitHub on 05 July 2022, 09:43:19 UTC
Experimental Apple Silicon (M1) support (#1924)
1 parent 5110164
  • Files
  • Changes
  • c75bac1
  • /
  • doc
  • /
  • update_versions.py
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:4373ecc6f4d857be4d05a63dafe2304ab3f4f81a
directory badge Iframe embedding
swh:1:dir:1fe128b1f3833e4c540e8b5f767abde08485bc97
content badge Iframe embedding
swh:1:cnt:b45b67827079ee32d65cce9e85e4fb3a42624bf5
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
update_versions.py
# Copyright 2022 The GPflow Contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Tool for updating the `versions.json` and `index.html` in our documentation.
"""
import argparse
import json
from pathlib import Path
from typing import Any, List, Mapping, Optional

from packaging.version import Version
from versions import Branch


class _Versions:
    def __init__(self, versions: List[Mapping[str, Any]]) -> None:
        self._versions = versions
        self._sorted = False

    @staticmethod
    def _versions_json(dest: Path) -> Path:
        return dest / "versions.json"

    @staticmethod
    def read(docs_dir: Path) -> "_Versions":
        if _Versions._versions_json(docs_dir).exists():
            with _Versions._versions_json(docs_dir).open("rt") as versions_file:
                versions = json.load(versions_file)
        else:
            versions = {}
        return _Versions(versions)

    def write(self, docs_dir: Path) -> None:
        with _Versions._versions_json(docs_dir).open("wt") as versions_file:
            json.dump(self._versions, versions_file, indent=2)

    def add(self, version: str) -> None:
        self._versions = [v for v in self._versions if v["version"] != version]
        self._versions.append(
            {
                "version": version,
                "url": f"https://gpflow.github.io/GPflow/{version}/index.html",
            }
        )
        self._sorted = False

    def sort(self) -> None:
        develop: Optional[Mapping[str, Any]] = None
        for v in self._versions:
            if v["version"] == "develop":
                develop = v
        versions = [v for v in self._versions if v["version"] != "develop"]
        versions.sort(key=lambda v: Version(v["version"]), reverse=True)
        if develop is not None:
            # Insert `develop` in the second spot, after the latest release, but before older
            # releases:
            versions.insert(1, develop)
        self._versions = versions
        self._sorted = True

    @property
    def latest(self) -> str:
        assert self._sorted, "Must sort versions to find latest."
        latest = self._versions[0]["version"]
        assert isinstance(latest, str)  # Hint for mypy.
        return latest


def _create_root_redirect(versions: _Versions, dest: Path) -> None:

    (dest / "index.html").write_text(
        f"""<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>GPflow documentation</title>
    <meta http-equiv="refresh" content="0;URL='{versions.latest}/index.html'" />
  </head>
  <body>
    <p>Redirecting to the most recent release.</p>
  </body>
</html>
"""
    )


def main() -> None:
    parser = argparse.ArgumentParser(description="Build the GPflow documentation.")
    parser.add_argument(
        "branch",
        type=str,
        choices=[b.value for b in Branch],
        help="Git branch that is currently being built.",
    )
    parser.add_argument("docs_dir", type=Path, help="To read / write docs versions from.")
    args = parser.parse_args()
    branch = Branch(args.branch)
    docs_dir = args.docs_dir

    versions = _Versions.read(docs_dir)
    versions.add(branch.version)
    versions.sort()
    versions.write(docs_dir)

    _create_root_redirect(versions, docs_dir)


if __name__ == "__main__":
    main()
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top