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

Consolidate config parsing and validation #568

Conversation

randomir
Copy link
Member

@randomir randomir commented Sep 1, 2023

This PR primarily addresses #504 (decoupling config parsing/validation from Client), and then adds from_config factories to low-level API clients and resources (#572).

To simplify config parsing, validation and usage going forward we also define a new dataclass-like model for the configuration, ClientConfig (Pydantic-based).

We also prepare ground for config file v2, a hierarchical config format (#426).

Close #504.
Close #572.
Close #505.
Fix #507.

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Merging #568 (d6015a4) into master (dd0e0f7) will increase coverage by 0.72%.
The diff coverage is 97.97%.

@@            Coverage Diff             @@
##           master     #568      +/-   ##
==========================================
+ Coverage   86.81%   87.54%   +0.72%     
==========================================
  Files          24       26       +2     
  Lines        3550     3677     +127     
==========================================
+ Hits         3082     3219     +137     
+ Misses        468      458      -10     
Files Changed Coverage Δ
dwave/cloud/api/client.py 96.17% <94.00%> (+2.11%) ⬆️
dwave/cloud/client/base.py 90.26% <95.55%> (-0.15%) ⬇️
dwave/cloud/api/resources.py 97.87% <100.00%> (+2.15%) ⬆️
dwave/cloud/cli.py 63.41% <100.00%> (+0.29%) ⬆️
dwave/cloud/config/__init__.py 100.00% <100.00%> (ø)
dwave/cloud/config/loaders.py 97.63% <100.00%> (ø)
dwave/cloud/config/models.py 100.00% <100.00%> (ø)
dwave/cloud/utils.py 89.88% <100.00%> (+0.05%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@randomir randomir force-pushed the consolidate-config-parsing-and-validation branch from 89eab98 to 88b8774 Compare September 5, 2023 14:15
@randomir randomir force-pushed the consolidate-config-parsing-and-validation branch from 88b8774 to c468773 Compare September 5, 2023 14:37
@randomir randomir force-pushed the consolidate-config-parsing-and-validation branch from 7d529b5 to 259c616 Compare September 6, 2023 16:29
@randomir randomir changed the title [wip] Consolidate config parsing and validation Consolidate config parsing and validation Sep 7, 2023
Copy link
Contributor

@thisac thisac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, as far as I can tell after a quick review. Just a few comments.

dwave/cloud/config/__init__.py Outdated Show resolved Hide resolved
dwave/cloud/api/client.py Show resolved Hide resolved
dwave/cloud/api/resources.py Outdated Show resolved Hide resolved
dwave/cloud/config/models.py Outdated Show resolved Hide resolved
dwave/cloud/config/models.py Show resolved Hide resolved
Copy link
Contributor

@JoelPasvolsky JoelPasvolsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Noting that you promised "We can update docs in a follow-up PR". For posterity.

@classmethod
def from_config_file(cls, config_file: Optional[str] = None,
profile: Optional[str] = None, **kwargs):
"""Create class instance based on config file / environment / kwarg options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this a bit confusing: the class loads up on info from the file and then runs the usual from_client_config to get what that always gets, but from this line I expected this class to deal with env vars. Can you slightly update for clairty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_config() few lines below actually loads from file and env. What's confusing is this method's name, but this is the best name I could come up with. I don't expect this method to get much usage.. The one you'll want to use is from_config -- which dispatches config loading to this method. And then the name (from_config) and the behavior is consistent with Client.from_config.

dwave/cloud/api/client.py Outdated Show resolved Hide resolved
dwave/cloud/api/client.py Outdated Show resolved Hide resolved
@randomir randomir force-pushed the consolidate-config-parsing-and-validation branch from 2fe686c to 60b3a9e Compare September 8, 2023 13:02
@randomir randomir merged commit f8f645c into dwavesystems:master Sep 8, 2023
@randomir randomir deleted the consolidate-config-parsing-and-validation branch September 8, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants