Skip to content

Add pre commit tool #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: rewrite-as-mkdocs-plugin
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Code Quality

on:
workflow_call:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit

- name: Run code quality checks
run: make code-quality
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ concurrency:
cancel-in-progress: true

jobs:
code-quality:
uses: "./.github/workflows/code-quality.yml"

docs:
uses: "./.github/workflows/docs.yml"

tests:
needs: "code-quality"
uses: "./.github/workflows/tests.yml"

ready-to-ship:
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
repos:
- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v5.0.0"
hooks:
- id: "trailing-whitespace"
exclude: "^pulp_docs"
- id: "end-of-file-fixer"
exclude: "^pulp_docs"
- id: "check-added-large-files"
- id: "check-toml"

- repo: "https://github.com/astral-sh/ruff-pre-commit"
rev: "v0.11.10"
hooks:
# Run the linter.
- id: "ruff-check"
args: [ "--fix" ]
# Run the formatter.
- id: "ruff-format"

- repo: "https://github.com/adrienverge/yamllint"
rev: "v1.37.1"
hooks:
- id: "yamllint"
files: ".*y[a]ml$"

- repo: "https://github.com/crate-ci/typos"
rev: "v1.32.0"
hooks:
- id: "typos"
exclude: "(^tests)|(^docs)|(^pulp_docs)"
...
42 changes: 42 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

yaml-files:
- '*.yaml'
- '*.yml'
- '.yamllint'

rules: # defaults are commented out
# anchors: enable
# braces: enable
# brackets: enable
# colons: enable
# commas: enable
# comments:
# level: warning
# comments-indentation:
# level: warning
document-end: enable
document-start: enable
# level: warning
# empty-lines: enable
# empty-values: disable
# float-values: disable
# hyphens: enable
# indentation: enable
# key-duplicates: enable
# key-ordering: disable
# line-length: enable
# new-line-at-end-of-file: enable
# new-lines: enable
# octal-values: disable
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.quoted_strings
quoted-strings:
quote-type: double
required: true
allow-quoted-quotes: true
check-keys: false

# trailing-spaces: enable
# truthy:
# level: warning
...
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
code-quality:
pre-commit run -a

