Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc] (WIP) Automatic release pipeline #1861

Closed
wants to merge 5 commits into from
Closed
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
60 changes: 53 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,67 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import re
from functools import partial
from pathlib import Path
from typing import Callable, Match, Tuple, Union


# -- Version forge -----------------------------------------------------------
# Note this section has some duplicate code which
# is directly copied from /misc.
def _semver_matcher() -> Callable:
"""Return a func performs regex matching for semantic versions.
The regex uses word_boundry and is sensitive to the changes
to the contents of the CMakeLists.txt file. The match should
have 3 matched groups:
1. `SET(TI_VERSION_MAJOR `
2. the corresponding version number
3. `)`
"""
return lambda s, w: re.search(rf"(\bSET\(TI_VERSION_{w} )(\d+)(\b\))", s)


def _intify_version(v: Match) -> int:
"""Convert matched group v to integer."""
return int(v.group(2))


def parse_semver(
cmakelist_path: str,
return_match_groups: bool = False
) -> Union[Tuple[int, int, int], Tuple[Match[str], Match[str], Match[str]]]:
"""Parse and return the major, minor and patch version numbers
(or matched groups) from CMakeLists.txt given CMAKELIST_PATH.
"""
with open(cmakelist_path, "r") as fp:
cmakelist = fp.read()
matcher = partial(_semver_matcher(), cmakelist)
major, minor, patch = map(matcher, ["MAJOR", "MINOR", "PATCH"])
if return_match_groups:
return major, minor, patch
return tuple(map(_intify_version, (major, minor, patch)))


# CMakeLists.txt is the only source of the truth when forging
# the version, this script always reads from it, parses the version
# and dump the version string to `version` file.
cmake_file = Path(__file__).resolve().parents[1].joinpath('CMakeLists.txt')
major, minor, patch = parse_semver(cmakelist_path=str(cmake_file))
version_file = Path(__file__).resolve().parent.joinpath("version")
taichi_version = f"{major}.{minor}.{patch}"
with version_file.open('w') as f:
f.write(f"{taichi_version}\n")
print('Building doc version', taichi_version)

# -- Project information -----------------------------------------------------

project = 'taichi'
copyright = '2020, Taichi Developers'
author = 'Taichi Developers'

version_fn = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'version')
with open(version_fn) as f:
taichi_version = f.readline().strip()
print('Building doc version', taichi_version)

# The short X.Y version
version = taichi_version
# The full version, including alpha/beta/rc tags
Expand Down
Loading