Skip to content

Commit cd081de

Browse files
committed
move configuration handling into main, for logging
1 parent 6325e5c commit cd081de

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

build_docs.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,6 @@
7070
import zc.lockfile
7171
from platformdirs import user_config_path, site_config_path
7272

73-
ENV_CONF_FILE = None
74-
_user_config_path = user_config_path("docsbuild-scripts")
75-
_site_config_path = site_config_path("docsbuild-scripts")
76-
if _user_config_path.is_file():
77-
ENV_CONF_FILE = _user_config_path
78-
elif _site_config_path.is_file():
79-
ENV_CONF_FILE = _site_config_path
80-
81-
if ENV_CONF_FILE:
82-
print(f"Reading environment variables from {ENV_CONF_FILE}")
83-
if ENV_CONF_FILE == _site_config_path:
84-
print(f"You can override settings in {_user_config_path}")
85-
elif _site_config_path.is_file():
86-
print(f"Overriding {_site_config_path}")
87-
with open(ENV_CONF_FILE, "r") as f:
88-
for key, value in tomlkit.parse(f.read()).get("env", {}).items():
89-
print(f"Setting {key} in environment")
90-
os.environ[key] = value
91-
else:
92-
print(
93-
"No environment variables configured. "
94-
f"Configure in {_site_config_path} or {_user_config_path}"
95-
)
96-
9773
TYPE_CHECKING = False
9874
if TYPE_CHECKING:
9975
from collections.abc import Iterator, Sequence, Set
@@ -952,6 +928,30 @@ def main():
952928
args = parse_args()
953929
setup_logging(args.log_directory, args.select_output)
954930

931+
ENV_CONF_FILE = None
932+
_user_config_path = user_config_path("docsbuild-scripts")
933+
_site_config_path = site_config_path("docsbuild-scripts")
934+
if _user_config_path.is_file():
935+
ENV_CONF_FILE = _user_config_path
936+
elif _site_config_path.is_file():
937+
ENV_CONF_FILE = _site_config_path
938+
939+
if ENV_CONF_FILE:
940+
logging.info(f"Reading environment variables from {ENV_CONF_FILE}")
941+
if ENV_CONF_FILE == _site_config_path:
942+
logging.info(f"You can override settings in {_user_config_path}")
943+
elif _site_config_path.is_file():
944+
logging.info(f"Overriding {_site_config_path}")
945+
with open(ENV_CONF_FILE, "r") as f:
946+
for key, value in tomlkit.parse(f.read()).get("env", {}).items():
947+
logging.debug(f"Setting {key} in environment")
948+
os.environ[key] = value
949+
else:
950+
logging.info(
951+
"No environment variables configured. "
952+
f"Configure in {_site_config_path} or {_user_config_path}"
953+
)
954+
955955
if args.select_output is None:
956956
build_docs_with_lock(args, "build_docs.lock")
957957
elif args.select_output == "no-html":

0 commit comments

Comments
 (0)