diff --git a/python-projector/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 b/python-projector/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 index 460f4fa..d30de77 100644 --- a/python-projector/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 +++ b/python-projector/deps/lock/aarch64-apple-darwin/.requirements.in.sha256 @@ -1 +1 @@ -6edde570198679e9302e2e78c037215131a507061766c547d19c5559ab8a7db5 requirements.in +3179ddf821eb9b1640acbfd5a43416596bf1ca019de276139e1760fbda7dd997 requirements.in diff --git a/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt b/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt index c410a4c..9987109 100644 --- a/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt +++ b/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt --python-platform aarch64-apple-darwin --python-version 3.13 +# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/aarch64-apple-darwin/requirements.txt --python-platform aarch64-apple-darwin --python-version 3.11 click==8.1.7 # via typer markdown-it-py==3.0.0 @@ -24,3 +24,5 @@ typer==0.12.5 # via -r requirements.in typing-extensions==4.12.2 # via typer +versioneer==0.29 + # via -r requirements.in diff --git a/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt b/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt index f0d69c8..20dc907 100644 --- a/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt +++ b/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.13 +# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/aarch64-apple-darwin/requirements_dev.txt --python-platform aarch64-apple-darwin --python-version 3.11 babel==2.15.0 # via mkdocs-material cairocffi==1.7.1 @@ -120,6 +120,7 @@ numpy==2.0.0 # via # contourpy # matplotlib + # pandas-stubs # types-seaborn packaging==24.1 # via @@ -198,6 +199,8 @@ tinycss2==1.3.0 # via # cairosvg # cssselect2 +tomli==2.2.1 + # via coverage tqdm==4.66.4 # via -r requirements.in typer==0.12.5 @@ -212,6 +215,8 @@ typing-extensions==4.12.2 # via typer urllib3==2.2.2 # via requests +versioneer==0.29 + # via -r requirements.in verspec==0.1.0 # via mike watchdog==4.0.1 diff --git a/python-projector/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 b/python-projector/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 index 460f4fa..d30de77 100644 --- a/python-projector/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 +++ b/python-projector/deps/lock/x86_64-apple-darwin/.requirements.in.sha256 @@ -1 +1 @@ -6edde570198679e9302e2e78c037215131a507061766c547d19c5559ab8a7db5 requirements.in +3179ddf821eb9b1640acbfd5a43416596bf1ca019de276139e1760fbda7dd997 requirements.in diff --git a/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt b/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt index 52a96f6..9633832 100644 --- a/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt +++ b/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt --python-platform x86_64-apple-darwin --python-version 3.13 +# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-apple-darwin/requirements.txt --python-platform x86_64-apple-darwin --python-version 3.11 click==8.1.7 # via typer markdown-it-py==3.0.0 @@ -24,3 +24,5 @@ typer==0.12.5 # via -r requirements.in typing-extensions==4.12.2 # via typer +versioneer==0.29 + # via -r requirements.in diff --git a/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt b/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt index 804e765..bbc57e5 100644 --- a/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt +++ b/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.13 +# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-apple-darwin/requirements_dev.txt --python-platform x86_64-apple-darwin --python-version 3.11 babel==2.15.0 # via mkdocs-material cairocffi==1.7.1 @@ -120,6 +120,7 @@ numpy==2.0.0 # via # contourpy # matplotlib + # pandas-stubs # types-seaborn packaging==24.1 # via @@ -198,6 +199,8 @@ tinycss2==1.3.0 # via # cairosvg # cssselect2 +tomli==2.2.1 + # via coverage tqdm==4.66.4 # via -r requirements.in typer==0.12.5 @@ -212,6 +215,8 @@ typing-extensions==4.12.2 # via typer urllib3==2.2.2 # via requests +versioneer==0.29 + # via -r requirements.in verspec==0.1.0 # via mike watchdog==4.0.1 diff --git a/python-projector/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 b/python-projector/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 index 460f4fa..d30de77 100644 --- a/python-projector/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 +++ b/python-projector/deps/lock/x86_64-manylinux_2_28/.requirements.in.sha256 @@ -1 +1 @@ -6edde570198679e9302e2e78c037215131a507061766c547d19c5559ab8a7db5 requirements.in +3179ddf821eb9b1640acbfd5a43416596bf1ca019de276139e1760fbda7dd997 requirements.in diff --git a/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt b/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt index b34be00..f199e4b 100644 --- a/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt +++ b/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt --python-platform x86_64-manylinux_2_28 --python-version 3.13 +# uv pip compile requirements.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-manylinux_2_28/requirements.txt --python-platform x86_64-manylinux_2_28 --python-version 3.11 click==8.1.7 # via typer markdown-it-py==3.0.0 @@ -24,3 +24,5 @@ typer==0.12.5 # via -r requirements.in typing-extensions==4.12.2 # via typer +versioneer==0.29 + # via -r requirements.in diff --git a/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt b/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt index b589600..acab618 100644 --- a/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt +++ b/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt --python-platform x86_64-manylinux_2_28 --python-version 3.13 +# uv pip compile requirements_dev.in -o /Users/kiyoon/project/workflows/python-projector/deps/lock/x86_64-manylinux_2_28/requirements_dev.txt --python-platform x86_64-manylinux_2_28 --python-version 3.11 babel==2.15.0 # via mkdocs-material cairocffi==1.7.1 @@ -120,6 +120,7 @@ numpy==2.0.0 # via # contourpy # matplotlib + # pandas-stubs # types-seaborn packaging==24.1 # via @@ -198,6 +199,8 @@ tinycss2==1.3.0 # via # cairosvg # cssselect2 +tomli==2.2.1 + # via coverage tqdm==4.66.4 # via -r requirements.in typer==0.12.5 @@ -212,6 +215,8 @@ typing-extensions==4.12.2 # via typer urllib3==2.2.2 # via requests +versioneer==0.29 + # via -r requirements.in verspec==0.1.0 # via mike watchdog==4.0.1 diff --git a/python-projector/deps/requirements.in b/python-projector/deps/requirements.in index 8cc23df..601b9a9 100644 --- a/python-projector/deps/requirements.in +++ b/python-projector/deps/requirements.in @@ -3,3 +3,4 @@ tqdm>=4.0.0 typer>=0.12.4 # python 3.11 `SomeType | None` support platformdirs packaging +versioneer>=0.29 diff --git a/python-projector/src/python_projector/cli/main.py b/python-projector/src/python_projector/cli/main.py index f783da0..caf1601 100644 --- a/python-projector/src/python_projector/cli/main.py +++ b/python-projector/src/python_projector/cli/main.py @@ -219,6 +219,57 @@ def run_doctest(project_dir: Annotated[Path | None, typer.Argument()] = None): sys.exit(1) +@app.command() +def get_versioneer_version( + project_dir: Annotated[Path | None, typer.Argument()] = None, + *, + chrome_compatible: Annotated[ + bool, typer.Option(help="Used for chrome extensions.") + ] = False, +): + """ + Similar to `versioneer.get_version()`, but with more options. + """ + import versioneer + + from python_projector.utils.files import find_pyproject_toml + from python_projector.utils.version import ( + versioneer_render_chrome_ext_compat_version, + ) + + pyproject_toml = find_pyproject_toml(project_dir) + with pyproject_toml.open("rb") as f: + pyproject = tomllib.load(f) + + if project_dir is None: + project_dir = pyproject_toml.parent + + try: + tag_prefix = pyproject["tool"]["versioneer"]["tag_prefix"] # usually "v" + except KeyError as e: + raise InvalidConfigError( + f"Missing key tool.versioneer.tag_prefix in {pyproject_toml}" + ) from e + + try: + style = pyproject["tool"]["versioneer"]["style"] # pep440 + except KeyError as e: + raise InvalidConfigError( + f"Missing key tool.versioneer.style in {pyproject_toml}" + ) from e + + pieces = versioneer.git_pieces_from_vcs( + tag_prefix=tag_prefix, root=project_dir, verbose=True + ) + + if chrome_compatible or style == "chrome-ext": + version = versioneer_render_chrome_ext_compat_version(pieces=pieces) + else: + version = versioneer.render(pieces=pieces, style=style)["version"] + + print(version) + + def main(): app() diff --git a/python-projector/src/python_projector/utils/version.py b/python-projector/src/python_projector/utils/version.py index 8b60f1e..6091789 100644 --- a/python-projector/src/python_projector/utils/version.py +++ b/python-projector/src/python_projector/utils/version.py @@ -1,3 +1,5 @@ +from typing import Any + from packaging.version import Version @@ -52,3 +54,30 @@ def min_version_requires_python(version_range: str): raise InvalidVersionRangeError(version_range) return str(min_version) + + +def versioneer_render_chrome_ext_compat_version(pieces: dict[str, Any]) -> str: + """ + Get versioneer version that is compatible for chrome extension. + + Note: + - Chrome extension requires version string to be in the format of 1~4 numbers. + - Thus, we remove git hash and dirty flag from the version string. (If dirty, add 1 to distance) + - We also change the format of distance from +DISTANCE to .DISTANCE + """ + if pieces["error"]: + raise ValueError("Unable to render version") + + if pieces["closest-tag"]: + closest_tag: str = pieces["closest-tag"] + else: + closest_tag = "0" + + version = closest_tag + if pieces["distance"] or pieces["dirty"]: + if pieces["dirty"]: + version += f".{pieces['distance'] + 1}" + else: + version += f".{pieces['distance']}" + + return version