Skip to content

Commit

Permalink
Merge pull request #1 from pedro-psb/some-changes
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
pedro-psb authored Mar 20, 2024
2 parents 06e61ad + 3716e96 commit 38fa60f
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 36 deletions.
12 changes: 9 additions & 3 deletions .ci/scripts/check_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ 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 @@ -101,7 +103,9 @@ 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 @@ -113,7 +117,9 @@ 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: 15 additions & 5 deletions .ci/scripts/check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@
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 @@ -48,14 +52,20 @@
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: 9 additions & 3 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
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 @@ -58,13 +60,17 @@ 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: 8 additions & 2 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
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 @@ -66,7 +68,11 @@ 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: 6 additions & 2 deletions .github/workflows/scripts/docs-publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ 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 @@ -131,7 +133,9 @@ 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,7 +23,9 @@
"""
)

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: 6 additions & 2 deletions .github/workflows/scripts/update_backport_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Also, this should be used for the production build.

Through a `mkdocs-macro-plugin` hook (called in early stages of mkdocs processing), we inject the following steps:

1. Read [`repolist.yml`](https://github.com/pedro-psb/pulp-docs/blob/main/src/pulp_docs/data/repolist.yml) packaged with `pulp-docs` to know which repos/urls to use
1. Read [`repolist.yml`](https://github.com/pulp/pulp-docs/blob/main/src/pulp_docs/data/repolist.yml) packaged with `pulp-docs` to know which repos/urls to use
1. Download/Move all source code required to dir under `tempfile.gettempdir()`
- Uses `../{repo}` if available OR
- Uses existing cached `{tmpdir}/{repo}` if available OR
Expand All @@ -39,7 +39,7 @@ And thats it, the magic is done.
Recommended way for daily usage:

```bash
pipx install git+https://github.com/pedro-psb/pulp-docs --include-deps
pipx install git+https://github.com/pulp/pulp-docs --include-deps
pulp-docs serve
```

Expand Down
1 change: 0 additions & 1 deletion src/pulp_docs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import subprocess
import sys
import tempfile
from pathlib import Path

import click
Expand Down
6 changes: 4 additions & 2 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo):
# Create placeholder, case it was not possible to fetch one
empty_changelog = changes_dir / "changelog.md"
empty_changelog.write_text(
"# Changelog\n\nThe repository does not provide a changelog or there was a problem fetching it."
"# Changelog\n\nThe repository does not provide a changelog or"
"there was a problem fetching it."
)


Expand Down Expand Up @@ -222,7 +223,8 @@ def print_user_repo(repos: Repos, config: Config):
# TODO: improve this refspec comparision heuristics
if repo.branch not in repo.branch_in_use:
warn_msgs.append(
f"[pulp-docs] Original {repo.name!r} ref is {repo.branch!r}, but local one is '{repo.branch_in_use}'."
f"[pulp-docs] Original {repo.name!r} ref is {repo.branch!r},"
f"but local one is '{repo.branch_in_use}'."
)

if len(local_checkouts) == 0:
Expand Down
8 changes: 0 additions & 8 deletions src/pulp_docs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from __future__ import annotations

import logging
import os
import shutil
import subprocess
import tarfile
import tempfile
import typing as t
from collections import ChainMap, defaultdict
from dataclasses import dataclass, field
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -68,10 +66,6 @@ class Repo:
def __post_init__(self):
self.branch_in_use = self.branch_in_use or self.branch

@property
def rest_api_link(self):
return RESTAPI_TEMPLATE.format(self.name)

def download(self, dest_dir: Path, clear_cache: bool = False) -> str:
"""
Download repository source from url into the {dest_dir} Path.
Expand Down Expand Up @@ -162,8 +156,6 @@ def download_from_gh_latest(dest_dir: Path, owner: str, name: str):
"""
Download repository source-code from latest GitHub Release (w/ GitHub API).
See: https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release
Returns the download url.
"""
latest_release_link_url = (
Expand Down
13 changes: 9 additions & 4 deletions src/pulp_docs/utils/aggregation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import typing as t
from pathlib import Path

Expand Down Expand Up @@ -67,9 +66,15 @@ def repo_grouping(
Get all markdown files that matches @template_str basepath and group by repos.
Arguments:
template_str: The template with fields to expand. Accepts combination of '{repo}' and '{content}'
repo_types: The set of repos to use. Accepts list with combination of "core", "content" and "other"
content_types: The set of content-types to use. Accepts combination of "guides", "learn" and "tutorial"
template_str:
The template with fields to expand.
Accepts combination of '{repo}' and '{content}'
repo_types:
The set of repos to use.
Accepts list with combination of "core", "content" and "other"
content_types:
The set of content-types to use.
Accepts combination of "guides", "learn" and "tutorial"
Example:
```python
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
from pathlib import Path

import pytest
import subprocess
from click.testing import CliRunner

Expand Down

0 comments on commit 38fa60f

Please sign in to comment.