Skip to content

Commit 42e3b2b

Browse files
committed
Update black
Change the versioning scheme to pin to the year. According to the documentation that is the stability cadence of the style.
1 parent fe1b004 commit 42e3b2b

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: "Lint plugin_template"
3131
working-directory: "plugin_template"
3232
run: |
33-
pip3 install black==24.3.0 flake8
33+
pip3 install black~=26.3 flake8
3434
black --version
3535
black --check --diff plugin-template utils.py
3636
flake8 plugin-template utils.py

plugin-template

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# /// script
33
# requires-python = ">=3.11"
44
# dependencies = [
5-
# "black==24.3.0",
5+
# "black~=26.3",
66
# "jamldump>=1.2.0,<1.3.0",
77
# "jinja2>=3.1.6,<3.2.0",
8+
# "packaging>=26.0,<27",
89
# "pyyaml>=6.0.3,<6.1.0",
910
# "requests~=2.32.3",
1011
# "requests-cache>=1.3.0,<1.4.0",
@@ -378,7 +379,7 @@ def write_template_section(
378379
"current_version": utils.current_version(plugin_root_dir),
379380
"pulpdocs_branch": PULPDOCS_BRANCH,
380381
"is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(PULPDOCS_BRANCH),
381-
"black_version": utils.black_version(),
382+
"black_requirement": utils.black_requirement(),
382383
"config": config,
383384
**config,
384385
}

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# This needs to match the version in templates/github/lint_requirement.txt.j2
2-
black==24.3.0
1+
# This (black) is copied into templates/github/lint_requirement.txt.j2
2+
black~=26.3 # Pin style to the year. https://black.readthedocs.io/en/stable/faq.html#how-stable-is-black-s-style
33
jamldump>=1.2.0,<1.3.0
44
jinja2
5+
packaging>=26.0,<27
56
pyyaml
67
requests~=2.32.3
78
requests_cache

templates/github/lint_requirements.txt.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% include 'header.j2' %}
22

33
{% if black -%}
4-
black=={{ black_version }}
4+
{{ black_requirement }}
55
{% endif -%}
66
bump-my-version
77
check-manifest

utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import contextlib
2+
13
from datetime import timedelta
4+
from packaging.requirements import Requirement, InvalidRequirement
25
from pathlib import Path
36
import re
47
import stat
@@ -94,12 +97,13 @@ def current_version(plugin_root_path):
9497
return current_version
9598

9699

97-
def black_version():
98-
PATTERN = re.compile(r"^black==(?P<version>.*)$")
100+
def black_requirement():
99101
requirements_file = Path(__file__).parent / "requirements.txt"
100102
for line in requirements_file.read_text().splitlines():
101-
if match := PATTERN.fullmatch(line):
102-
return match.group("version")
103+
with contextlib.suppress(InvalidRequirement):
104+
requirement = Requirement(line.split("#")[0])
105+
if requirement.name.lower() == "black":
106+
return line
103107

104108
raise ValueError("'black' not found in 'requirements.txt'")
105109

0 commit comments

Comments
 (0)