Skip to content

Commit d75ecde

Browse files
committed
Update from cookiecutter
1 parent e04a5de commit d75ecde

26 files changed

Lines changed: 285 additions & 328 deletions

.ci/gen_certs.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# ///
77

88
import argparse
9-
import os
109
import sys
10+
from pathlib import Path
1111

1212
import trustme
1313

@@ -17,43 +17,41 @@ def main() -> None:
1717
parser.add_argument(
1818
"-d",
1919
"--dir",
20-
default=os.getcwd(),
20+
default=".",
2121
help="Directory where certificates and keys are written to. Defaults to cwd.",
2222
)
2323

2424
args = parser.parse_args(sys.argv[1:])
25-
cert_dir = args.dir
25+
cert_dir = Path(args.dir)
2626

27-
if not os.path.isdir(cert_dir):
27+
if not cert_dir.is_dir():
2828
raise ValueError(f"--dir={cert_dir} is not a directory")
2929

3030
key_type = trustme.KeyType["ECDSA"]
3131

3232
# Generate the CA certificate
3333
ca = trustme.CA(key_type=key_type)
3434
# Write the certificate the client should trust
35-
ca_cert_path = os.path.join(cert_dir, "ca.pem")
35+
ca_cert_path = cert_dir / "ca.pem"
3636
ca.cert_pem.write_to_path(path=ca_cert_path)
3737

3838
# Generate the server certificate
3939
server_cert = ca.issue_cert("localhost", "127.0.0.1", "::1", key_type=key_type)
4040
# Write the certificate and private key the server should use
41-
server_key_path = os.path.join(cert_dir, "server.key")
42-
server_cert_path = os.path.join(cert_dir, "server.pem")
41+
server_key_path = cert_dir / "server.key"
42+
server_cert_path = cert_dir / "server.pem"
4343
server_cert.private_key_pem.write_to_path(path=server_key_path)
44-
with open(server_cert_path, mode="w") as f:
45-
f.truncate()
44+
server_cert_path.write_text("")
4645
for blob in server_cert.cert_chain_pems:
4746
blob.write_to_path(path=server_cert_path, append=True)
4847

4948
# Generate the client certificate
5049
client_cert = ca.issue_cert("admin@example.com", common_name="admin", key_type=key_type)
5150
# Write the certificate and private key the client should use
52-
client_key_path = os.path.join(cert_dir, "client.key")
53-
client_cert_path = os.path.join(cert_dir, "client.pem")
51+
client_key_path = cert_dir / "client.key"
52+
client_cert_path = cert_dir / "client.pem"
5453
client_cert.private_key_pem.write_to_path(path=client_key_path)
55-
with open(client_cert_path, mode="w") as f:
56-
f.truncate()
54+
client_cert_path.write_text("")
5755
for blob in client_cert.cert_chain_pems:
5856
blob.write_to_path(path=client_cert_path, append=True)
5957

.ci/run_container.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ else
6969
fi
7070
export PULP_CONTENT_ORIGIN
7171

72+
PULP_SECRET_KEY="$(python3 -c "import secrets; print(secrets.token_urlsafe(50))")"
73+
export PULP_SECRET_KEY
74+
7275
"${CONTAINER_RUNTIME}" \
7376
run ${RM:+--rm} \
7477
--env S6_KEEP_ENV=1 \
@@ -79,6 +82,7 @@ export PULP_CONTENT_ORIGIN
7982
${PULP_DOMAIN_ENABLED:+--env PULP_DOMAIN_ENABLED} \
8083
${PULP_ENABLED_PLUGINS:+--env PULP_ENABLED_PLUGINS} \
8184
--env PULP_CONTENT_ORIGIN \
85+
--env PULP_SECRET_KEY \
8286
--detach \
8387
--name "pulp-ephemeral" \
8488
--volume "${PULP_CLI_TEST_TMPDIR}/settings:/etc/pulp${SELINUX:+:Z}" \

.ci/scripts/calc_constraints.py

Lines changed: 0 additions & 119 deletions
This file was deleted.

.ci/scripts/check_click_for_mypy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# "packaging>=25.0,<25.1",
66
# ]
77
# ///
8-
8+
import sys
99
from importlib import metadata
1010

1111
from packaging.version import Version
@@ -15,4 +15,4 @@
1515
if click_version < Version("8.1.1"):
1616
print("🚧 Linting with mypy is currently only supported with click>=8.1.1. 🚧")
1717
print("🔧 Please run `pip install click>=8.1.1` first. 🔨")
18-
exit(1)
18+
sys.exit(1)

.ci/scripts/collect_changes.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/bin/env python3
22
# /// script
3-
# requires-python = ">=3.11"
3+
# requires-python = ">=3.13"
44
# dependencies = [
55
# "gitpython>=3.1.46,<3.2.0",
66
# "packaging>=25.0,<25.1",
77
# ]
88
# ///
99

1010
import itertools
11-
import os
1211
import re
12+
import typing as t
13+
from pathlib import Path
1314

1415
import tomllib
1516
from git import GitCommandError, Repo
17+
from packaging.version import Version
1618
from packaging.version import parse as parse_version
1719

1820
# Read Towncrier settings
19-
with open("pyproject.toml", "rb") as fp:
21+
with Path("pyproject.toml").open("rb") as fp:
2022
tc_settings = tomllib.load(fp)["tool"]["towncrier"]
2123

2224
CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
@@ -51,37 +53,36 @@
5153
)
5254

5355

