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

NF: register_config() #6601

Merged
merged 6 commits into from
Apr 4, 2022
Merged

NF: register_config() #6601

merged 6 commits into from
Apr 4, 2022

Conversation

mih
Copy link
Member

@mih mih commented Mar 30, 2022

This PR requires and sits on top of #6594. The first commit is not unique to this PR.

This also replaces the previously very flexible data structure for such items with a more rigid set of classes that implement lazy evaluation of defaults (avoiding their possibly expensive computation, even when they are not actually needed). They otherwise implement all elements of the previously used API, such that they work as a drop-in replacement.

Only register_config() (and its friend has_config() is intended to be used publicly. Like so:

from datalad.support.extensions import register_config
register_config(
    'datalad.mihextras.blows',
    title="Does it?",
    default=True,
    scope='global',
    type=bool,
    description="I could tell you, but I won't!",
)

Changelog

💫 Enhancements and new features

@yarikoptic
Copy link
Member

+1 on register_config since in-line with what I was looking after in #6314 . I would only also "expose" it within some centralized datalad.support.extensions module.

This PR requires and sits on top of #6594.

but in principle this functionality is not needing #6594, right? i.e. extension can only define config variable it uses, thus would need to be imported by then one way (as via datalad.api or CLI) or another (the #6594), most likely using that register_config within that extension's __init__.py, correct?

@bpoldrack
Copy link
Member

This PR is currently in draft mode to gather feedback on the API, before tests are added.

Feedback: I like it.

@mih
Copy link
Member Author

mih commented Mar 30, 2022

Can be seen in action here: https://github.com/datalad/datalad-next/blob/master/datalad_next/__init__.py (running across platforms)

@mih
Copy link
Member Author

mih commented Mar 30, 2022

This PR requires and sits on top of #6594.

but in principle this functionality is not needing #6594, right? i.e. extension can only define config variable it uses, thus would need to be imported by then one way (as via datalad.api or CLI) or another (the #6594), most likely using that register_config within that extension's __init__.py, correct?

#6594 is already needed to give the configuration command the chance to see such definitions.

Performance impact when this feature is unused is negligible. Otherwise
it is determined by the import time of a particular extensions
`__init__.py`.

Fixes #datalad#6589
@mslw
Copy link
Contributor

mslw commented Mar 31, 2022

I read the docstring to figure out the proposed mechanism. Looks clear to me.

mih and others added 5 commits April 1, 2022 09:21
This also replaces the previously very flexible data structure
for such items with a more rigid set of classes that implement
lazy evaluation of defaults (avoiding their possibly expensive
computation, even when they are not actually needed). They otherwise
implement all elements of the previously used API, such that they
work as a drop-in replacement.

Only register_config() is intended to be used publicly.

Fixed datalad#6314
Co-authored-by: Michał Szczepanik <mslw92@gmail.com>
@mih mih marked this pull request as ready for review April 1, 2022 08:33
@codeclimate
Copy link

codeclimate bot commented Apr 1, 2022

Code Climate has analyzed commit dcb749e and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2

View more on Code Climate.

@mih mih added the semver-minor Increment the minor version when merged label Apr 1, 2022
@mih
Copy link
Member Author

mih commented Apr 1, 2022

I took this out of draft mode. Test coverage is now 100%, and missing functionality for the doc builder was added. I also added has_config() to mitigate the concern expressed in #6601 (comment)

@bpoldrack
Copy link
Member

Restarted CI, since unrelated failures should be gone (except for snapshot build)

@codecov
Copy link

codecov bot commented Apr 4, 2022

Codecov Report

Merging #6601 (dcb749e) into master (8bf53dd) will increase coverage by 0.17%.
The diff coverage is 91.26%.

@@            Coverage Diff             @@
##           master    #6601      +/-   ##
==========================================
+ Coverage   91.13%   91.31%   +0.17%     
==========================================
  Files         350      353       +3     
  Lines       44232    45580    +1348     
==========================================
+ Hits        40312    41621    +1309     
- Misses       3920     3959      +39     
Impacted Files Coverage Δ
datalad/__init__.py 85.63% <ø> (-0.33%) ⬇️
datalad/support/entrypoints.py 47.36% <26.66%> (-13.51%) ⬇️
datalad/cli/main.py 76.00% <100.00%> (+1.26%) ⬆️
datalad/coreapi.py 100.00% <100.00%> (ø)
datalad/interface/common_cfg.py 100.00% <100.00%> (ø)
datalad/support/extensions.py 100.00% <100.00%> (ø)
datalad/support/tests/test_extensions.py 100.00% <100.00%> (ø)
datalad/core/local/tests/test_status.py 97.97% <0.00%> (-0.51%) ⬇️
datalad/support/annex_utils.py 100.00% <0.00%> (ø)
datalad/core/local/tests/test_save.py 98.12% <0.00%> (+<0.01%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bf53dd...dcb749e. Read the comment docs.

@bpoldrack
Copy link
Member

Everyone in agreement it seems. Merging.

@bpoldrack bpoldrack merged commit 324310b into datalad:master Apr 4, 2022
@mih mih deleted the bf-6314 branch April 15, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

formalize extending common_cfg.definitions (and other things) in extensions?
4 participants