-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathcustom-versionit-format.py
More file actions
98 lines (85 loc) · 3.31 KB
/
Copy pathcustom-versionit-format.py
File metadata and controls
98 lines (85 loc) · 3.31 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from parver import Version
import versioningit
from typing import Any, Dict, Union
import pathlib
import re
import versioningit.basics
import versioningit.git
import versioningit.next_version
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 is_central_branch(branch: str | None) -> bool:
return type(branch) == str and re.match(r'^(dev|stage|master).*', branch)
building_on_central_branch = False
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
)
print("Branch:", vcs_description.branch)
if is_central_branch(vcs_description.branch):
print("We are on a central branch")
# Need to set flag to override latest tag with release version in tag2version for central branches
global building_on_central_branch
building_on_central_branch = True
# Skip the format step. (i.e wheel should have the release version)
vcs_description.state = "exact"
elif vcs_description.state == "exact":
print("We are on a feature branch")
# We don't want the format step to be skipped (we always want the build to have the latest tag in the version)
# Workaround: https://github.com/jwodder/versioningit/issues/42#issuecomment-1235573432
vcs_description.state = "exact_"
return vcs_description
def my_tag2version(
tag: str,
params: Dict[str, Any]
):
if building_on_central_branch:
print("my_next_version: we are on a central branch")
version_with_dev_number = Version.parse(tag, strict=True)
# Get release version
version = version_with_dev_number.replace(dev=None)
version = version.__str__()
else:
version = versioningit.basics.basic_tag2version(tag=tag, params=params)
print(f"tag2version: {version}")
return version
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")
if os.getenv("SANITIZER"):
version_str = append_to_local(version_str, "sanitizer")
return version_str