54-
def get_changelog(repo, branch):
56+
def get_changelog(repo: Repo, branch: str) -> str:
5557
branch_tc_settings = tomllib.loads(repo.git.show(f"{branch}:pyproject.toml"))["tool"][
5658
"towncrier"
5759
]
5860
branch_changelog_file = branch_tc_settings.get("filename", "NEWS.rst")
5961
return repo.git.show(f"{branch}:{branch_changelog_file}") + "\n"
6062

6163

62-
def _tokenize_changes(splits):
64+
def _tokenize_changes(splits: list[str]) -> t.Iterator[list[Version | str]]:
6365
assert len(splits) % 3 == 0
6466
for i in range(len(splits) // 3):
6567
title = splits[3 * i]
6668
version = parse_version(splits[3 * i + 1])
6769
yield [version, title + splits[3 * i + 2]]
6870

6971

70-
def split_changelog(changelog):
72+
def split_changelog(changelog: str) -> tuple[str, list[list[Version | str]]]:
7173
preamble, rest = changelog.split(START_STRING, maxsplit=1)
7274
split_rest = re.split(TITLE_REGEX, rest)
7375
return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:]))
7476

7577

76-
def main():
77-
repo = Repo(os.getcwd())
78+
def main() -> None:
79+
repo = Repo(Path.cwd())
7880
remote = repo.remotes[0]
7981
branches = [ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)]
8082
branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True)
8183
branches = [ref.name for ref in branches]
8284

83-
with open(CHANGELOG_FILE, "r") as f:
84-
main_changelog = f.read()
85+
main_changelog = Path(CHANGELOG_FILE).read_text()
8586
preamble, main_changes = split_changelog(main_changelog)
8687
old_length = len(main_changes)
8788

@@ -92,7 +93,7 @@ def main():
9293
except GitCommandError:
9394
print("No changelog found on this branch.")
9495
continue
95-
dummy, changes = split_changelog(changelog)
96+
_dummy, changes = split_changelog(changelog)
9697
new_changes = sorted(main_changes + changes, key=lambda x: x[0], reverse=True)
9798
# Now remove duplicates (retain the first one)
9899
main_changes = [new_changes[0]]
@@ -103,10 +104,9 @@ def main():
103104
new_length = len(main_changes)
104105
if old_length < new_length:
105106
print(f"{new_length - old_length} new versions have been added.")
106-
with open(CHANGELOG_FILE, "w") as fp:
107+
with Path(CHANGELOG_FILE).open("w") as fp:
107108
fp.write(preamble)
108-
for change in main_changes:
109-
fp.write(change[1])
109+
fp.writelines(change[1] for change in main_changes)
110110

111111
repo.git.commit("-m", "Update Changelog", CHANGELOG_FILE)
112112

.ci/scripts/pr_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def main():
2020
assert len(sys.argv) == 3
2121

22-
with open("pyproject.toml", "rb") as fp:
22+
with Path("pyproject.toml").open("rb") as fp:
2323
PYPROJECT_TOML = tomllib.load(fp)
2424
BLOCKING_REGEX = re.compile(r"DRAFT|WIP|NO\s*MERGE|DO\s*NOT\s*MERGE|EXPERIMENT")
2525
ISSUE_REGEX = re.compile(r"(?:fixes|closes)[\s:]+#(\d+)")

.ci/scripts/validate_commit_message.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
from pathlib import Path
1313

1414
import tomllib
15-
from github import Github
1615

17-
with open("pyproject.toml", "rb") as fp:
16+
with Path("pyproject.toml").open("rb") as fp:
1817
PYPROJECT_TOML = tomllib.load(fp)
1918
KEYWORDS = ["fixes", "closes"]
2019
BLOCKING_REGEX = [
@@ -33,22 +32,24 @@
3332
if NOISSUE_MARKER in message:
3433
sys.exit("Do not add '[noissue]' in the commit message.")
3534

36-
if any((re.match(pattern, message) for pattern in BLOCKING_REGEX)):
35+
if any(re.match(pattern, message) for pattern in BLOCKING_REGEX):
3736
sys.exit("This PR is not ready for consumption.")
3837

39-
g = Github(os.environ.get("GITHUB_TOKEN"))
40-
repo = g.get_repo("pulp/pulp-cli")
4138

39+
def check_status(issue: str) -> None:
40+
from github import Github
41+
42+
g = Github(os.environ.get("GITHUB_TOKEN"))
43+
repo = g.get_repo("pulp/pulp-cli")
4244

43-
def check_status(issue):
4445
gi = repo.get_issue(int(issue))
4546
if gi.pull_request:
4647
sys.exit(f"Error: issue #{issue} is a pull request.")
4748
if gi.closed_at:
4849
sys.exit(f"Error: issue #{issue} is closed.")
4950

5051

51-
def check_changelog(issue):
52+
def check_changelog(issue: str) -> None:
5253
matches = list(Path("CHANGES").rglob(f"{issue}.*"))
5354

5455
if len(matches) < 1:
@@ -58,7 +59,7 @@ def check_changelog(issue):
5859
sys.exit(f"Invalid extension for changelog entry '{match}'.")
5960

6061

61-
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
62+
print(f"Checking commit message for {sha[0:7]}.")
6263

6364
# validate the issue attached to the commit
6465
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
@@ -72,4 +73,4 @@ def check_changelog(issue):
7273
check_status(issue)
7374
check_changelog(issue)
7475

75-
print("Commit message for {sha} passed.".format(sha=sha[0:7]))
76+
print(f"Commit message for {sha[0:7]} passed.")

0 commit comments

Comments
 (0)