Skip to content

Commit

Permalink
More re-formatting
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
pedro-psb committed Mar 21, 2024
1 parent 9562fe7 commit 5934076
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 108 deletions.
12 changes: 3 additions & 9 deletions .ci/scripts/check_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def main():
for branch in branches:
if branch != DEFAULT_BRANCH:
# Check if a Z release is needed
changes = repo.git.ls_tree(
"-r", "--name-only", f"origin/{branch}", "CHANGES/"
)
changes = repo.git.ls_tree("-r", "--name-only", f"origin/{branch}", "CHANGES/")
z_release = False
for change in changes.split("\n"):
# Check each changelog file to make sure everything checks out
Expand Down Expand Up @@ -103,9 +101,7 @@ def main():
"--",
".bumpversion.cfg",
)
next_version = (
bump_commit.split("to ")[-1] if bump_commit else None
)
next_version = bump_commit.split("to ")[-1] if bump_commit else None

# You could, theoretically, be next_vers==None here - but that's always
# been true for this script.
Expand All @@ -117,9 +113,7 @@ def main():
releases.append(next_version)
else:
# Check if a Y release is needed
changes = repo.git.ls_tree(
"-r", "--name-only", DEFAULT_BRANCH, "CHANGES/"
)
changes = repo.git.ls_tree("-r", "--name-only", DEFAULT_BRANCH, "CHANGES/")
for change in changes.split("\n"):
_, ext = os.path.splitext(change)
if ext in Y_CHANGELOG_EXTS:
Expand Down
20 changes: 5 additions & 15 deletions .ci/scripts/check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
if line.startswith("git+"):
# The single exception...
if "pulp-smash" not in line:
errors.append(
f"{filename}:{nr}: Invalid source requirement: {line}"
)
errors.append(f"{filename}:{nr}: Invalid source requirement: {line}")
elif line.startswith("-r "):
if check_r:
errors.append(
f"{filename}:{nr}: Invalid deferred requirement: {line}"
)
errors.append(f"{filename}:{nr}: Invalid deferred requirement: {line}")
else:
errors.append(f"{filename}:{nr}: Unreadable requirement {line}")
else:
Expand All @@ -52,20 +48,14 @@
not req.name.startswith("opentelemetry")
and req.name != "pulp-docs-client"
):
errors.append(
f"{filename}:{nr}: Prerelease versions found in {line}."
)
errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.")
ops = [op for op, ver in req.specs]
spec = str(req.specs)
if "~=" in ops:
warnings.warn(
f"{filename}:{nr}: Please avoid using ~= on {req.name}!"
)
warnings.warn(f"{filename}:{nr}: Please avoid using ~= on {req.name}!")
elif "<" not in ops and "<=" not in ops and "==" not in ops:
if check_upperbound:
errors.append(
f"{filename}:{nr}: Upper bound missing in {line}."
)
errors.append(f"{filename}:{nr}: Upper bound missing in {line}.")
except FileNotFoundError:
# skip this test for plugins that don't use this requirements.txt
pass
Expand Down
12 changes: 3 additions & 9 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
TITLE_REGEX = (
"("
+ re.escape(
TITLE_FORMAT.format(
name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX"
)
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
)
.replace("NAME_REGEX", NAME_REGEX)
.replace("VERSION_REGEX", VERSION_REGEX)
Expand All @@ -60,17 +58,13 @@ def _tokenize_changes(splits):
def split_changelog(changelog):
preamble, rest = changelog.split(START_STRING, maxsplit=1)
split_rest = re.split(TITLE_REGEX, rest)
return preamble + START_STRING + split_rest[0], list(
_tokenize_changes(split_rest[1:])
)
return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:]))


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

Expand Down
10 changes: 2 additions & 8 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
NO_ISSUE = "[noissue]"
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"]
sha = sys.argv[1]
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode(
"utf-8"
)
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")


