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 6175052
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion 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,6 +663,13 @@ def get_libs_from_config(config: Configuration) -> List[str]:
if "dir" in sec or "dirs" in sec:
libs.append(section)

# 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, section in default_settings.items():
if "dir" in section or "dirs" in section:
libs.append(name)

return libs


Expand Down

0 comments on commit 6175052

Please sign in to comment.