-
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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 forTypedDict
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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request