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

Scoped global config #226

Open
jorenham opened this issue May 20, 2024 · 0 comments
Open

Scoped global config #226

jorenham opened this issue May 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jorenham
Copy link
Owner

Useful for globally or temporarily overriding defaults, e.g. those used for kwargs such as dtype, trim, cache, sort, rowvar, n_extra, etc.

See polars.Config for a similar feature in polars with a clean API.

Usage

Global config:

Setting:

lmo.config.set(sort='stable')

Local config

with lmo.config(sort='stable'):
    ...

or

@lmo.config.override(sort='stable')
def spam(...):
    ...

Implementation

  • The code will live in a new lmo.config namespace.
  • Specify the config options using a class ConfigOptions(TypedDict, total=False): ....
  • Use a _CONFIG: collections.ChainMap for global config (although maybe an alternative or subclass is needed for TypedDict support).
  • Initialize the root of _CONFIG using default values.
  • Implement lmo.config.override(**options: *ConfigOptions) contextmanager + decorator by having it push/pop from _CONFIG.
  • Implement lmo.config.set(*ConfigOptions) by replacing the root _CONFIG, so that any potential locally overridden options aren't affected

Bonus feature: Environment variables

So that e.g. LMO_SORT="stable" can be used to specifiy sort='stable' (supersedes the root config).

Bonus feature: pyproject.toml

Something like

[tool.lmo]
sort = "stable"

It should have lower priorty than the environment variables.

@jorenham jorenham added the enhancement New feature or request label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant