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

Refactor the configuration parsing #513

Merged
merged 4 commits into from
Oct 17, 2024
Merged

Refactor the configuration parsing #513

merged 4 commits into from
Oct 17, 2024

Conversation

amritghimire
Copy link
Contributor

@amritghimire amritghimire commented Oct 16, 2024

As a part of #10774 , this introduces a process to save the configuration
in local, system and global configuration.

The precedence of the level are as:

  • system
  • global
  • local

Local configuration overrides global and so on.

This borrows the logic of how configuration is managed in DVC.

@amritghimire amritghimire self-assigned this Oct 16, 2024
Copy link

cloudflare-workers-and-pages bot commented Oct 16, 2024

Deploying datachain-documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0150437
Status: ✅  Deploy successful!
Preview URL: https://3d2a9b2b.datachain-documentation.pages.dev
Branch Preview URL: https://amrit-config.datachain-documentation.pages.dev

View logs

As a part of #10774, this introduces a process to save the configuration
in local, system and global configuration.

The precedence of the level are as:
- system
- global
- local

Local configuration overrides global and so on.

This borrows the logic of how configuration is managed in DVC.
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 59.00000% with 41 lines in your changes missing coverage. Please review.

Project coverage is 87.16%. Comparing base (c6ca542) to head (0150437).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/datachain/config.py 50.00% 37 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #513      +/-   ##
==========================================
- Coverage   87.25%   87.16%   -0.09%     
==========================================
  Files          96       96              
  Lines        9931     9991      +60     
  Branches     1359     1367       +8     
==========================================
+ Hits         8665     8709      +44     
- Misses        915      928      +13     
- Partials      351      354       +3     
Flag Coverage Δ
datachain 87.13% <59.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dreadatour dreadatour left a comment

Choose a reason for hiding this comment

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

Overall, it looks good to me as long as it has been thoroughly tested 👍
It would be great to add more tests, and I’ve left a couple of minor comments below.

)

if remote_type == "http":
for key in ["url", "username", "token"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wonder, should we also have team_id as a part of remote config? User can be a member of many teams in Studio 🤔 Or team_id will be required as a (required? optional?) param in API calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may be part of future changes when implementing some functionality with the token access.

Comment on lines +113 to +117
except KeyError:
raise Exception(
f"config section remote.{remote} of type {remote_type} "
f"must contain key {key}"
) from None
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a comment: Studio URL may be optional 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not sure if we will continue using this TBH. Keeping this part as it is for now.

return load(f)
except FileNotFoundError:
return None
class Config:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me, it would be great to add tests for this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests and fixes in #514

# In the order of precedence
LEVELS = SYSTEM_LEVELS + LOCAL_LEVELS

CONFIG = "config"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I understand the reason behind this attribute 👀 Can't find any usage of this.


def __init__(
self,
level: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wonder, will it be better from typing prospective to have level as enum, let's say? 👀

@amritghimire amritghimire merged commit f29e034 into main Oct 17, 2024
37 of 38 checks passed
@amritghimire amritghimire deleted the amrit/config branch October 17, 2024 14:59
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.

2 participants