Skip to content

Commit 57136bc

Browse files
authored
Use Ruff linting (#277)
1 parent 2fee30f commit 57136bc

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ repos:
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
1717
rev: v0.11.5
1818
hooks:
19+
- id: ruff
1920
- id: ruff-format
2021

2122
- repo: https://github.com/python-jsonschema/check-jsonschema

.ruff.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,25 @@ output-format = "full"
55
[format]
66
preview = true
77
docstring-code-format = true
8+
9+
[lint]
10+
preview = true
11+
select = [
12+
"C4", # flake8-comprehensions
13+
"B", # flake8-bugbear
14+
"E", # pycodestyle
15+
"F", # pyflakes
16+
"FA", # flake8-future-annotations
17+
"FLY", # flynt
18+
"I", # isort
19+
"N", # pep8-naming
20+
"PERF", # perflint
21+
"PGH", # pygrep-hooks
22+
"PT", # flake8-pytest-style
23+
"TC", # flake8-type-checking
24+
"UP", # pyupgrade
25+
"W", # pycodestyle
26+
]
27+
ignore = [
28+
"E501", # Ignore line length errors (we use auto-formatting)
29+
]

build_docs.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@
6565
from urllib.parse import urljoin
6666

6767
import jinja2
68+
import platformdirs
6869
import tomlkit
6970
import urllib3
7071
import zc.lockfile
71-
from platformdirs import user_config_path, site_config_path
7272

7373
TYPE_CHECKING = False
7474
if TYPE_CHECKING:
7575
from collections.abc import Collection, Iterator, Sequence, Set
7676
from typing import Literal
7777

7878
try:
79-
from os import EX_OK, EX_SOFTWARE as EX_FAILURE
79+
from os import EX_OK
80+
from os import EX_SOFTWARE as EX_FAILURE
8081
except ImportError:
8182
EX_OK, EX_FAILURE = 0, 1
8283

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

285286

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

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

10581059

10591060
def load_environment_variables() -> None:
1060-
_user_config_path = user_config_path("docsbuild-scripts")
1061-
_site_config_path = site_config_path("docsbuild-scripts")
1062-
if _user_config_path.is_file():
1063-
ENV_CONF_FILE = _user_config_path
1064-
elif _site_config_path.is_file():
1065-
ENV_CONF_FILE = _site_config_path
1061+
dbs_user_config = platformdirs.user_config_path("docsbuild-scripts")
1062+
dbs_site_config = platformdirs.site_config_path("docsbuild-scripts")
1063+
if dbs_user_config.is_file():
1064+
env_conf_file = dbs_user_config
1065+
elif dbs_site_config.is_file():
1066+
env_conf_file = dbs_site_config
10661067
else:
10671068
logging.info(
10681069
"No environment variables configured. "
1069-
f"Configure in {_site_config_path} or {_user_config_path}."
1070+
f"Configure in {dbs_site_config} or {dbs_user_config}."
10701071
)
10711072
return
10721073

1073-
logging.info(f"Reading environment variables from {ENV_CONF_FILE}.")
1074-
if ENV_CONF_FILE == _site_config_path:
1075-
logging.info(f"You can override settings in {_user_config_path}.")
1076-
elif _site_config_path.is_file():
1077-
logging.info(f"Overriding {_site_config_path}.")
1078-
with open(ENV_CONF_FILE, "r") as f:
1079-
for key, value in tomlkit.parse(f.read()).get("env", {}).items():
1080-
logging.debug(f"Setting {key} in environment.")
1081-
os.environ[key] = value
1074+
logging.info(f"Reading environment variables from {env_conf_file}.")
1075+
if env_conf_file == dbs_site_config:
1076+
logging.info(f"You can override settings in {dbs_user_config}.")
1077+
elif dbs_site_config.is_file():
1078+
logging.info(f"Overriding {dbs_site_config}.")
1079+
1080+
env_config = env_conf_file.read_text(encoding="utf-8")
1081+
for key, value in tomlkit.parse(env_config).get("env", {}).items():
1082+
logging.debug(f"Setting {key} in environment.")
1083+
os.environ[key] = value
10821084

10831085

10841086
def build_docs_with_lock(args: argparse.Namespace, lockfile_name: str) -> int:

tests/test_build_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.mark.parametrize(
7-
"seconds, expected",
7+
("seconds", "expected"),
88
[
99
(0.4, "0s"),
1010
(0.5, "0s"),

tests/test_build_docs_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from build_docs import Versions, Version
1+
from build_docs import Version, Versions
22

33

44
def test_filter_default() -> None:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy