2014-11-16 17:08:42 +00:00
|
|
|
# This file is dual licensed under the terms of the Apache License, Version
|
|
|
|
|
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
|
|
|
|
# for complete details.
|
2014-07-06 09:51:26 +00:00
|
|
|
|
2023-04-26 13:21:39 +00:00
|
|
|
import pathlib
|
|
|
|
|
import re
|
2017-05-20 21:37:40 +00:00
|
|
|
import subprocess
|
2019-05-25 15:11:49 +00:00
|
|
|
|
2017-05-20 21:37:40 +00:00
|
|
|
import click
|
2023-09-19 16:36:14 +00:00
|
|
|
import tomllib
|
2023-12-12 14:09:51 +00:00
|
|
|
from packaging.version import Version
|
2020-03-21 19:14:46 +00:00
|
|
|
|
2014-02-20 00:44:06 +00:00
|
|
|
|
2023-01-02 00:38:57 +00:00
|
|
|
def run(*args: str) -> None:
|
2023-01-19 21:36:01 +00:00
|
|
|
print(f"[running] {list(args)}")
|
2023-01-02 00:38:57 +00:00
|
|
|
subprocess.check_call(list(args))
|
2017-05-20 21:37:40 +00:00
|
|
|
|
|
|
|
|
|
2023-04-26 13:21:39 +00:00
|
|
|
@click.group()
|
|
|
|
|
def cli():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
2023-12-12 14:09:51 +00:00
|
|
|
def release() -> None:
|
2023-09-19 16:36:14 +00:00
|
|
|
base_dir = pathlib.Path(__file__).parent
|
|
|
|
|
with (base_dir / "pyproject.toml").open("rb") as f:
|
|
|
|
|
pyproject = tomllib.load(f)
|
2023-12-12 14:09:51 +00:00
|
|
|
version = pyproject["project"]["version"]
|
2023-09-19 16:36:14 +00:00
|
|
|
|
2023-12-12 14:09:51 +00:00
|
|
|
if Version(version).is_prerelease:
|
2023-09-19 16:36:14 +00:00
|
|
|
raise RuntimeError(
|
2023-12-12 14:09:51 +00:00
|
|
|
f"Can't release, pyproject.toml version is pre-release: {version}"
|
2023-09-19 16:36:14 +00:00
|
|
|
)
|
|
|
|
|
|
2021-09-30 00:38:28 +00:00
|
|
|
# Tag and push the tag (this will trigger the wheel builder in Actions)
|
2023-01-02 05:27:13 +00:00
|
|
|
run("git", "tag", "-s", version, "-m", f"{version} release")
|
2023-11-28 17:34:30 +00:00
|
|
|
run("git", "push", "--tags", "git@github.com:pyca/cryptography.git")
|
2014-01-06 20:04:53 +00:00
|
|
|
|
2017-05-20 21:37:40 +00:00
|
|
|
|
2024-01-28 19:29:34 +00:00
|
|
|
def replace_pattern(p: pathlib.Path, pattern: str, replacement: str) -> None:
|
2023-10-09 14:21:14 +00:00
|
|
|
content = p.read_text()
|
2023-04-26 13:21:39 +00:00
|
|
|
match = re.search(pattern, content, re.MULTILINE)
|
|
|
|
|
assert match is not None
|
|
|
|
|
|
|
|
|
|
start, end = match.span()
|
2024-01-28 19:29:34 +00:00
|
|
|
new_content = content[:start] + replacement + content[end:]
|
2023-10-09 14:21:14 +00:00
|
|
|
p.write_text(new_content)
|
2023-04-26 13:21:39 +00:00
|
|
|
|
|
|
|
|
|
2024-01-28 19:29:34 +00:00
|
|
|
def replace_version(
|
|
|
|
|
p: pathlib.Path, variable_name: str, new_version: str
|
|
|
|
|
) -> None:
|
|
|
|
|
replace_pattern(
|
|
|
|
|
p, rf"^{variable_name}\s*=\s*.*$", f'{variable_name} = "{new_version}"'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2023-04-26 13:21:39 +00:00
|
|
|
@cli.command()
|
|
|
|
|
@click.argument("new_version")
|
|
|
|
|
def bump_version(new_version: str) -> None:
|
|
|
|
|
base_dir = pathlib.Path(__file__).parent
|
|
|
|
|
|
|
|
|
|
replace_version(base_dir / "pyproject.toml", "version", new_version)
|
|
|
|
|
replace_version(
|
|
|
|
|
base_dir / "src/cryptography/__about__.py", "__version__", new_version
|
|
|
|
|
)
|
2023-05-02 14:09:19 +00:00
|
|
|
replace_version(
|
|
|
|
|
base_dir / "vectors/pyproject.toml",
|
|
|
|
|
"version",
|
|
|
|
|
new_version,
|
|
|
|
|
)
|
2023-04-26 13:21:39 +00:00
|
|
|
replace_version(
|
|
|
|
|
base_dir / "vectors/cryptography_vectors/__about__.py",
|
|
|
|
|
"__version__",
|
|
|
|
|
new_version,
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-28 19:29:34 +00:00
|
|
|
if Version(new_version).is_prerelease:
|
|
|
|
|
replace_pattern(
|
|
|
|
|
base_dir / "pyproject.toml",
|
|
|
|
|
r'"cryptography_vectors(==.*?)?"',
|
|
|
|
|
'"cryptography_vectors"',
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
replace_pattern(
|
|
|
|
|
base_dir / "pyproject.toml",
|
|
|
|
|
r'"cryptography_vectors(==.*?)?"',
|
|
|
|
|
f'"cryptography_vectors=={new_version}"',
|
|
|
|
|
)
|
|
|
|
|
|
2023-04-26 13:21:39 +00:00
|
|
|
|
2017-05-20 21:37:40 +00:00
|
|
|
if __name__ == "__main__":
|
2023-04-26 13:21:39 +00:00
|
|
|
cli()
|