Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: allow libraries in default-settings #855

Merged
merged 1 commit into from
May 21, 2024

Conversation

alexfikl
Copy link
Collaborator

@alexfikl alexfikl commented May 19, 2024

This should allow setting libraries in config.py using register_default_settings dynamically. Something like this should now work as expected

import pathlib

from papis.config import register_default_settings

basedir = pathlib.Path('/home/user/Documents')
register_default_settings({
    **{subdir.stem: {'dir': str(subdir)} for subdir in basedir.glob('[a-z]*/')},
	**{"settings": {"default-library": "lib1"}}
    })

xref: #851

@alexfikl
Copy link
Collaborator Author

@octvs In case you have the git version of papis available, it would be great if you get a chance to test this!

@octvs
Copy link

octvs commented May 19, 2024

Just gave it a try with my original config files, however when I execute

$ papis -l INFO --pick-lib open

to see which libraries have been registered, I see the library defined as
default-library on [settings] section duplicated. Which justifies the
following block from your snippet:

if libname not in self:
    self.add_section(libname)

I will check the API doc to see whether I can refer back to already registered
libs on ConfigParser, which would let me include a similar check in a less
hacky way.

@alexfikl
Copy link
Collaborator Author

alexfikl commented May 19, 2024

to see which libraries have been registered, I see the library defined as default-library on [settings] section duplicated.

@octvs Oops, nice catch! That should be fixed in the latest version.

I went with the following choice: if the library is defined in the static config file, it takes priority over a library with the same name defined in config.py using papis.config.register_default_settings.

@octvs
Copy link

octvs commented May 21, 2024 via email

@alexfikl
Copy link
Collaborator Author

I wonder if this should be documented somewhere.

Yeah, it really should! I've opened an issue to improve the documentation for config.py, since at the moment it's pretty much non-existent.

Thanks for all the testing and help with this! In it goes! 🚀

@alexfikl alexfikl merged commit 2230fbb into papis:main May 21, 2024
19 checks passed
@alexfikl alexfikl deleted the allow-configpy-libs branch May 21, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants