Skip to content

Commit db4abb8

Browse files
committed
Switch to using ruff
1 parent 67736fe commit db4abb8

File tree

11 files changed

+184
-36
lines changed

11 files changed

+184
-36
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-gem"

.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:

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
include:
2020
- image_tag: "nightly"
2121
pulp_api_root: "/relocated/djnd/"
22+
upper_bounds: true
2223
python: "3.11"
2324
- image_tag: "latest"
2425
lower_bounds: true

Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue-gem/pulp_glue/*))
33
CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*))
44

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

12+
.PHONY: build
1113
build:
1214
cd pulp-glue-gem; pyproject-build -n
1315
pyproject-build -n
1416

15-
black: format
16-
17+
.PHONY: format
1718
format:
18-
isort .
19-
cd pulp-glue-gem; isort .
20-
black .
19+
ruff format
20+
ruff check --fix
2121

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

37+
.PHONY: test
3838
test: | tests/cli.toml
3939
python3 -m pytest -v tests pulp-glue-gem/tests
4040

41+
.PHONY: livetest
4142
livetest: | tests/cli.toml
4243
python3 -m pytest -v tests pulp-glue-gem/tests -m live
4344

45+
.PHONY: unittest
4446
unittest:
4547
python3 -m pytest -v tests pulp-glue-gem/tests -m "not live"
4648

49+
.PHONY: unittest_glue
4750
unittest_glue:
4851
python3 -m pytest -v pulp-glue-gem/tests -m "not live"
49-
.PHONY: build info black lint test

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.10
63
mypy==1.19.1
74
shellcheck-py==0.11.0.1
85

0 commit comments

Comments
 (0)