KEYWORDS = ["fixes", "closes"]
Expand Down Expand Up @@ -68,11 +66,7 @@ def __check_changelog(issue):
__check_changelog(issue)
else:
if NO_ISSUE in message:
print(
"Commit {sha} has no issues but is tagged {tag}.".format(
sha=sha[0:7], tag=NO_ISSUE
)
)
print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE))
elif "Merge" in message and "cherry picked from commit" in message:
pass
else:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/scripts/docs-publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def main():
if exit_code != 0:
raise RuntimeError("An error occurred while pushing docs.")
elif build_type == "tag":
if (not re.search("[a-zA-Z]", branch) or "post" in branch) and len(
branch.split(".")
) > 2:
if (not re.search("[a-zA-Z]", branch) or "post" in branch) and len(branch.split(".")) > 2:
# Only publish docs at the root if this is the latest version
r = requests.get("https://pypi.org/pypi/pulp-docs/json")
latest_version = version.parse(json.loads(r.text)["info"]["version"])
Expand All @@ -133,9 +131,7 @@ def main():
# publish to the root of docs.pulpproject.org
if publish_at_root:
version_components = branch.split(".")
x_y_version = "{}.{}".format(
version_components[0], version_components[1]
)
x_y_version = "{}.{}".format(version_components[0], version_components[1])
remote_path_arg = "%s@%s:%s" % (USERNAME, HOSTNAME, SITE_ROOT)
rsync_command = [
"rsync",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"""
)

parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter, description=helper
)
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)

parser.add_argument(
"release_version",
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/scripts/update_backport_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ def random_color():
session.headers.update(headers)

# get all labels from the repository's current state
response = session.get(
"https://api.github.com/repos/pulp/pulp-docs/labels", headers=headers
)
response = session.get("https://api.github.com/repos/pulp/pulp-docs/labels", headers=headers)
assert response.status_code == 200
old_labels = set(
[x["name"] for x in response.json() if x["name"].startswith("backport-")]
)
old_labels = set([x["name"] for x in response.json() if x["name"].startswith("backport-")])

# get list of branches from template_config.yml
with open("./template_config.yml", "r") as f:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ exclude = '''
\.eggs
| \.git
| \.venv
| venv
| _build
| build
| dist
Expand Down
20 changes: 5 additions & 15 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def print_user_repo(repos: Repos, config: Config):
)

if len(local_checkouts) == 0:
warn_msgs.append(
"[pulp-docs] No local checkouts found. Serving in read-only mode."
)
warn_msgs.append("[pulp-docs] No local checkouts found. Serving in read-only mode.")

if config.verbose:
report = {
Expand Down Expand Up @@ -263,9 +261,7 @@ def define_env(env):
repos = Repos.from_yaml(config.repolist)
repos.update_local_checkouts()
else:
repos = (
Repos.test_fixtures()
) # try to use fixtures if there is no BASE_REPOLIST
repos = Repos.test_fixtures() # try to use fixtures if there is no BASE_REPOLIST
log.info(f"Repository configurations loaded: {[repo.name for repo in repos.all]}")

# Download and organize repository files
Expand All @@ -279,18 +275,14 @@ def define_env(env):
for repo_or_package in repos.all:
# Handle subpackages or repos
if isinstance(repo_or_package, SubPackage):
repo_or_package_path = (
repo_or_package.subpackage_of + "/" + repo_or_package.name
)
repo_or_package_path = repo_or_package.subpackage_of + "/" + repo_or_package.name
else:
repo_or_package_path = repo_or_package.name

# Add to mkdocstring pythonpath
code_sources.append(str(source_dir / repo_or_package_path))

env.conf["plugins"]["mkdocstrings"].config["handlers"]["python"][
"paths"
] = code_sources
env.conf["plugins"]["mkdocstrings"].config["handlers"]["python"]["paths"] = code_sources

# Configure navigation
log.info("[pulp-docs] Configuring navigation")
Expand All @@ -307,9 +299,7 @@ def define_env(env):
def get_repos(repo_type="content"):
"Return repo names by type"
_repo_type = [repo_type] if repo_type else None
repos_list = sorted(
repos.get_repos(repo_types=_repo_type), key=lambda x: x.title
)
repos_list = sorted(repos.get_repos(repo_types=_repo_type), key=lambda x: x.title)
repos_data = [
{
"title": repo.title,
Expand Down
28 changes: 5 additions & 23 deletions src/pulp_docs/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
f.section(Names.GUIDES, f.get_children, "pulpcore/docs/user/guides"),
]
},
{
"Plugins": f.repo_grouping(
"{repo}/docs/user/{content}", repo_types=["content"]
)
},
{"Plugins": f.repo_grouping("{repo}/docs/user/{content}", repo_types=["content"])},
{"Extras": f.repo_grouping("{repo}/docs/user/{content}", repo_types=["other"])},
]
admin_section = [
Expand Down Expand Up @@ -117,35 +113,21 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
f.section(Names.GUIDES, f.get_children, "pulpcore/docs/dev/guides"),
]
},
{
"Plugins": f.repo_grouping(
"{repo}/docs/dev/{content}", repo_types=["content"]
)
},
{"Plugins": f.repo_grouping("{repo}/docs/dev/{content}", repo_types=["content"])},
{"Extras": f.repo_grouping("{repo}/docs/dev/{content}", repo_types=["other"])},
]
help_section = [
*f.get_children("pulp-docs/docs/sections/help/community"),
{
"Documentation Usage": f.get_children(
"pulp-docs/docs/sections/help/using-this-doc"
)
},
{"Documentation Usage": f.get_children("pulp-docs/docs/sections/help/using-this-doc")},
{
"Changelogs": [
{"Pulpcore": "pulpcore/changes/changelog.md"},
{
"Plugins": sorted(
f.repo_grouping(
"{repo}/changes", repo_types=["content"]
).items()
)
},
{
"Extra": sorted(
f.repo_grouping("{repo}/changes", repo_types=["other"]).items()
f.repo_grouping("{repo}/changes", repo_types=["content"]).items()
)
},
{"Extra": sorted(f.repo_grouping("{repo}/changes", repo_types=["other"]).items())},
]
},
{"Governance": f.get_children("pulp-docs/docs/sections/help/governance")},
Expand Down
12 changes: 4 additions & 8 deletions src/pulp_docs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ def download_from_gh_main(dest_dir: Path, owner: str, name: str, branch: str):
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
log.error(
f"An error ocurred while trying to download '{name}' source-code:\n{e}"
)
log.error(f"An error ocurred while trying to download '{name}' source-code:\n{e}")
raise

log.info("Done.")
Expand All @@ -158,8 +156,8 @@ def download_from_gh_latest(dest_dir: Path, owner: str, name: str):
Returns the download url.
"""
latest_release_link_url = (
"https://api.github.com/repos/{}/{}/releases/latest".format(owner, name)
latest_release_link_url = "https://api.github.com/repos/{}/{}/releases/latest".format(
owner, name
)

print("Fetching latest release with:", latest_release_link_url)
Expand Down Expand Up @@ -318,8 +316,6 @@ def test_fixtures(cls):
type="content",
),
Repo("Maven", "new_repo3", local_basepath=FIXTURE_WORKDIR, type="content"),
Repo(
"Docs Tool", "pulp-docs", local_basepath=FIXTURE_WORKDIR, type="other"
),
Repo("Docs Tool", "pulp-docs", local_basepath=FIXTURE_WORKDIR, type="other"),
]
return Repos(core_repo=DEFAULT_CORE, content_repos=DEFAULT_CONTENT_REPOS)
8 changes: 2 additions & 6 deletions src/pulp_docs/utils/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def repo_grouping(
lookup_path = self._parse_template_str(template_str, repo.name)
_repo_content = self.get_children(lookup_path)
if _repo_content:
_nav[repo.title] = (
_repo_content if len(_repo_content) > 1 else _repo_content[0]
)
_nav[repo.title] = _repo_content if len(_repo_content) > 1 else _repo_content[0]
# Expand content-types
else:
for repo in selected_repos:
Expand All @@ -133,9 +131,7 @@ def repo_grouping(

for content_type in selected_content:
# Get repo files from content-type and persona
lookup_path = self._parse_template_str(
template_str, repo.name, content_type
)
lookup_path = self._parse_template_str(template_str, repo.name, content_type)
_repo_content = self.get_children(lookup_path)

# Prevent rendering content-type section if there are no files
Expand Down

0 comments on commit 5934076

Please sign in to comment.