Skip to content

Commit eab79a6

Browse files
committed
Apply cookiecutter
1 parent 5677978 commit eab79a6

File tree

15 files changed

+178
-31
lines changed

15 files changed

+178
-31
lines changed

.ci/scripts/calc_constraints.py

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

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: "ubuntu-latest"
1010
steps:
11-
- uses: "actions/checkout@v4"
11+
- uses: "actions/checkout@v5"
1212
- uses: "actions/cache@v4"
1313
with:
1414
path: "~/.cache/pip"

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: "Checkout repository"
21-
uses: "actions/checkout@v4"
21+
uses: "actions/checkout@v5"
2222
- name: "Initialize CodeQL"
2323
uses: "github/codeql-action/init@v3"
2424
with:

.github/workflows/collect_changes.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
collect-changes:
99
runs-on: "ubuntu-latest"
1010
steps:
11-
- uses: "actions/checkout@v4"
11+
- uses: "actions/checkout@v5"
1212
with:
1313
ref: "main"
1414
fetch-depth: 0
@@ -25,10 +25,18 @@ jobs:
2525
python3 .ci/scripts/collect_changes.py
2626
- name: "Create Pull Request"
2727
uses: "peter-evans/create-pull-request@v7"
28+
id: "create_pr"
2829
with:
2930
token: "${{ secrets.RELEASE_TOKEN }}"
3031
title: "Update Changelog"
3132
body: ""
3233
branch: "update_changes"
3334
delete-branch: true
35+
- name: "Mark PR automerge"
36+
run: |
37+
gh pr merge --rebase --auto "${{ steps.create_pr.outputs.pull-request-number }}"
38+
if: "steps.create_pr.outputs.pull-request-number"
39+
env:
40+
GH_TOKEN: "${{ secrets.RELEASE_TOKEN }}"
41+
continue-on-error: true
3442
...

.github/workflows/cookiecutter.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
name: "Update CI from cookiecutter"
33
on:
44
workflow_dispatch:
5+
schedule:
6+
- cron: "30 14 * * 0"
57

68
defaults:
79
run:
@@ -11,11 +13,11 @@ jobs:
1113
update-ci:
1214
runs-on: "ubuntu-latest"
1315
steps:
14-
- uses: "actions/checkout@v4"
16+
- uses: "actions/checkout@v5"
1517
with:
1618
repository: "pulp/pulp-cli"
1719
path: "pulp-cli"
18-
- uses: "actions/checkout@v4"
20+
- uses: "actions/checkout@v5"
1921
with:
2022
token: "${{ secrets.RELEASE_TOKEN }}"
2123
path: "pulp-cli-ostree"

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- "3.11"
1515
- "3.13"
1616
steps:
17-
- uses: "actions/checkout@v4"
17+
- uses: "actions/checkout@v5"
1818
- uses: "actions/cache@v4"
1919
with:
2020
path: "~/.cache/pip"
@@ -23,7 +23,7 @@ jobs:
2323
${{ runner.os }}-pip-
2424
2525
- name: "Download wheels"
26-
uses: "actions/download-artifact@v4"
26+
uses: "actions/download-artifact@v5"
2727
with:
2828
name: "pulp_cli_packages"
2929
- name: "Set up Python"

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
check-commits:
2727
runs-on: "ubuntu-latest"
2828
steps:
29-
- uses: "actions/checkout@v4"
29+
- uses: "actions/checkout@v5"
3030
with:
3131
fetch-depth: 0
3232
- name: "Set up Python"

.github/workflows/pr_checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
permissions:
2020
pull-requests: "write"
2121
steps:
22-
- uses: "actions/checkout@v4"
22+
- uses: "actions/checkout@v5"
2323
with:
2424
fetch-depth: 0
2525
- uses: "actions/setup-python@v5"

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
needs: "build"
1515
runs-on: "ubuntu-latest"
1616
steps:
17-
- uses: "actions/checkout@v4"
17+
- uses: "actions/checkout@v5"
1818
- name: "Download wheels"
19-
uses: "actions/download-artifact@v4"
19+
uses: "actions/download-artifact@v5"
2020
with:
2121
name: "pulp_cli_packages"
2222
- name: "Set up Python"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: "Release"
1010
runs-on: "ubuntu-latest"
1111
steps:
12-
- uses: "actions/checkout@v4"
12+
- uses: "actions/checkout@v5"
1313
with:
1414
token: "${{ secrets.RELEASE_TOKEN }}"
1515
- name: "Set up Python"

0 commit comments

Comments
 (0)