|
5 | 5 | Without any arguments builds docs for all active versions and
|
6 | 6 | languages.
|
7 | 7 |
|
| 8 | +Environment variables for: |
| 9 | + - SENTRY_DSN (Error reporting) |
| 10 | + - FASTLY_SERVICE_ID/FASTLY_TOKEN (CDN purges) |
| 11 | + - PYTHON_DOCS_ENABLE_ANALYTICS (enable plausible for online docs) |
| 12 | +are read from the site configuration path for your platform |
| 13 | +(/etc/xdg/docsbuild-scripts on linux) if available, |
| 14 | +and can be overriden by writing a file to the user config dir |
| 15 | +for your platform ($HOME/.config/docsbuild-scripts on linux). |
| 16 | +The contents of the file is parsed as toml: |
| 17 | +
|
| 18 | +[env] |
| 19 | +SENTRY_DSN = "https://[email protected]/69420" |
| 20 | +FASTLY_SERVICE_ID = "deadbeefdeadbeefdead" |
| 21 | +FASTLY_TOKEN = "secureme!" |
| 22 | +PYTHON_DOCS_ENABLE_ANALYTICS = "1" |
| 23 | +
|
8 | 24 | Languages are stored in `config.toml` while versions are discovered
|
9 | 25 | from the devguide.
|
10 | 26 |
|
|
48 | 64 | import tomlkit
|
49 | 65 | import urllib3
|
50 | 66 | import zc.lockfile
|
| 67 | +from platformdirs import user_config_path, site_config_path |
| 68 | + |
| 69 | +ENV_CONF_FILE = None |
| 70 | +_user_config_path = user_config_path("docsbuild-scripts") |
| 71 | +_site_config_path = site_config_path("docsbuild-scripts") |
| 72 | +if _user_config_path.is_file(): |
| 73 | + ENV_CONF_FILE = _user_config_path |
| 74 | +elif _site_config_path.is_file(): |
| 75 | + ENV_CONF_FILE = _site_config_path |
| 76 | + |
| 77 | +if ENV_CONF_FILE: |
| 78 | + print(f"Reading environment variables from {ENV_CONF_FILE}") |
| 79 | + if ENV_CONF_FILE == _site_config_path: |
| 80 | + print(f"You can override settings in {_user_config_path}") |
| 81 | + elif _site_config_path.is_file(): |
| 82 | + print(f"Overriding {_site_config_path}") |
| 83 | + with open(ENV_CONF_FILE, "r") as f: |
| 84 | + for key, value in tomlkit.parse(f.read()).get("env", {}).items(): |
| 85 | + print(f"Setting {key} in environment") |
| 86 | + os.environ[key] = value |
| 87 | +else: |
| 88 | + print( |
| 89 | + "No environment variables configured. " |
| 90 | + f"Configure in {_site_config_path} or {_user_config_path}" |
| 91 | + ) |
51 | 92 |
|
52 | 93 | TYPE_CHECKING = False
|
53 | 94 | if TYPE_CHECKING:
|
|
0 commit comments