docs:
mkdocs build

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ pipx install git+https://github.com/pulp/pulp-docs --include-deps
pulp-docs serve
```

For development, use your prefered method!
For development, use your preferred method!

## How to override `repolist.yml`

If you want to share work you are doing in muliple forks, you can share a custom `repolist.yml` which points to your forks.
If you want to share work you are doing in multiple forks, you can share a custom `repolist.yml` which points to your forks.

Then, anyone can test them locally by overriting your `repolist.yml` like so:
Then, anyone can test them locally by overwriting your `repolist.yml` like so:

```bash
$ cat "path/to/my/repolist.yml"
Expand All @@ -63,4 +63,3 @@ repos:
$ export PULPDOCS_MKDOCS_FILE="path/to/my/repolist.yml"
$ pulp-docs serve
```

2 changes: 0 additions & 2 deletions docs/dev/guides/create-plugin-overviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ Things to keep in mind:
- **Audience:** Target newcomers. Experienced users will probably use the ToC or the search.
- **Format:** Synopsis + Roadmap. Tell what your plugin is, what it does and a simple roadmap for starting.
- **Size:** Keep it brief. This should an easy win for the user before he starts this journey.


1 change: 0 additions & 1 deletion docs/dev/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Also, this is used for the production build.

To start using it, see the [Getting Started](site:pulp-docs/docs/dev/tutorials/getting-started/) section.
Before contributing, we recommend reading about the [Architecture](site:pulp-docs/docs/dev/reference/architecture/).

1 change: 0 additions & 1 deletion docs/dev/reference/markdown-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,3 @@ With subtitle:
[See mkdocs-material](https://squidfunk.github.io/mkdocs-material/reference/admonitions/#supported-types)

Use them wisely.

2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ theme:
toggle:
icon: material/toggle-switch
name: Switch to light mode
# Blog's Navigation needs to be excempt from literate nav...
# Blog's Navigation needs to be exempt from literate nav...
nav:
- Home: "index.md"
- "User Manual":
Expand Down
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ pythonpath = "src"
addopts = [
"--import-mode=importlib",
]

[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "I"]
ignore = []
exclude = [
".git",
".ruff_cache",
"__pycache__",
"build",
"dist",
"venv",
".venv",
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
line-ending = "auto"
19 changes: 7 additions & 12 deletions src/pulp_docs/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import asyncio
import click
import git
from pathlib import Path

import click
import git
from mkdocs.__main__ import cli as mkdocs_cli
from mkdocs.config import load_config

from pulp_docs.context import ctx_blog, ctx_docstrings, ctx_draft, ctx_path


Expand All @@ -13,9 +14,7 @@ def blog_callback(ctx: click.Context, param: click.Parameter, value: bool) -> bo
return value


def docstrings_callback(
ctx: click.Context, param: click.Parameter, value: bool
) -> bool:
def docstrings_callback(ctx: click.Context, param: click.Parameter, value: bool) -> bool:
ctx_docstrings.set(value)
return value

Expand Down Expand Up @@ -59,7 +58,7 @@ def find_path_callback(ctx: click.Context, param: click.Parameter, value: bool)
expose_value=False,
default="",
callback=find_path_callback,
help="A colon separated list of lookup paths in the form: [repo1@]path1 [:[repo2@]path2 [...]].",
help="A colon separated list of lookup paths in the form:[repo1@]path1 [:[repo2@]path2 [...]].",
)


Expand All @@ -70,15 +69,11 @@ async def clone_repository(repo_url: str) -> None:
repo_name = repo_url.split("/")[-1]
repo_path = dest_dir / repo_name
if repo_path.exists():
click.echo(
f"Repository {repo_name} already exists at {repo_path}, skipping."
)
click.echo(f"Repository {repo_name} already exists at {repo_path}, skipping.")
return
click.echo(f"Cloning {repo_url} to {repo_path}...")
loop = asyncio.get_running_loop()
await loop.run_in_executor(
None, lambda: git.Repo.clone_from(repo_url, repo_path, depth=1)
)
await loop.run_in_executor(None, lambda: git.Repo.clone_from(repo_url, repo_path, depth=1))
click.echo(f"Successfully cloned {repo_name}")

tasks = [clone_repository(repo) for repo in repositories]
Expand Down
2 changes: 1 addition & 1 deletion src/pulp_docs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Names:
# personas
USER = "Usage"
ADMIN = "Administration"
DEV = "Developemnt"
DEV = "Developments"

# other
PULPCORE_TUTORIAL = "Getting Started"
Expand Down
1 change: 0 additions & 1 deletion src/pulp_docs/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from contextvars import ContextVar


ctx_blog = ContextVar("ctx_blog", default=True)
ctx_docstrings = ContextVar("ctx_docstrings", default=True)
ctx_draft = ContextVar("ctx_draft", default=False)
Expand Down
2 changes: 1 addition & 1 deletion src/pulp_docs/data/repolist.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
meta:
version: 1
rest_api_template: https://docs.pulpproject.org/{}/restapi.html
rest_api_template: https://docs.pulpproject.org/{}/restapi.html
repo_types:
- core
- content
Expand Down
17 changes: 6 additions & 11 deletions src/pulp_docs/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import shutil
import subprocess
import tempfile
from importlib.resources import files
from pathlib import Path
from typing import NamedTuple, Optional

from importlib.resources import files

from pulp_docs.constants import BASE_TMPDIR_NAME
from pulp_docs.repository import Repos


def main(
output_dir: Path, plugins_filter: Optional[list[str]] = None, dry_run: bool = False
):
def main(output_dir: Path, plugins_filter: Optional[list[str]] = None, dry_run: bool = False):
"""Creates openapi json files for all or selected plugins in output dir."""
repolist = str(files("pulp_docs").joinpath("data/repolist.yml"))
repos = Repos.from_yaml(repolist).get_repos(["content"])
Expand Down Expand Up @@ -57,7 +54,7 @@ def get_remote_url(self):

class OpenAPIGenerator:
"""
Responsible for seting up a python environment with the required
Responsible for setting up a python environment with the required
Pulp packages to generate openapi schemas for all registered plugins.

Args:
Expand Down Expand Up @@ -97,9 +94,7 @@ def setup_venv(self, plugin: PulpPlugin):
"""
create_venv_cmd = ("python", "-m", "venv", self.venv_path)
url = (
plugin.get_remote_url()
if not plugin.is_subpackage
else self.pulpcore.get_remote_url()
plugin.get_remote_url() if not plugin.is_subpackage else self.pulpcore.get_remote_url()
)
# setuptools provides distutils for python >=3.12.
install_cmd = ["pip", "install", f"git+{url}", "setuptools"]
Expand All @@ -115,7 +110,7 @@ def setup_venv(self, plugin: PulpPlugin):
def run_python(self, *cmd: str) -> str:
"""Run a binary command from within the tmp venv.

Basicaly: $tmp-venv/bin/{first-arg} {remaining-args}
Basically: $tmp-venv/bin/{first-arg} {remaining-args}
"""
cmd_bin = os.path.join(self.venv_path, f"bin/{cmd[0]}")
final_cmd = [cmd_bin] + list(cmd[1:])
Expand Down Expand Up @@ -146,7 +141,7 @@ def parse_args():
"-l",
"--plugin-list",
type=str,
help="List of plugins that should be used. Use all if ommited.",
help="List of plugins that should be used. Use all if omitted.",
)
args = parser.parse_args()

Expand Down
Loading