Skip to content
Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.5
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
22 changes: 22 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,25 @@ output-format = "full"
[format]
preview = true
docstring-code-format = true

[lint]
preview = true
select = [
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"I", # isort
"N", # pep8-naming
"PERF", # perflint
"PGH", # pygrep-hooks
"PT", # flake8-pytest-style
"TC", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
"E501", # Ignore line length errors (we use auto-formatting)
]
42 changes: 22 additions & 20 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,19 @@
from urllib.parse import urljoin

import jinja2
import platformdirs
import tomlkit
import urllib3
import zc.lockfile
from platformdirs import user_config_path, site_config_path

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Collection, Iterator, Sequence, Set
from typing import Literal

try:
from os import EX_OK, EX_SOFTWARE as EX_FAILURE
from os import EX_OK
from os import EX_SOFTWARE as EX_FAILURE
except ImportError:
EX_OK, EX_FAILURE = 0, 1

Expand Down Expand Up @@ -279,7 +280,7 @@ def filter(self, language_tags: Sequence[str] = ()) -> Sequence[Language]:
"""Filter a sequence of languages according to --languages."""
if language_tags:
language_tags = frozenset(language_tags)
return [l for l in self if l.tag in language_tags]
return [l for l in self if l.tag in language_tags] # NoQA: E741
return list(self)


Expand Down Expand Up @@ -480,7 +481,7 @@ def setup_switchers(versions: Versions, languages: Languages, html_root: Path) -
- Cross-link various languages in a language switcher
- Cross-link various versions in a version switcher
"""
language_pairs = sorted((l.tag, l.switcher_label) for l in languages if l.in_prod)
language_pairs = sorted((l.tag, l.switcher_label) for l in languages if l.in_prod) # NoQA: E741
version_pairs = [(v.name, v.picker_label) for v in reversed(versions)]

switchers_template_file = HERE / "templates" / "switchers.js"
Expand Down Expand Up @@ -1057,28 +1058,29 @@ def setup_logging(log_directory: Path, select_output: str | None) -> None:


def load_environment_variables() -> None:
_user_config_path = user_config_path("docsbuild-scripts")
_site_config_path = site_config_path("docsbuild-scripts")
if _user_config_path.is_file():
ENV_CONF_FILE = _user_config_path
elif _site_config_path.is_file():
ENV_CONF_FILE = _site_config_path
dbs_user_config = platformdirs.user_config_path("docsbuild-scripts")
dbs_site_config = platformdirs.site_config_path("docsbuild-scripts")
if dbs_user_config.is_file():
env_conf_file = dbs_user_config
elif dbs_site_config.is_file():
env_conf_file = dbs_site_config
else:
logging.info(
"No environment variables configured. "
f"Configure in {_site_config_path} or {_user_config_path}."
f"Configure in {dbs_site_config} or {dbs_user_config}."
)
return

logging.info(f"Reading environment variables from {ENV_CONF_FILE}.")
if ENV_CONF_FILE == _site_config_path:
logging.info(f"You can override settings in {_user_config_path}.")
elif _site_config_path.is_file():
logging.info(f"Overriding {_site_config_path}.")
with open(ENV_CONF_FILE, "r") as f:
for key, value in tomlkit.parse(f.read()).get("env", {}).items():
logging.debug(f"Setting {key} in environment.")
os.environ[key] = value
logging.info(f"Reading environment variables from {env_conf_file}.")
if env_conf_file == dbs_site_config:
logging.info(f"You can override settings in {dbs_user_config}.")
elif dbs_site_config.is_file():
logging.info(f"Overriding {dbs_site_config}.")

env_config = env_conf_file.read_text(encoding="utf-8")
for key, value in tomlkit.parse(env_config).get("env", {}).items():
logging.debug(f"Setting {key} in environment.")
os.environ[key] = value


def build_docs_with_lock(args: argparse.Namespace, lockfile_name: str) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.mark.parametrize(
"seconds, expected",
("seconds", "expected"),
[
(0.4, "0s"),
(0.5, "0s"),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_docs_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from build_docs import Versions, Version
from build_docs import Version, Versions


def test_filter_default() -> None:
Expand Down