Skip to content

Commit cafd31b

Browse files
committed
Refactoring: uniform use of keyword cred_filepath
1 parent fe5a27b commit cafd31b

File tree

12 files changed

+59
-55
lines changed

12 files changed

+59
-55
lines changed

examples/create_page_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# Provide the information needed (only) to create the page package
4848
config = Package.CreationConfig(
4949
# Specify the path to the credentials file
50-
credentials_file_path=Path(__file__).parent / "accounts.pwd.yaml",
50+
cred_filepath=Path(__file__).parent / "accounts.pwd.yaml",
5151
# Specify the domain of the OSW/OSL instance to load pages from
5252
domain="wiki-dev.open-semantic-lab.org",
5353
# Specify the path to the working directory - where the package is stored on disk

examples/gui_local_slot_editing.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SETTINGS_FILE_PATH_DEFAULT = os.path.join(
3434
os.path.dirname(os.path.abspath(__file__)), "settings.json"
3535
)
36-
CREDENTIALS_FILE_PATH_DEFAULT = os.path.join(
36+
CRED_FILEPATH_DEFAULT = os.path.join(
3737
os.path.dirname(os.path.abspath(__file__)), "accounts.pwd.yaml"
3838
)
3939
PACKAGE_INFO_FILE_NAME = "packages.json"
@@ -144,7 +144,7 @@ def save_as_page_package(
144144
settings_read_from_file = True
145145
else:
146146
settings = {
147-
"credentials_file_path": str(CREDENTIALS_FILE_PATH_DEFAULT),
147+
"cred_filepath": str(CRED_FILEPATH_DEFAULT),
148148
"local_working_directory": str(LWD_DEFAULT),
149149
"settings_file_path": str(SETTINGS_FILE_PATH_DEFAULT),
150150
"target_page": TARGET_PAGE_DEFAULT,
@@ -156,17 +156,15 @@ def save_as_page_package(
156156
}
157157
settings_read_from_file = False
158158

159-
domains, accounts = read_domains_from_credentials_file(
160-
settings["credentials_file_path"]
161-
)
159+
domains, accounts = read_domains_from_credentials_file(settings["cred_filepath"])
162160
if "wiki-dev.open-semantic-lab.org" in domains:
163161
domain = "wiki-dev.open-semantic-lab.org"
164162
else:
165163
domain = domains[0]
166164
if settings_read_from_file:
167165
settings["domain"] = domain
168166

169-
cm = CredentialManager(cred_filepath=settings["credentials_file_path"])
167+
cm = CredentialManager(cred_filepath=settings["cred_filepath"])
170168
osw_obj = OswExpress(domain=domain, cred_mngr=cm)
171169
wtsite_obj = osw_obj.site
172170

@@ -215,7 +213,7 @@ def save_as_page_package(
215213
size=(50, 1),
216214
enable_events=True,
217215
key="-CREDENTIALS-",
218-
default_text=settings["credentials_file_path"],
216+
default_text=settings["cred_filepath"],
219217
),
220218
psg.FileBrowse(
221219
button_text="Browse", key="-BROWSE_CREDENTIALS-"
@@ -352,7 +350,7 @@ def save_as_page_package(
352350
with open(settings["settings_file_path"], "r") as f:
353351
settings = json.load(f)
354352
# update GUI
355-
window["-CREDENTIALS-"].update(settings["credentials_file_path"])
353+
window["-CREDENTIALS-"].update(settings["cred_filepath"])
356354
window["-LWD-"].update(settings["local_working_directory"])
357355
window["-DOMAIN-"].update(settings["domain"])
358356
window["-ADDRESS-"].update(settings["target_page"])
@@ -369,9 +367,9 @@ def save_as_page_package(
369367
with open(settings["settings_file_path"], "w") as f:
370368
json.dump(settings, f, indent=4)
371369
elif event == "-CREDENTIALS-":
372-
settings["credentials_file_path"] = values["-CREDENTIALS-"]
370+
settings["cred_filepath"] = values["-CREDENTIALS-"]
373371
domains, accounts = read_domains_from_credentials_file(
374-
settings["credentials_file_path"]
372+
settings["cred_filepath"]
375373
)
376374
window["-DOMAIN-"].update(values=domains)
377375
elif event == "-LWD-":

examples/inter_osw_copy_page.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
class OswInstance(OswBaseModel):
1616
domain: str
17-
cred_fp: Union[str, Path]
17+
cred_filepath: Union[str, Path]
1818
credentials_manager: Optional[CredentialManager]
1919
osw: Optional[OSW]
2020
wtsite: Optional[WtSite]
2121

2222
class Config:
2323
arbitrary_types_allowed = True
2424

25-
def __init__(self, domain: str, cred_fp: Union[str, Path]):
26-
super().__init__(**{"domain": domain, "cred_fp": cred_fp})
27-
self.credentials_manager = CredentialManager(cred_filepath=cred_fp)
25+
def __init__(self, domain: str, cred_filepath: Union[str, Path]):
26+
super().__init__(**{"domain": domain, "cred_filepath": cred_filepath})
27+
self.credentials_manager = CredentialManager(cred_filepath=cred_filepath)
2828
self.osw = OSW(
2929
site=WtSite(
3030
WtSite.WtSiteConfig(iri=domain, cred_mngr=self.credentials_manager)
@@ -115,20 +115,20 @@ def copy_pages_from(
115115
source_domain: str,
116116
to_target_domains: List[str],
117117
page_titles: List[str],
118-
cred_fp: Union[str, Path],
118+
cred_filepath: Union[str, Path],
119119
comment: str = None,
120120
overwrite: bool = False,
121121
):
122122
if comment is None:
123123
comment = f"[bot edit] Copied from {source_domain}"
124124
osw_source = OswInstance(
125125
domain=source_domain,
126-
cred_fp=cred_fp,
126+
cred_filepath=cred_filepath,
127127
)
128128
osw_targets = [
129129
OswInstance(
130130
domain=domain,
131-
cred_fp=cred_fp,
131+
cred_filepath=cred_filepath,
132132
)
133133
for domain in to_target_domains
134134
]
@@ -150,7 +150,7 @@ def copy_pages_from(
150150

151151

152152
if __name__ == "__main__":
153-
credentials_fp = Path(r"accounts.pwd.yaml")
153+
cred_filepath_ = Path(r"accounts.pwd.yaml")
154154
source = "onto-wiki.eu"
155155
targets = ["wiki-dev.open-semantic-lab.org"]
156156
titles = [
@@ -164,26 +164,26 @@ def copy_pages_from(
164164
source_domain=source,
165165
to_target_domains=targets,
166166
page_titles=titles,
167-
cred_fp=credentials_fp,
167+
cred_filepath=cred_filepath_,
168168
overwrite=True,
169169
)
170170
# Implementation within wtsite
171171
use_wtsite = True
172172
if use_wtsite:
173-
osw_source = OswInstance(
173+
osw_source_ = OswInstance(
174174
domain=source,
175-
cred_fp=credentials_fp,
175+
cred_filepath=cred_filepath_,
176176
)
177-
osw_targets = [
177+
osw_targets_ = [
178178
OswInstance(
179179
domain=target,
180-
cred_fp=credentials_fp,
180+
cred_filepath=cred_filepath_,
181181
)
182182
for target in targets
183183
]
184-
source_site = osw_source.wtsite
185-
target_sites = [osw_target.wtsite for osw_target in osw_targets]
186-
result = {}
184+
source_site = osw_source_.wtsite
185+
target_sites: List[WtSite] = [osw_target.wtsite for osw_target in osw_targets_]
186+
result_ = {}
187187
for target_site in target_sites:
188188
target = target_site.mw_site.host
189189
copied_pages = target_site.copy_pages(
@@ -194,4 +194,4 @@ def copy_pages_from(
194194
parallel=False,
195195
)
196196
)
197-
result[target] = copied_pages
197+
result_[target] = copied_pages

examples/settings.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"local_working_directory": "C:\\Users\\gold\\github\\osw-python\\data",
3-
"credentials_file_path": "C:/Users/gold/github/osw-python/examples/accounts.pwd.yaml",
3+
"cred_filepath": "C:/Users/gold/github/osw-python/examples/accounts.pwd.yaml",
44
"settings_file_path": "C:\\Users\\gold\\github\\osw-python\\examples\\settings.json",
55
"target_page": "https://wiki-dev.open-semantic-lab.org/wiki/Main_Page",
66
"namespace_as_folder": false,

examples/use_express_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# cred_filepath_default.set_default(r"C:\Users\gold\ownCloud\Personal\accounts.pwd.yaml")
1414

1515
# Check setting
16-
print(f"Credentials loaded from '{str(default_paths.cred_fp)}'")
16+
print(f"Credentials loaded from '{str(default_paths.cred_filepath)}'")
1717

1818
# The domain to connect to
1919
domain = "wiki-dev.open-semantic-lab.org"

src/osw/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(self, **data):
8585
if self.cred_filepath:
8686
if not isinstance(self.cred_filepath, list):
8787
self.cred_filepath = [self.cred_filepath]
88-
# Make sure to at least warn the user if they pass cred_fp instead of
88+
# Make sure to at least warn the user if they pass cred_filepath instead of
8989
# cred_filepath
9090
attribute_names = self.__dict__.keys()
9191
unexpected_kwargs = [key for key in data.keys() if key not in attribute_names]
@@ -257,7 +257,7 @@ def save_credentials_to_file(
257257
if filepath is None:
258258
cred_filepaths = self.cred_filepath
259259
if self.cred_filepath is None:
260-
cred_filepaths = [default_paths.cred_fp]
260+
cred_filepaths = [default_paths.cred_filepath]
261261
if set_cred_filepath:
262262
# Creates error if file does not exist -> Using custom FilePath
263263
self.cred_filepath = cred_filepaths

src/osw/controller/page_package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CreationConfig(OswBaseModel):
361361

362362
domain: str
363363
"""A string formatted as domain"""
364-
credentials_file_path: Union[str, FilePath]
364+
cred_filepath: Union[str, FilePath]
365365
"""Path to a existing credentials yaml files"""
366366
working_dir: Union[str, Path]
367367
"""Working directory. Will be created automatically if not existing."""
@@ -386,7 +386,7 @@ def create(
386386
WtSite.WtSiteConfig(
387387
iri=creation_config.domain,
388388
cred_mngr=CredentialManager(
389-
cred_filepath=creation_config.credentials_file_path
389+
cred_filepath=creation_config.cred_filepath
390390
),
391391
)
392392
)
@@ -676,7 +676,7 @@ def recursive(
676676
WtSite.WtSiteConfig(
677677
iri=params.creation_config.domain,
678678
cred_mngr=CredentialManager(
679-
cred_filepath=params.creation_config.credentials_file_path
679+
cred_filepath=params.creation_config.cred_filepath
680680
),
681681
)
682682
)

src/osw/data/import_utility.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def create_page_name_from_label(label: str) -> str:
758758
def get_entities_from_osw(
759759
category_to_search: Union[str, uuid_module.UUID],
760760
model_to_cast_to,
761-
credentials_fp,
761+
cred_filepath,
762762
domain,
763763
osw_obj: OSW = None,
764764
debug: bool = False,
@@ -773,8 +773,12 @@ def get_entities_from_osw(
773773
Category to search for.
774774
model_to_cast_to:
775775
Model to cast the entities to.
776-
credentials_fp:
776+
cred_filepath:
777777
Filepath to the credentials file, used to access the OSW instance.
778+
domain:
779+
Domain of the OSW instance.
780+
osw_obj:
781+
OSW instance to use. If None, a new instance is created.
778782
debug:
779783
If True, prints debug information.
780784
@@ -799,7 +803,7 @@ def test_if_empty_list_or_none(obj) -> bool:
799803
else: # elif isinstance(category_to_search, uuid_module.UUID):
800804
category_uuid = str(category_to_search)
801805
if osw_obj is None:
802-
cred_man = CredentialManager(cred_filepath=credentials_fp)
806+
cred_man = CredentialManager(cred_filepath=cred_filepath)
803807
osw_obj = OSW(site=WtSite(WtSite.WtSiteConfig(iri=domain, cred_mngr=cred_man)))
804808
wtsite_obj = osw_obj.site
805809
entities_from_osw = []
@@ -870,16 +874,16 @@ def create_full_page_title(
870874

871875
def translate_list_with_deepl(
872876
seq: list,
873-
credentials_file_path: Union[str, Path] = None,
877+
cred_filepath: Union[str, Path] = None,
874878
target_lang: str = "EN-US",
875879
translations: dict = None,
876880
) -> dict:
877881
"""Translates a list of strings with DeepL."""
878-
if credentials_file_path is None:
879-
credentials_file_path = default_paths.cred_fp
882+
if cred_filepath is None:
883+
cred_filepath = default_paths.cred_filepath
880884
if translations is None:
881885
translations = {}
882-
domains, accounts = wt.read_domains_from_credentials_file(credentials_file_path)
886+
domains, accounts = wt.read_domains_from_credentials_file(cred_filepath)
883887
domain = "api-free.deepl.com"
884888
auth = accounts[domain]["password"]
885889
translator = deepl.Translator(auth)

src/osw/defaults.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
BASE_PATH = Path.cwd()
1313
OSW_FILES_DIR_DEFAULT = BASE_PATH / "osw_files"
1414
DOWNLOAD_DIR_DEFAULT = OSW_FILES_DIR_DEFAULT / "downloads"
15-
CREDENTIALS_FN_DEFAULT = "credentials.pwd.yaml"
16-
CREDENTIALS_FP_DEFAULT = OSW_FILES_DIR_DEFAULT / CREDENTIALS_FN_DEFAULT
15+
CRED_FILENAME_DEFAULT = "credentials.pwd.yaml"
16+
CRED_FILEPATH_DEFAULT = OSW_FILES_DIR_DEFAULT / CRED_FILENAME_DEFAULT
1717
WIKI_DOMAIN_DEFAULT = "wiki.open-semantic-lab.org"
1818

1919

@@ -62,9 +62,9 @@ class Paths(OswBaseModel):
6262
osw_files_dir: Path = OSW_FILES_DIR_DEFAULT
6363
"""If you want to specify the default OSW files directory, use
6464
Path.osw_files_dir = new_path."""
65-
cred_fp: Path = CREDENTIALS_FP_DEFAULT
65+
cred_filepath: Path = CRED_FILEPATH_DEFAULT
6666
"""If you want to specify the saving location of the credentials file, use
67-
Path.cred_fp = new_path."""
67+
Path.cred_filepath = new_path."""
6868
download_dir: Path = DOWNLOAD_DIR_DEFAULT
6969
"""If you want to specify the default download directory, use
7070
Path.download_dir = new_path."""
@@ -119,13 +119,13 @@ def update_attr(set_attr, to_update, old_val, new_val):
119119
if attr_name == "base":
120120
update_attr(
121121
"base",
122-
["osw_files_dir", "cred_fp", "download_dir"],
122+
["osw_files_dir", "cred_filepath", "download_dir"],
123123
old_value,
124124
new_value,
125125
)
126126
elif attr_name == "osw_files_dir":
127127
update_attr(
128-
"osw_files_dir", ["cred_fp", "download_dir"], old_value, new_value
128+
"osw_files_dir", ["cred_filepath", "download_dir"], old_value, new_value
129129
)
130130

131131

src/osw/express.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
cred_mngr: CredentialManager = None,
7272
):
7373
if cred_filepath is None:
74-
cred_filepath = default_paths.cred_fp
74+
cred_filepath = default_paths.cred_filepath
7575
if cred_mngr is not None:
7676
if cred_mngr.cred_filepath is not None:
7777
cred_filepath = cred_mngr.cred_filepath[0]
@@ -381,7 +381,9 @@ def import_with_fallback(
381381
domain = input("Please enter the domain of the OSW instance to connect to:")
382382
if domain == "" or domain is None:
383383
domain = default_params.wiki_domain
384-
osw_express = OswExpress(domain=domain, cred_filepath=default_paths.cred_fp)
384+
osw_express = OswExpress(
385+
domain=domain, cred_filepath=default_paths.cred_filepath
386+
)
385387

386388
osw_express.install_dependencies(dependencies, mode="append")
387389
osw_express.shut_down() # Avoiding connection error
@@ -523,7 +525,7 @@ def process_init_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
523525
# set by the source file controller
524526
del data["label"]
525527
if data.get("cred_filepath") is None:
526-
data["cred_filepath"] = default_paths.cred_fp
528+
data["cred_filepath"] = default_paths.cred_filepath
527529
if not data.get("cred_filepath").parent.exists():
528530
data["cred_filepath"].parent.mkdir(parents=True)
529531
if data.get("cred_mngr") is None:

0 commit comments

Comments
 (0)