|
65 | 65 | from urllib.parse import urljoin |
66 | 66 |
|
67 | 67 | import jinja2 |
| 68 | +import platformdirs |
68 | 69 | import tomlkit |
69 | 70 | import urllib3 |
70 | 71 | import zc.lockfile |
71 | | -from platformdirs import user_config_path, site_config_path |
72 | 72 |
|
73 | 73 | TYPE_CHECKING = False |
74 | 74 | if TYPE_CHECKING: |
75 | 75 | from collections.abc import Collection, Iterator, Sequence, Set |
76 | 76 | from typing import Literal |
77 | 77 |
|
78 | 78 | 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 |
80 | 81 | except ImportError: |
81 | 82 | EX_OK, EX_FAILURE = 0, 1 |
82 | 83 |
|
@@ -279,7 +280,7 @@ def filter(self, language_tags: Sequence[str] = ()) -> Sequence[Language]: |
279 | 280 | """Filter a sequence of languages according to --languages.""" |
280 | 281 | if language_tags: |
281 | 282 | 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 |
283 | 284 | return list(self) |
284 | 285 |
|
285 | 286 |
|
@@ -480,7 +481,7 @@ def setup_switchers(versions: Versions, languages: Languages, html_root: Path) - |
480 | 481 | - Cross-link various languages in a language switcher |
481 | 482 | - Cross-link various versions in a version switcher |
482 | 483 | """ |
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 |
484 | 485 | version_pairs = [(v.name, v.picker_label) for v in reversed(versions)] |
485 | 486 |
|
486 | 487 | switchers_template_file = HERE / "templates" / "switchers.js" |
@@ -1057,28 +1058,29 @@ def setup_logging(log_directory: Path, select_output: str | None) -> None: |
1057 | 1058 |
|
1058 | 1059 |
|
1059 | 1060 | 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 |
1066 | 1067 | else: |
1067 | 1068 | logging.info( |
1068 | 1069 | "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}." |
1070 | 1071 | ) |
1071 | 1072 | return |
1072 | 1073 |
|
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 |
1082 | 1084 |
|
1083 | 1085 |
|
1084 | 1086 | def build_docs_with_lock(args: argparse.Namespace, lockfile_name: str) -> int: |
|
0 commit comments