|
22 | 22 | from keyring.errors import NoKeyringError |
23 | 23 |
|
24 | 24 | # Local |
| 25 | +from redfetch import config |
25 | 26 | from redfetch import net |
26 | 27 |
|
27 | 28 | # Constants |
|
38 | 39 |
|
39 | 40 |
|
40 | 41 | def _get_setting(key: str, default=None): |
41 | | - """Get a setting from env first, then Dynaconf (if initialized).""" |
| 42 | + """Get a setting from env first, then initialized Dynaconf settings.""" |
42 | 43 | env_key = f"REDFETCH_{key}" |
43 | 44 | env_val = os.environ.get(env_key) |
44 | 45 | if env_val not in (None, ""): |
45 | 46 | return env_val |
46 | 47 |
|
47 | | - try: |
48 | | - from redfetch import config |
49 | | - |
50 | | - settings = getattr(config, "settings", None) |
51 | | - if settings is not None: |
52 | | - val = settings.get(key, default) |
53 | | - return default if val in ("", None) else val |
54 | | - except Exception: |
55 | | - pass |
| 48 | + if config.settings is not None: |
| 49 | + val = config.settings.get(key, default) |
| 50 | + return default if val in ("", None) else val |
56 | 51 |
|
57 | 52 | return default |
58 | 53 |
|
@@ -391,12 +386,8 @@ def initialize_keyring(): |
391 | 386 |
|
392 | 387 | if __name__ == "__main__": |
393 | 388 | initialize_keyring() |
394 | | - # Initialize config lazily if invoked directly, so this can be used as a standalone script. |
395 | | - try: |
396 | | - from redfetch import config |
397 | | - |
398 | | - if getattr(config, "settings", None) is None: |
| 389 | + if not os.environ.get("REDGUIDES_API_KEY"): |
| 390 | + # Initialize config lazily if invoked directly, so this can be used as a standalone script. |
| 391 | + if config.settings is None: |
399 | 392 | config.initialize_config() |
400 | | - except Exception: |
401 | | - pass |
402 | 393 | authorize() |
0 commit comments