Skip to content

Commit b1d4e50

Browse files
committed
Fix linting and only render subset of docs as jinja2
1 parent 782d7e1 commit b1d4e50

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

docs/conf.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@
6060

6161
def rstjinja(app, docname, source):
6262
"""
63-
Render our pages as a jinja template for fancy templating goodness.
63+
Render certain pages as a jinja templates.
6464
"""
6565
# this should only be run when building html
6666
if app.builder.format != "html":
6767
return
68-
src = source[0]
69-
rendered = app.builder.templates.render_string(src, app.config.html_context)
70-
source[0] = rendered
68+
# We currently only render docs/operations.rst
69+
# and docs/facts.rst as jinja2 templates
70+
if docname in ["operations", "facts"]:
71+
src = source[0]
72+
rendered = app.builder.templates.render_string(src, app.config.html_context)
73+
source[0] = rendered
7174

7275

7376
def setup(app):

src/pyinfra/api/metadata.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import tomllib
8-
from typing import Literal
8+
from typing import Literal, get_args
99

1010
from pydantic import BaseModel, TypeAdapter, field_validator
1111

@@ -34,24 +34,17 @@ class Tag(BaseModel):
3434

3535
@field_validator("value", mode="before")
3636
def _validate_value(cls, v) -> AllowedTagType:
37-
allowed_tags = set(AllowedTagType.__args__)
37+
allowed_tags = set(get_args(AllowedTagType))
3838
if v not in allowed_tags:
39-
raise ValueError(f"Invalid tag: {self.value}. Allowed: {allowed_tags}")
39+
raise ValueError(f"Invalid tag: {v}. Allowed: {allowed_tags}")
4040
return v
4141

4242
@property
4343
def title_case(self) -> str:
4444
return " ".join([t.title() for t in self.value.split("-")])
4545

46-
def __eq__(self, other):
47-
if isinstance(other, Tag):
48-
return self.value == other.value
49-
if isinstance(other, str):
50-
return self.value == other
51-
return NotImplemented
5246

53-
54-
ALLOWED_TAGS = [Tag(value=tag) for tag in set(AllowedTagType.__args__)]
47+
ALLOWED_TAGS = [Tag(value=tag) for tag in set(get_args(AllowedTagType))]
5548

5649

5750
class Plugin(BaseModel):
@@ -73,6 +66,4 @@ def parse_plugins(metadata_text: str) -> list[Plugin]:
7366
pyinfra_metadata = tomllib.loads(metadata_text).get("pyinfra", None)
7467
if not pyinfra_metadata:
7568
raise ValueError("Missing [pyinfra.plugins] section in pyinfra-metadata.toml")
76-
return TypeAdapter(list[Plugin]).validate_python(
77-
pyinfra_metadata["plugins"].values()
78-
)
69+
return TypeAdapter(list[Plugin]).validate_python(pyinfra_metadata["plugins"].values())

0 commit comments

Comments
 (0)