Apply black to version_helper

This commit is contained in:
Mikhail f. Shiryaev 2022-01-27 13:21:57 +01:00
parent e6a7ef77ac
commit cac6f1cd69
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4

View File

@ -9,7 +9,7 @@ CHANGELOG_PATH = "debian/changelog"
CONTRIBUTORS_SCRIPT_DIR = "src/Storages/System/"
class ClickHouseVersion():
class ClickHouseVersion:
def __init__(self, major, minor, patch, tweak, revision):
self.major = major
self.minor = minor
@ -18,42 +18,28 @@ class ClickHouseVersion():
self.revision = revision
def minor_update(self):
return ClickHouseVersion(
self.major,
self.minor + 1,
1,
1,
self.revision + 1)
return ClickHouseVersion(self.major, self.minor + 1, 1, 1, self.revision + 1)
def patch_update(self):
return ClickHouseVersion(
self.major,
self.minor,
self.patch + 1,
1,
self.revision)
self.major, self.minor, self.patch + 1, 1, self.revision
)
def tweak_update(self):
return ClickHouseVersion(
self.major,
self.minor,
self.patch,
self.tweak + 1,
self.revision)
self.major, self.minor, self.patch, self.tweak + 1, self.revision
)
def get_version_string(self):
return '.'.join([
str(self.major),
str(self.minor),
str(self.patch),
str(self.tweak)
])
return ".".join(
[str(self.major), str(self.minor), str(self.patch), str(self.tweak)]
)
def as_tuple(self):
return (self.major, self.minor, self.patch, self.tweak)
class VersionType():
class VersionType:
STABLE = "stable"
TESTING = "testing"
@ -63,19 +49,22 @@ def build_version_description(version, version_type):
def _get_version_from_line(line):
_, ver_with_bracket = line.strip().split(' ')
_, ver_with_bracket = line.strip().split(" ")
return ver_with_bracket[:-1]
def get_tweak_from_git_describe(repo_path):
# something like v21.12.1.8816-testing-358-g81942b8128
# or v21.11.4.14-stable-31-gd6aab025e0
output = subprocess.check_output(f"cd {repo_path} && git describe --long", shell=True).decode('utf-8')
commits_number = int(output.split('-')[-2])
output = subprocess.check_output(
f"cd {repo_path} && git describe --long", shell=True
).decode("utf-8")
commits_number = int(output.split("-")[-2])
# for testing releases we have to also add fourth number of
# the previous tag
if 'testing' in output:
previous_version = output.split('-')[0]
previous_version_commits = int(previous_version.split('.')[3])
if "testing" in output:
previous_version = output.split("-")[0]
previous_version_commits = int(previous_version.split(".")[3])
commits_number += previous_version_commits
return commits_number
@ -88,7 +77,7 @@ def get_version_from_repo(repo_path):
patch = 0
tweak = get_tweak_from_git_describe(repo_path)
version_revision = 0
with open(path_to_file, 'r') as ver_file:
with open(path_to_file, "r") as ver_file:
for line in ver_file:
if "VERSION_MAJOR" in line and "math" not in line and "SET" in line:
major = _get_version_from_line(line)
@ -133,19 +122,28 @@ def _update_changelog(repo_path, version):
version_str=version.get_version_string(),
date=datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S") + " +0300",
in_path=os.path.join(repo_path, CHANGELOG_IN_PATH),
changelog_path=os.path.join(repo_path, CHANGELOG_PATH)
changelog_path=os.path.join(repo_path, CHANGELOG_PATH),
)
subprocess.check_call(cmd, shell=True)
def _update_contributors(repo_path):
cmd = "cd {} && ./StorageSystemContributors.sh".format(os.path.join(repo_path, CONTRIBUTORS_SCRIPT_DIR))
cmd = "cd {} && ./StorageSystemContributors.sh".format(
os.path.join(repo_path, CONTRIBUTORS_SCRIPT_DIR)
)
subprocess.check_call(cmd, shell=True)
def _update_dockerfile(repo_path, version):
version_str_for_docker = '.'.join([str(version.major), str(version.minor), str(version.patch), '*'])
cmd = "ls -1 {path}/docker/*/Dockerfile | xargs sed -i -r -e 's/ARG version=.+$/ARG version='{ver}'/'".format(path=repo_path, ver=version_str_for_docker)
version_str_for_docker = ".".join(
[str(version.major), str(version.minor), str(version.patch), "*"]
)
cmd = "ls -1 {path}/docker/*/Dockerfile | xargs sed -i -r -e 's/ARG version=.+$/ARG version='{ver}'/'".format(
path=repo_path, ver=version_str_for_docker
)
subprocess.check_call(cmd, shell=True)
def update_version_local(repo_path, sha, version, version_type="testing"):
_update_contributors(repo_path)
_update_cmake_version(repo_path, version, sha, version_type)