|
70 | 70 | import zc.lockfile
|
71 | 71 | from platformdirs import user_config_path, site_config_path
|
72 | 72 |
|
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 |
| - |
97 | 73 | TYPE_CHECKING = False
|
98 | 74 | if TYPE_CHECKING:
|
99 | 75 | from collections.abc import Iterator, Sequence, Set
|
@@ -952,6 +928,30 @@ def main():
|
952 | 928 | args = parse_args()
|
953 | 929 | setup_logging(args.log_directory, args.select_output)
|
954 | 930 |
|
| 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 | + |
955 | 955 | if args.select_output is None:
|
956 | 956 | build_docs_with_lock(args, "build_docs.lock")
|
957 | 957 | elif args.select_output == "no-html":
|
|
0 commit comments