Skip to content

Commit 1bbce7c

Browse files
committed
Instantiate config when needed and support optional env vars
1 parent 4e22ce8 commit 1bbce7c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

carbon/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class Config:
1818
"WORKSPACE",
1919
)
2020
OPTIONAL_ENVIRONMENT_VARIABLES: Iterable[str] = ("ARTICLES_PUBLISH_DAYS_PAST",)
21-
ARTICLES_PUBLISH_DAYS_PAST: str
21+
22+
ARTICLES_PUBLISH_DAYS_PAST: str | None = None
2223
FEED_TYPE: str
2324
CONNECTION_STRING: str
2425
SYMPLECTIC_FTP_USER: str

carbon/feed.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from abc import ABC, abstractmethod
32
from collections.abc import Generator
43
from contextlib import closing
@@ -17,8 +16,6 @@
1716
get_initials,
1817
)
1918

20-
config = Config()
21-
2219

2320
class BaseXmlFeed(ABC):
2421
"""Base XML feed class.
@@ -121,6 +118,8 @@ def query(self) -> Select: # type: ignore[override]
121118
be in the future, so an article may be included multiple times in the XML output
122119
until its future date has passed.
123120
"""
121+
config = Config()
122+
124123
query_object = (
125124
select(aa_articles)
126125
.where(aa_articles.c.ARTICLE_ID.is_not(None))
@@ -129,11 +128,11 @@ def query(self) -> Select: # type: ignore[override]
129128
.where(aa_articles.c.MIT_ID.is_not(None))
130129
)
131130

132-
if days_past := os.environ.get("ARTICLES_PUBLISH_DAYS_PAST"):
131+
if config.ARTICLES_PUBLISH_DAYS_PAST:
133132
query_object = query_object.where(
134133
text(
135134
"TO_DATE(PUBLISH_DATE, 'MM/DD/YYYY') >= "
136-
f"SYSDATE - {int(days_past)}"
135+
f"SYSDATE - {int(config.ARTICLES_PUBLISH_DAYS_PAST)}"
137136
)
138137
)
139138

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _test_env(ftp_server, monkeypatch):
4141
'"SYMPLECTIC_FTP_PASS": "pass"}'
4242
),
4343
)
44-
monkeypatch.delenv("ARTICLES_PUBLISH_DAYS_PAST")
44+
monkeypatch.delenv("ARTICLES_PUBLISH_DAYS_PAST", raising=False)
4545

4646

4747
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)