Skip to content

Commit 48738fb

Browse files
committed
Fix: Uniform use of OSW_DOMAIN or OSL_DOMAIN instead of OSW_WIKI_DOMAIN and OSL_WIKI_DOMAIN
1 parent 0f2fb5f commit 48738fb

5 files changed

Lines changed: 41 additions & 44 deletions

File tree

examples/.env_example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
OSW_WIKI_DOMAIN=wiki-dev.open-semantic-lab.org
1+
OSW_DOMAIN=wiki-dev.open-semantic-lab.org
22
OSW_CRED_FILEPATH=/path/to/credentials/file
33
OSW_DOWNLOAD_DIR=/path/to/download/directory

examples/use_express_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
dotenv.load_dotenv() # will look for a .env file in CWD and above
1010

1111
# (Alternative) Setting the domain of the wiki to connect to
12-
os.environ["OSW_WIKI_DOMAIN"] = "wiki-dev.open-semantic-lab.org"
12+
os.environ["OSW_DOMAIN"] = "wiki-dev.open-semantic-lab.org"
1313
# (Optional) Set the default credentials filepath to desired location. Otherwise,
1414
# it will use the default location (current working directory)
1515
os.environ["OSW_CRED_FILEPATH"] = str(

src/osw/express.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
55
This module expects environment variables to be set and available, e.g. through
66
dotenv.load_dotenv()
7-
- OSW_WIKI_DOMAIN: domain of the OSL instance to connect to
8-
- OSW_CRED_FILEPATH: filepath to the credential file, if not specified the default
9-
file path based on current working directory will be used
10-
- OSW_DOWNLOAD_DIR: directory to download files, if not specified the default
11-
directory based on the current working directory will be used
7+
- OSW_DOMAIN: domain of the OSL instance to connect to
8+
- OSW_CRED_FILEPATH: filepath to the credential file, otherwise falls back to the
9+
default file path, which is based on current working directory
10+
- OSW_DOWNLOAD_DIR: directory to download files, otherwise falls back to the default
11+
directory, which is based on the current working directory
1212
"""
1313

1414
import importlib.util
@@ -98,10 +98,10 @@ def __init__(
9898
cred_mngr: CredentialManager = None,
9999
):
100100
if domain is None:
101-
if os.getenv("OSW_WIKI_DOMAIN") is not None:
102-
domain = os.getenv("OSW_WIKI_DOMAIN")
103-
elif os.getenv("OSL_WIKI_DOMAIN") is not None:
104-
domain = os.getenv("OSL_WIKI_DOMAIN")
101+
if os.getenv("OSW_DOMAIN") is not None:
102+
domain = os.getenv("OSW_DOMAIN")
103+
elif os.getenv("OSL_DOMAIN") is not None:
104+
domain = os.getenv("OSL_DOMAIN")
105105
else:
106106
raise TypeError(
107107
"The constructor of OswExpress is missing 1 required positional "
@@ -336,7 +336,7 @@ class FileResult(OswBaseModel):
336336
domain: Optional[str] = None
337337
"""The domain of the OSL instance to download the file from. Required if
338338
urL_or_title is a full page title and the domain is not set in the environment
339-
variable 'OSW_WIKI_DOMAIN'. If None the domain is parsed from the URL."""
339+
variable 'OSW_DOMAIN'. If None the domain is parsed from the URL."""
340340
cred_filepath: Optional[Union[str, Path]] = None
341341
"""The filepath to the credentials file. Will only be used if cred_mngr is
342342
None. If cred_filepath is None, a credentials file named 'accounts.pwd.yaml' is
@@ -491,10 +491,10 @@ def __init__(self, url_or_title, **data):
491491
string=url_or_title,
492492
)
493493
if match is None:
494-
if os.getenv("OSW_WIKI_DOMAIN") is not None:
495-
data["domain"] = os.getenv("OSW_WIKI_DOMAIN")
496-
elif os.getenv("OSL_WIKI_DOMAIN") is not None:
497-
data["domain"] = os.getenv("OSL_WIKI_DOMAIN")
494+
if os.getenv("OSW_DOMAIN") is not None:
495+
data["domain"] = os.getenv("OSW_DOMAIN")
496+
elif os.getenv("OSL_DOMAIN") is not None:
497+
data["domain"] = os.getenv("OSL_DOMAIN")
498498
else:
499499
raise ValueError(
500500
f"Could not parse domain from URL: {url_or_title}. "
@@ -574,7 +574,7 @@ def osw_download_file(
574574
domain
575575
The domain of the OSL instance to download the file from. Required if
576576
urL_or_title is a full page title and the domain is not set in the environment
577-
variable 'OSW_WIKI_DOMAIN'. If None the domain is parsed from the URL.
577+
variable 'OSW_DOMAIN'. If None the domain is parsed from the URL.
578578
cred_filepath
579579
The filepath to the credentials file. Will only be used if cred_mngr is
580580
None. If cred_filepath is None, a credentials file named 'accounts.pwd.yaml'
@@ -695,9 +695,7 @@ def __init__(
695695
if match is not None:
696696
data["domain"] = match.group(1)
697697
else:
698-
data["domain"] = os.getenv("OSW_WIKI_DOMAIN") or os.getenv(
699-
"OSL_WIKI_DOMAIN"
700-
)
698+
data["domain"] = os.getenv("OSW_DOMAIN") or os.getenv("OSL_DOMAIN")
701699
else:
702700
if match is not None:
703701
if not data.get("domain") == match.group(1):
@@ -964,10 +962,10 @@ def import_with_fallback(
964962
# todo: should this be taken from globals?
965963
# If the user has set the default domain, use it
966964
if domain is None:
967-
if os.getenv("OSW_WIKI_DOMAIN") is not None:
968-
domain = os.getenv("OSW_WIKI_DOMAIN")
969-
elif os.getenv("OSL_WIKI_DOMAIN") is not None:
970-
domain = os.getenv("OSL_WIKI_DOMAIN")
965+
if os.getenv("OSW_DOMAIN") is not None:
966+
domain = os.getenv("OSW_DOMAIN")
967+
elif os.getenv("OSL_DOMAIN") is not None:
968+
domain = os.getenv("OSL_DOMAIN")
971969
elif default_params.has_changed("wiki_domain"):
972970
domain = default_params.wiki_domain
973971
else:

tests/integration/test_express.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_init_from_env_vars(wiki_domain, wiki_username, wiki_password):
9595
cred_filepath = Path.cwd() / "accounts.pwd.yaml"
9696
os.environ["OSW_CRED_FILEPATH"] = str(cred_filepath)
9797
create_credentials_file(cred_filepath, wiki_domain, wiki_username, wiki_password)
98-
os.environ["OSW_WIKI_DOMAIN"] = wiki_domain
98+
os.environ["OSW_DOMAIN"] = wiki_domain
9999

100100
osw_express = osw.express.OswExpress()
101101
osw_express_and_credentials(osw_express, wiki_domain, wiki_username, wiki_password)

tests/integration/test_express_init.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def clean_env_vars(*var_names):
7070

7171

7272
ENV_VARS = [
73-
"OSW_WIKI_DOMAIN",
74-
"OSL_WIKI_DOMAIN",
73+
"OSW_DOMAIN",
74+
"OSL_DOMAIN",
7575
"OSW_CRED_FILEPATH",
7676
"OSL_CRED_FILEPATH",
7777
]
@@ -186,13 +186,12 @@ class TestInitEnvVarPriority:
186186
"""Test that OSW_* env vars take priority over OSL_* env vars."""
187187

188188
def test_osw_domain_takes_priority_over_osl(self, mocker):
189-
"""When both OSW_WIKI_DOMAIN and OSL_WIKI_DOMAIN are set,
190-
OSW_WIKI_DOMAIN should be used."""
189+
"""When both OSW_DOMAIN and OSL_DOMAIN are set, OSW_DOMAIN should be used."""
191190
with clean_env_vars(*ENV_VARS):
192191
osw_domain = "osw.example.com"
193192
osl_domain = "osl.example.com"
194-
os.environ["OSW_WIKI_DOMAIN"] = osw_domain
195-
os.environ["OSL_WIKI_DOMAIN"] = osl_domain
193+
os.environ["OSW_DOMAIN"] = osw_domain
194+
os.environ["OSL_DOMAIN"] = osl_domain
196195

197196
cred_filepath = Path.cwd() / "test_priority_accounts.pwd.yaml"
198197
create_credentials_file(cred_filepath, osw_domain, "user", "pass")
@@ -213,10 +212,10 @@ def test_osw_domain_takes_priority_over_osl(self, mocker):
213212
cred_filepath.unlink()
214213

215214
def test_osl_domain_used_when_osw_absent(self, mocker):
216-
"""When only OSL_WIKI_DOMAIN is set, it should be used."""
215+
"""When only OSL_DOMAIN is set, it should be used."""
217216
with clean_env_vars(*ENV_VARS):
218217
osl_domain = "osl.example.com"
219-
os.environ["OSL_WIKI_DOMAIN"] = osl_domain
218+
os.environ["OSL_DOMAIN"] = osl_domain
220219

221220
cred_filepath = Path.cwd() / "test_osl_accounts.pwd.yaml"
222221
create_credentials_file(cred_filepath, osl_domain, "user", "pass")
@@ -239,7 +238,7 @@ def test_osw_cred_filepath_takes_priority_over_osl(self, mocker):
239238
OSW_CRED_FILEPATH should be used."""
240239
with clean_env_vars(*ENV_VARS):
241240
domain = "priority.example.com"
242-
os.environ["OSW_WIKI_DOMAIN"] = domain
241+
os.environ["OSW_DOMAIN"] = domain
243242

244243
osw_cred_fp = Path.cwd() / "test_osw_cred.pwd.yaml"
245244
osl_cred_fp = Path.cwd() / "test_osl_cred.pwd.yaml"
@@ -336,7 +335,7 @@ def test_live_init_from_osl_env_vars(
336335
create_credentials_file(
337336
cred_filepath, wiki_domain, wiki_username, wiki_password
338337
)
339-
os.environ["OSL_WIKI_DOMAIN"] = wiki_domain
338+
os.environ["OSL_DOMAIN"] = wiki_domain
340339
os.environ["OSL_CRED_FILEPATH"] = str(cred_filepath)
341340

342341
try:
@@ -566,9 +565,9 @@ def test_domain_parsed_from_url(self, tmp_path, mocker):
566565
assert result.domain == "wiki.example.com"
567566

568567
def test_domain_from_osw_env_var(self, tmp_path, mocker):
569-
"""When url_or_title is a title and OSW_WIKI_DOMAIN is set."""
568+
"""When url_or_title is a title and OSW_DOMAIN is set."""
570569
with clean_env_vars(*self.DOWNLOAD_ENV_VARS):
571-
os.environ["OSW_WIKI_DOMAIN"] = "env.example.com"
570+
os.environ["OSW_DOMAIN"] = "env.example.com"
572571
mock_osw, cred_fp = self._make_download_mocks(mocker, tmp_path)
573572
target_fp = tmp_path / "SomeFile.txt"
574573
result = DownloadFileResult(
@@ -580,9 +579,9 @@ def test_domain_from_osw_env_var(self, tmp_path, mocker):
580579
assert result.domain == "env.example.com"
581580

582581
def test_domain_from_osl_env_var(self, tmp_path, mocker):
583-
"""When url_or_title is a title and only OSL_WIKI_DOMAIN is set."""
582+
"""When url_or_title is a title and only OSL_DOMAIN is set."""
584583
with clean_env_vars(*self.DOWNLOAD_ENV_VARS):
585-
os.environ["OSL_WIKI_DOMAIN"] = "osl-env.example.com"
584+
os.environ["OSL_DOMAIN"] = "osl-env.example.com"
586585
mock_osw, cred_fp = self._make_download_mocks(mocker, tmp_path)
587586
target_fp = tmp_path / "SomeFile.txt"
588587
result = DownloadFileResult(
@@ -596,7 +595,7 @@ def test_domain_from_osl_env_var(self, tmp_path, mocker):
596595
def test_target_dir_from_osw_env_var(self, tmp_path, mocker):
597596
"""When OSW_DOWNLOAD_DIR is set, it should be used as target_dir."""
598597
with clean_env_vars(*self.DOWNLOAD_ENV_VARS):
599-
os.environ["OSW_WIKI_DOMAIN"] = "env.example.com"
598+
os.environ["OSW_DOMAIN"] = "env.example.com"
600599
download_dir = str(tmp_path / "downloads")
601600
os.environ["OSW_DOWNLOAD_DIR"] = download_dir
602601
mock_osw, cred_fp = self._make_download_mocks(mocker, tmp_path)
@@ -610,7 +609,7 @@ def test_target_dir_from_osw_env_var(self, tmp_path, mocker):
610609
def test_target_dir_from_osl_env_var(self, tmp_path, mocker):
611610
"""When only OSL_DOWNLOAD_DIR is set, it should be used."""
612611
with clean_env_vars(*self.DOWNLOAD_ENV_VARS):
613-
os.environ["OSW_WIKI_DOMAIN"] = "env.example.com"
612+
os.environ["OSW_DOMAIN"] = "env.example.com"
614613
download_dir = str(tmp_path / "osl_downloads")
615614
os.environ["OSL_DOWNLOAD_DIR"] = download_dir
616615
mock_osw, cred_fp = self._make_download_mocks(mocker, tmp_path)
@@ -642,7 +641,7 @@ def test_use_cached_with_existing_file(self, tmp_path):
642641
def test_target_fn_derived_from_title(self, tmp_path, mocker):
643642
"""The target filename should be derived from the title after 'File:'."""
644643
with clean_env_vars(*self.DOWNLOAD_ENV_VARS):
645-
os.environ["OSW_WIKI_DOMAIN"] = "env.example.com"
644+
os.environ["OSW_DOMAIN"] = "env.example.com"
646645
mock_osw, cred_fp = self._make_download_mocks(mocker, tmp_path)
647646
result = DownloadFileResult(
648647
url_or_title="File:MyDocument.pdf",
@@ -977,7 +976,7 @@ class TestUploadDomainFromEnv:
977976

978977
def test_domain_from_env_when_title_only(self, tmp_path, mocker):
979978
with clean_env_vars(*ENV_VARS):
980-
os.environ["OSW_WIKI_DOMAIN"] = "env-upload.example.com"
979+
os.environ["OSW_DOMAIN"] = "env-upload.example.com"
981980

982981
source_file = tmp_path / "env_domain.txt"
983982
source_file.write_text("data")
@@ -1223,7 +1222,7 @@ def test_live_fallback_fetches_from_wiki(
12231222
)
12241223
try:
12251224
with clean_env_vars(*ENV_VARS):
1226-
os.environ["OSW_WIKI_DOMAIN"] = wiki_domain
1225+
os.environ["OSW_DOMAIN"] = wiki_domain
12271226
os.environ["OSW_CRED_FILEPATH"] = str(cred_filepath)
12281227

12291228
with preserve_entity_py_state():

0 commit comments

Comments
 (0)