Skip to content
Merged

Black #995

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ def main():
print("\nDeprecation check:")
check_for_deprecated_files(plugin_root_dir, sections)

if config["black"]:
try:
subprocess.run(["black", "--quiet", "."], cwd=plugin_root_dir)
except FileNotFoundError:
pass


def migrate_dummy(plugin_root_dir):
pass
Expand Down Expand Up @@ -422,6 +428,7 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
"current_version": utils.current_version(plugin_root_path),
"pulpdocs_branch": PULPDOCS_BRANCH,
"is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(PULPDOCS_BRANCH),
"black_version": utils.black_version(),
**config,
}

Expand Down Expand Up @@ -472,20 +479,6 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
if verbose:
print(f"Copied file: {relative_path}")

if config["black"]:
black_paths = filter(lambda x: x.endswith(".py.j2"), relative_path_set)
black_paths = map(lambda x: x[: -len(".j2")], black_paths)
black_paths = map(
lambda x: x.replace("plugin_name", utils.to_snake(config["plugin_name"])), black_paths
)
black_paths = filter(
lambda x: os.path.exists(os.path.join(plugin_root_dir, x)), black_paths
)
try:
subprocess.run(["black", "--quiet"] + list(black_paths), cwd=plugin_root_dir)
except FileNotFoundError:
pass

print(f"Section: {name} \n templated: {files_templated}\n copied: {files_copied}")
return 0

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Click is pinned because of:
# https://github.com/pallets/click/issues/3065
click<8.3
black
# This needs to match the version in templates/github/lint_requirement.txt.j2
black==24.3.0
jinja2
pyyaml
requests~=2.32.3
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion templates/github/lint_requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% include 'header.j2' %}

{% if black -%}
black==24.3.0
black=={{ black_version }}
{% endif -%}
# Click is pinned because of:
# https://github.com/pallets/click/issues/3065
Expand Down
11 changes: 11 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
from pathlib import Path
import re
import requests_cache
import stat
Expand Down Expand Up @@ -93,6 +94,16 @@ def current_version(plugin_root_path):
return current_version


def black_version():
PATTERN = re.compile(r"^black==(?P<version>.*)$")
requirements_file = Path(__file__).parent / "requirements.txt"
for line in requirements_file.read_text().splitlines():
if match := PATTERN.fullmatch(line):
return match.group("version")

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


def get_pulpdocs_members(pulpdocs_branch="main") -> list[str]:
"""
Get repositories which are members of the Pulp managed documentation.
Expand Down