Skip to content

Commit b31ea2e

Browse files
committed
Add metadata to ci scripts
1 parent d14c23e commit b31ea2e

15 files changed

+217
-7
lines changed

.ci/gen_certs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# /// script
2+
# requires-python = ">=3.10"
3+
# dependencies = [
4+
# "trustme>=1.2.1,<1.3.0",
5+
# ]
6+
# ///
7+
18
import argparse
29
import os
310
import sys

.ci/scripts/calc_constraints.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/bin/python3
2+
# /// script
3+
# requires-python = ">=3.10"
4+
# dependencies = [
5+
# "packaging>=25.0,<25.1",
6+
# "tomli>=2.3.0,<2.4.0;python_version<'3.11'",
7+
# ]
8+
# ///
29

310
import argparse
411
import fileinput

.ci/scripts/check_click_for_mypy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# dependencies = [
5+
# "packaging>=25.0,<25.1",
6+
# ]
7+
# ///
28

39
from importlib import metadata
410

.ci/scripts/collect_changes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# dependencies = [
5+
# "gitpython>=3.1.46,<3.2.0",
6+
# "packaging>=25.0,<25.1",
7+
# ]
8+
# ///
29

310
import itertools
411
import os

.ci/scripts/pr_labels.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# dependencies = [
5+
# "gitpython>=3.1.46,<3.2.0",
6+
# ]
7+
# ///
28

39
# This script is running with elevated privileges from the main branch against pull requests.
410

.ci/scripts/validate_commit_message.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# /// script
2+
# requires-python = ">=3.11"
3+
# dependencies = [
4+
# "gitpython>=3.1.46,<3.2.0",
5+
# ]
6+
# ///
7+
18
import os
29
import re
310
import subprocess

cookiecutter/apply_templates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# dependencies = [
5+
# "click>=8.3.1,<8.4",
6+
# "cookiecutter>=2.6.0,<2.7",
7+
# "pyyaml>=6.0.3,<6.1",
8+
# "tomlkit>=0.13.3,<0.14",
9+
# ]
10+
# ///
211

3-
# This script requires click, cookiecutter, tomlkit and pyyaml
412

513
import os
614
from pathlib import Path
15+
import tomllib
716

817
import click
9-
import tomllib
1018
import yaml
1119

1220
from cookiecutter.main import cookiecutter

cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/gen_certs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# /// script
2+
# requires-python = ">=3.10"
3+
# dependencies = [
4+
# "trustme>=1.2.1,<1.3.0",
5+
# ]
6+
# ///
7+
18
import argparse
29
import os
310
import sys
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/python3
2+
# /// script
3+
# requires-python = ">=3.10"
4+
# dependencies = [
5+
# "packaging>=25.0,<25.1",
6+
# "tomli>=2.3.0,<2.4.0;python_version<'3.11'",
7+
# ]
8+
# ///
9+
10+
import argparse
11+
import fileinput
12+
import sys
13+
14+
from packaging.requirements import Requirement
15+
from packaging.version import Version
16+
17+
try:
18+
import tomllib
19+
except ImportError:
20+
import tomli as tomllib
21+
22+
23+
def split_comment(line):
24+
split_line = line.split("#", maxsplit=1)
25+
try:
26+
comment = " # " + split_line[1].strip()
27+
except IndexError:
28+
comment = ""
29+
return split_line[0].strip(), comment
30+
31+
32+
def to_upper_bound(req):
33+
try:
34+
requirement = Requirement(req)
35+
except ValueError:
36+
return f"# UNPARSABLE: {req}"
37+
else:
38+
for spec in requirement.specifier:
39+
if spec.operator == "~=":
40+
return f"# NO BETTER CONSTRAINT: {req}"
41+
if spec.operator == "<=":
42+
operator = "=="
43+
max_version = spec.version
44+
return f"{requirement.name}{operator}{max_version}"
45+
if spec.operator == "<":
46+
operator = "~="
47+
version = Version(spec.version)
48+
if version.micro != 0:
49+
max_version = f"{version.major}.{version.minor}.{version.micro - 1}"
50+
elif version.minor != 0:
51+
max_version = f"{version.major}.{version.minor - 1}"
52+
elif version.major != 0:
53+
max_version = f"{version.major - 1}.0"
54+
else:
55+
return f"# NO BETTER CONSTRAINT: {req}"
56+
return f"{requirement.name}{operator}{max_version}"
57+
return f"# NO UPPER BOUND: {req}"
58+
59+
60+
def to_lower_bound(req):
61+
try:
62+
requirement = Requirement(req)
63+
except ValueError:
64+
return f"# UNPARSABLE: {req}"
65+
else:
66+
for spec in requirement.specifier:
67+
if spec.operator == ">=":
68+
if requirement.name == "pulpcore":
69+
# Currently an exception to allow for pulpcore bugfix releases.
70+
# TODO Semver libraries should be allowed too.
71+
operator = "~="
72+
else:
73+
operator = "=="
74+
min_version = spec.version
75+
return f"{requirement.name}{operator}{min_version}"
76+
return f"# NO LOWER BOUND: {req}"
77+
78+
79+
def main():
80+
"""Calculate constraints for the lower bound of dependencies where possible."""
81+
parser = argparse.ArgumentParser(
82+
prog=sys.argv[0],
83+
description="Calculate constraints for the lower or upper bound of dependencies where "
84+
"possible.",
85+
)
86+
parser.add_argument("-u", "--upper", action="store_true")
87+
parser.add_argument("filename", nargs="*")
88+
args = parser.parse_args()
89+
90+
modifier = to_upper_bound if args.upper else to_lower_bound
91+
92+
req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")]
93+
pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")]
94+
if req_files:
95+
with fileinput.input(files=req_files) as req_file:
96+
for line in req_file:
97+
if line.strip().startswith("#"):
98+
# Shortcut comment only lines
99+
print(line.strip())
100+
else:
101+
req, comment = split_comment(line)
102+
new_req = modifier(req)
103+
print(new_req + comment)
104+
for filename in pyp_files:
105+
with open(filename, "rb") as fp:
106+
pyproject = tomllib.load(fp)
107+
for req in pyproject["project"]["dependencies"]:
108+
new_req = modifier(req)
109+
print(new_req)
110+
optional_dependencies = pyproject["project"].get("optional-dependencies")
111+
if optional_dependencies:
112+
for opt in optional_dependencies.values():
113+
for req in opt:
114+
new_req = modifier(req)
115+
print(new_req)
116+
117+
118+
if __name__ == "__main__":
119+
main()

cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/check_cli_dependencies.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#!/bin/env python3
2-
import tomllib
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# dependencies = [
5+
# "packaging>=25.0,<25.1",
6+
# ]
7+
# ///
8+
39
import typing as t
410
from pathlib import Path
511

12+
import tomllib
613
from packaging.requirements import Requirement
714

815
GLUE_DIR = "pulp-glue{{ cookiecutter.__app_label_suffix }}"

0 commit comments

Comments
 (0)