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

Add settings module #1044

Merged
merged 20 commits into from
Jan 22, 2025
Merged

Add settings module #1044

merged 20 commits into from
Jan 22, 2025

Conversation

soapy1
Copy link
Contributor

@soapy1 soapy1 commented Jan 9, 2025

Fixes #1005

Description

This PR introduces a settings module for interacting with conda store settings. It also adds some documentation and enforces rules for how settings get merged at each of the different levels of abstraction that setting apply to.

There are multiple levels which settings config can be applied to conda store.

  • deployment defaults (controlled by the config file)
  • global defaults (controlled by the admin console)
  • namespace defaults (controlled by the admin console)
  • environment default (controlled by the admin console)

The most specific settings config will take precedence over the more general setting.

The introduction of this settings object will allow:

  • defining a common pattern for accessing settings
  • enforcing rules around setting precedence
  • providing a common implementation for accessing settings.

With this change, plugin authors will have better patterns for accessing settings. For example, consider the lock plugin which requires running a conda command

def _conda_command(self, conda_store) -> str:
        with conda_store.session_factory() as db:
            settings = conda_store.get_settings(db=db)
        return settings.conda_command

can now become

def _conda_command(self, conda_store, namespace=None, environment=None) -> str:
        return conda_store.get_setting(
            "conda_command", namespace=namespace, environment=environment
        ) or "mamba"

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentation (if required)?
  • Did you add/update relevant tests for this change (if required)?

Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for conda-store ready!

Name Link
🔨 Latest commit 9df6602
🔍 Latest deploy log https://app.netlify.com/sites/conda-store/deploys/678024c4eb92e30008d8cfde
😎 Deploy Preview https://deploy-preview-1044--conda-store.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for conda-store canceled.

Name Link
🔨 Latest commit 7e6d2ed
🔍 Latest deploy log https://app.netlify.com/sites/conda-store/deploys/67914e0e4de9de000812da4c

@soapy1 soapy1 force-pushed the settings-module branch 3 times, most recently from 3b5eee6 to 1570e12 Compare January 9, 2025 22:14
@soapy1 soapy1 requested a review from peytondmurray January 13, 2025 17:01
Copy link
Contributor

@peytondmurray peytondmurray left a comment

Choose a reason for hiding this comment

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

Looks good, just one minor change and a bunch of annotations.

Thanks for this, it's going to make this much clearer for users 👍

Copy link
Contributor

@peytondmurray peytondmurray left a comment

Choose a reason for hiding this comment

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

Minor changes. One question: should setting an invalid setting raise an exception? Right now if you set a setting that isn't real there's no way for you to know other than checking whether it is None.

@soapy1
Copy link
Contributor Author

soapy1 commented Jan 22, 2025

Right now if you set a setting that isn't real there's no way for you to know other than checking whether it is None.

It should be throwing an error if the user is trying to set a setting that does not exist in the Settings schema object. There is a test for this test_set_settings_invalid_setting_field.

@soapy1 soapy1 merged commit a7a6390 into conda-incubator:main Jan 22, 2025
30 checks passed
@soapy1 soapy1 deleted the settings-module branch January 22, 2025 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

Rethink how settings get applied to conda-store servers/workers
2 participants