Skip to content

Commit 1b32190

Browse files
authored
Merge pull request #241 from pulp/update_cookiecutter
Update cookiecutter
2 parents 859303b + 154f70c commit 1b32190

File tree

12 files changed

+202
-43
lines changed

12 files changed

+202
-43
lines changed

.ci/gen_certs.py

Lines changed: 7 additions & 1 deletion
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
@@ -6,7 +13,6 @@
613

714

815
def main() -> None:
9-
1016
parser = argparse.ArgumentParser(prog="gen_certs")
1117
parser.add_argument(
1218
"-d",

.ci/scripts/calc_constraints.py

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()

.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-deb"

.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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
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
512
import re
6-
import tomllib
713

14+
import tomllib
815
from git import GitCommandError, Repo
916
from packaging.version import parse as parse_version
1017

.ci/scripts/pr_labels.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
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

511
import re
612
import sys
7-
import tomllib
813
from pathlib import Path
914

15+
import tomllib
1016
from git import Repo
1117

1218

.ci/scripts/validate_commit_message.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
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
411
import sys
5-
import tomllib
612
from pathlib import Path
713

14+
import tomllib
815
from github import Github
916

1017
with open("pyproject.toml", "rb") as fp:

Makefile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,28 @@ LANGUAGES=de
33
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue-deb/pulp_glue/*))
44
CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*))
55

6+
.PHONY: info
67
info:
78
@echo Pulp glue
89
@echo plugins: $(GLUE_PLUGINS)
910
@echo Pulp CLI
1011
@echo plugins: $(CLI_PLUGINS)
1112

13+
.PHONY: build
1214
build:
1315
cd pulp-glue-deb; pyproject-build -n
1416
pyproject-build -n
1517

16-
black: format
17-
18+
.PHONY: format
1819
format:
19-
isort .
20-
cd pulp-glue-deb; isort .
21-
black .
20+
ruff format
21+
ruff check --fix
2222

23+
.PHONY: lint
2324
lint:
2425
find tests .ci -name '*.sh' -print0 | xargs -0 shellcheck -x
25-
isort -c --diff .
26-
cd pulp-glue-deb; isort -c --diff .
27-
black --diff --check .
28-
flake8
26+
ruff format --check --diff
27+
ruff check --diff
2928
.ci/scripts/check_cli_dependencies.py
3029
.ci/scripts/check_click_for_mypy.py
3130
MYPYPATH=pulp-glue-deb mypy
@@ -36,15 +35,19 @@ tests/cli.toml:
3635
cp $@.example $@
3736
@echo "In order to configure the tests to talk to your test server, you might need to edit $@ ."
3837

38+
.PHONY: test
3939
test: | tests/cli.toml
4040
python3 -m pytest -v tests pulp-glue-deb/tests
4141

42+
.PHONY: livetest
4243
livetest: | tests/cli.toml
4344
python3 -m pytest -v tests pulp-glue-deb/tests -m live
4445

46+
.PHONY: unittest
4547
unittest:
4648
python3 -m pytest -v tests pulp-glue-deb/tests -m "not live"
4749

50+
.PHONY: unittest_glue
4851
unittest_glue:
4952
python3 -m pytest -v pulp-glue-deb/tests -m "not live"
5053

@@ -56,6 +59,7 @@ pulpcore/cli/%/locale/messages.pot: pulpcore/cli/%/*.py
5659
xgettext -d $* -o $@ pulpcore/cli/$*/*.py
5760
sed -i 's/charset=CHARSET/charset=UTF-8/g' $@
5861

62+
.PHONY: extract_messages
5963
extract_messages: $(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue-deb/pulp_glue/$(GLUE_PLUGIN)/locale/messages.pot) $(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/messages.pot)
6064

6165
$(foreach LANGUAGE,$(LANGUAGES),pulp-glue-deb/pulp_glue/%/locale/$(LANGUAGE)/LC_MESSAGES/messages.po): pulp-glue-deb/pulp_glue/%/locale/messages.pot
@@ -71,6 +75,7 @@ $(foreach LANGUAGE,$(LANGUAGES),pulpcore/cli/%/locale/$(LANGUAGE)/LC_MESSAGES/me
7175
%.mo: %.po
7276
msgfmt -o $@ $<
7377

78+
.PHONY: compile_messages
7479
compile_messages: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue-deb/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo))
75-
.PHONY: build info black lint test
80+
7681
.PRECIOUS: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue-deb/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po))

lint_requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Lint requirements
2-
black==25.12.0
3-
flake8==7.3.0
4-
flake8-pyproject==1.2.4
5-
isort==7.0.0
2+
ruff==0.14.11
63
mypy==1.19.1
74
shellcheck-py==0.11.0.1
85

pulp-glue-deb/pyproject.toml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,38 @@ repository = "https://github.com/pulp/pulp-cli-deb"
3131
changelog = "https://github.com/pulp/pulp-cli-deb/blob/main/CHANGES.md"
3232

3333
[tool.setuptools.packages.find]
34+
# This section is managed by the cookiecutter templates.
3435
where = ["."]
3536
include = ["pulp_glue.*"]
3637
namespaces = true
3738

3839
[tool.setuptools.package-data]
40+
# This section is managed by the cookiecutter templates.
3941
"*" = ["py.typed", "locale/*/LC_MESSAGES/*.mo"]
4042

41-
[tool.black]
42-
line-length = 100
43-
44-
[tool.isort]
45-
profile = "black"
46-
line_length = 100
4743

4844
[tool.mypy]
45+
# This section is managed by the cookiecutter templates.
4946
strict = true
47+
warn_unused_ignores = false
5048
show_error_codes = true
51-
files = "pulp_glue/**/*.py"
49+
files = "pulp_glue/**/*.py, tests/**/*.py"
5250
namespace_packages = true
5351
explicit_package_bases = true
5452

5553
[[tool.mypy.overrides]]
54+
# This section is managed by the cookiecutter templates.
5655
module = [
5756
"schema.*",
5857
]
5958
ignore_missing_imports = true
59+
60+
61+
[tool.ruff]
62+
# This section is managed by the cookiecutter templates.
63+
line-length = 100
64+
65+
[tool.ruff.lint]
66+
# This section is managed by the cookiecutter templates.
67+
extend-select = ["I"]
68+

0 commit comments

Comments
 (0)