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 a config mechanism #126

Merged
merged 14 commits into from
Mar 12, 2025
Merged

Add a config mechanism #126

merged 14 commits into from
Mar 12, 2025

Conversation

suvayu
Copy link
Collaborator

@suvayu suvayu commented Mar 7, 2025

  • config.py: add config object
  • scripts/config.toml: example config

Features

  • The configs are namespaced such that separate sections can be read as separate config objects.
  • The config objects are also easily created from a dictionary, so that it's easy to use programmatically.
  • There are no mandatory fields; there are defaults when fields are missing, some are None because I didn't know what would be most appropriate.
  • The config also does type validation in a very limited capacity. Changing the types arbitrarily will most likely fail (e.g. nested types), but plain old data types, and basic containers like list (including multi-dimensional), dict as long as they are flat will validate correctly.

How to use?

@HannoSpreeuw, I wonder if you have any preference how to use the config object. Typically I would adjust the code so that where relevant you pass a config object.

@suvayu suvayu requested a review from HannoSpreeuw March 7, 2025 12:58
@suvayu suvayu marked this pull request as ready for review March 7, 2025 13:17
@HannoSpreeuw
Copy link
Collaborator

HannoSpreeuw commented Mar 7, 2025

Let me get into this in one of the coming days.

This is about fixing issue #74 , right?

@suvayu
Copy link
Collaborator Author

suvayu commented Mar 7, 2025

Yes, that's right

Copy link
Collaborator

@HannoSpreeuw HannoSpreeuw left a comment

Choose a reason for hiding this comment

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

I can't immediately grasp the idea behind the _Validate class and the validate_nested function.

@suvayu
Copy link
Collaborator Author

suvayu commented Mar 8, 2025

I can't immediately grasp the idea behind the _Validate class and the validate_nested function.

They are my implementation to do type validation without adding additional dependencies. As I mentioned in the PR intro, for simple flat data structures, it should work. It's somewhat future proof.

Basically it prevents the user from providing incorrect data types in the config.

@HannoSpreeuw
Copy link
Collaborator

HannoSpreeuw commented Mar 9, 2025

Allright, aside from a few adjustments - removing sep and appropriate default values - we can move forward after fixing the build problem: ModuleNotFoundError: No module named 'tomllib'.

@HannoSpreeuw
Copy link
Collaborator

The unit tests may pass since the global variables are still used.

@suvayu suvayu merged commit 750b687 into master Mar 12, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants