Skip to content

Commit

Permalink
config: allow libraries in default-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed May 19, 2024
1 parent 2aa65d5 commit dbe1e7e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions papis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,10 @@ def get_lib_from_name(libname: str) -> papis.library.Library:
to an existing folder that should be considered a library.
"""
config = get_configuration()
default_settings = get_default_settings()
libs = get_libs_from_config(config)

if libname not in config:
if libname not in libs:
if os.path.isdir(libname):
logger.warning("Setting path '%s' as the main library folder.", libname)

Expand All @@ -579,6 +581,9 @@ def get_lib_from_name(libname: str) -> papis.library.Library:
f"\tdir = path/to/your/{libname}/folder"
)
else:
if libname in default_settings and libname not in config:
config[libname] = default_settings[libname]

try:
# NOTE: can't use `getstring(...)` due to cyclic dependency
paths = [os.path.expanduser(config[libname]["dir"])]
Expand Down Expand Up @@ -658,7 +663,14 @@ def get_libs_from_config(config: Configuration) -> List[str]:
if "dir" in sec or "dirs" in sec:
libs.append(section)

return libs
# NOTE: also look through default settings in case they were registered
# in `config.py` using `register_default_settings`.
default_settings = get_default_settings()
for name, values in default_settings.items():
if "dir" in values or "dirs" in values:
libs.append(name)

return sorted(frozenset(libs))


def reset_configuration() -> Configuration:
Expand Down

0 comments on commit dbe1e7e

Please sign in to comment.