-
Notifications
You must be signed in to change notification settings - Fork 111
/
custom-versionit-format.py
62 lines (55 loc) · 1.98 KB
/
custom-versionit-format.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from parver import Version
import versioningit
from typing import Any, Dict, Union
import pathlib
import versioningit.basics
import versioningit.git
import os
# Take in <version> and <string> as input
# If local version identifier doesn't exist, append +<string> to <version>
# Example: 15.0.0rc1 and dsym as input -> 15.0.0rc1+dsym
# If it does exist, append <version> with .<string>
# Then output new version as str
def append_to_local(version_str: str, value: str) -> str:
version = Version.parse(version_str, strict=True)
if version.local == None:
new_local = value
else:
new_local = f"{version.local}.{value}"
version = version.replace(local=new_local)
return version.__str__()
def my_vcs(
project_dir: Union[str, pathlib.Path],
params: Dict[str, Any]
) -> versioningit.VCSDescription:
vcs_description = versioningit.git.describe_git(
project_dir=project_dir,
params=params
)
if vcs_description.state == "exact":
# We don't want the format step to be skipped
# Workaround: https://github.com/jwodder/versioningit/issues/42#issuecomment-1235573432
vcs_description.state = "exact_"
return vcs_description
def my_format(
description: versioningit.VCSDescription,
base_version: str,
next_version: str,
params: Dict[str, Any]
) -> str:
# Even if the repository state matches a tag, we always need to label the version if it's unoptimized or includes
# dsym for macOS
if description.state != "exact_":
version_str = versioningit.basics.basic_format(
description=description,
base_version=base_version,
next_version=next_version,
params=params
)
else:
version_str = base_version
if os.getenv("UNOPTIMIZED"):
version_str = append_to_local(version_str, "unoptimized")
if os.getenv("INCLUDE_DSYM"):
version_str = append_to_local(version_str, "dsym")
return version_str