Skip to content

Commit 3e52760

Browse files
committed
Add black linting using
./plugin-template --github pulp_python
1 parent 7099857 commit 3e52760

File tree

8 files changed

+56
-17
lines changed

8 files changed

+56
-17
lines changed

.ci/scripts/calc_constraints.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import tomli as tomllib
2020

2121

22-
CORE_TEMPLATE_URL = "https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml"
22+
CORE_TEMPLATE_URL = (
23+
"https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml"
24+
)
2325

2426

2527
def fetch_pulpcore_upper_bound(requirement):
@@ -89,7 +91,9 @@ def to_lower_bound(req):
8991
# TODO Semver libraries should be allowed too.
9092
operator = "~="
9193
if len(Version(min_version).release) != 3:
92-
raise RuntimeError("Pulpcore lower bound must be in the form '>=x.y.z'.")
94+
raise RuntimeError(
95+
"Pulpcore lower bound must be in the form '>=x.y.z'."
96+
)
9397
else:
9498
operator = "=="
9599
return f"{requirement.name}{operator}{min_version}"
@@ -109,8 +113,14 @@ def main():
109113

110114
modifier = to_upper_bound if args.upper else to_lower_bound
111115

112-
req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")]
113-
pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")]
116+
req_files = [
117+
filename
118+
for filename in args.filename
119+
if not filename.endswith("pyproject.toml")
120+
]
121+
pyp_files = [
122+
filename for filename in args.filename if filename.endswith("pyproject.toml")
123+
]
114124
if req_files:
115125
with fileinput.input(files=req_files) as req_file:
116126
for line in req_file:

.ci/scripts/check_requirements.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ def main():
5353
if line.startswith("git+"):
5454
# The single exception...
5555
if "pulp-smash" not in line:
56-
errors.append(f"{filename}:{nr}: Invalid source requirement: {line}")
56+
errors.append(
57+
f"{filename}:{nr}: Invalid source requirement: {line}"
58+
)
5759
elif line.startswith("-r "):
5860
if check_r:
59-
errors.append(f"{filename}:{nr}: Invalid deferred requirement: {line}")
61+
errors.append(
62+
f"{filename}:{nr}: Invalid deferred requirement: {line}"
63+
)
6064
else:
6165
errors.append(f"{filename}:{nr}: Unreadable requirement {line}")
6266
else:
@@ -66,13 +70,19 @@ def main():
6670
not req.name.startswith("opentelemetry")
6771
and req.name != "pulp-python-client"
6872
):
69-
errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.")
73+
errors.append(
74+
f"{filename}:{nr}: Prerelease versions found in {line}."
75+
)
7076
ops = [spec.operator for spec in req.specifier]
7177
if "~=" in ops:
72-
warnings.warn(f"{filename}:{nr}: Please avoid using ~= on {req.name}!")
78+
warnings.warn(
79+
f"{filename}:{nr}: Please avoid using ~= on {req.name}!"
80+
)
7381
elif "<" not in ops and "<=" not in ops and "==" not in ops:
7482
if check_upperbound:
75-
errors.append(f"{filename}:{nr}: Upper bound missing in {line}.")
83+
errors.append(
84+
f"{filename}:{nr}: Upper bound missing in {line}."
85+
)
7686
except FileNotFoundError:
7787
# skip this test for plugins that don't use this requirements.txt
7888
pass

.ci/scripts/collect_changes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
TITLE_REGEX = (
4141
"("
4242
+ re.escape(
43-
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
43+
TITLE_FORMAT.format(
44+
name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX"
45+
)
4446
)
4547
.replace("NAME_REGEX", NAME_REGEX)
4648
.replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1)
@@ -65,13 +67,17 @@ def _tokenize_changes(splits):
6567
def split_changelog(changelog):
6668
preamble, rest = changelog.split(START_STRING, maxsplit=1)
6769
split_rest = re.split(TITLE_REGEX, rest)
68-
return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:]))
70+
return preamble + START_STRING + split_rest[0], list(
71+
_tokenize_changes(split_rest[1:])
72+
)
6973

7074

7175
def main():
7276
repo = Repo(os.getcwd())
7377
remote = repo.remotes[0]
74-
branches = [ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)]
78+
branches = [
79+
ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)
80+
]
7581
branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True)
7682
branches = [ref.name for ref in branches]
7783

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ jobs:
4343
bump-my-version bump --dry-run release
4444
bump-my-version show-bump
4545
46+
# run black separately from flake8 to get a diff
47+
- name: "Run black"
48+
run: |
49+
black --version
50+
black --check --diff .
51+
4652
# Lint code.
4753
- name: "Run flake8"
4854
run: |

.github/workflows/scripts/stage-changelog-for-default-branch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"""
2424
)
2525

26-
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)
26+
parser = argparse.ArgumentParser(
27+
formatter_class=argparse.RawTextHelpFormatter, description=helper
28+
)
2729

2830
parser.add_argument(
2931
"release_version",

.github/workflows/scripts/update_backport_labels.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ def random_color():
2828
session.headers.update(headers)
2929

3030
# get all labels from the repository's current state
31-
response = session.get("https://api.github.com/repos/pulp/pulp_python/labels", headers=headers)
31+
response = session.get(
32+
"https://api.github.com/repos/pulp/pulp_python/labels", headers=headers
33+
)
3234
assert response.status_code == 200
33-
old_labels = set([x["name"] for x in response.json() if x["name"].startswith("backport-")])
35+
old_labels = set(
36+
[x["name"] for x in response.json() if x["name"].startswith("backport-")]
37+
)
3438

3539
# get list of branches from template_config.yml
3640
with open("./template_config.yml", "r") as f:

lint_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#
66
# For more info visit https://github.com/pulp/plugin_template
77

8+
black==24.3.0
89
bump-my-version
910
check-manifest
1011
flake8
12+
flake8-black
1113
packaging
1214
yamllint

template_config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# generated with plugin_template
55

66
api_root: /pulp/
7-
black: false
7+
black: true
88
check_commit_message: true
99
check_gettext: true
1010
check_manifest: true
@@ -72,4 +72,3 @@ test_reroute: true
7272
test_s3: true
7373
test_storages_compat_layer: true
7474
use_issue_template: true
75-

0 commit comments

Comments
 (0)