-
Notifications
You must be signed in to change notification settings - Fork 63
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
chg: Use pydantic to manage config schemas. #108
Conversation
A couple of observations -- and sorry if that sounds all too negative, just concentrating on the things that might be problematic 🙂 I feel like this makes config loading more complicated by introducing a 3-level class inheritance structure, without actually changing very much how it works. While this does introduce classes, these don't really seem to offer much benefit over the old '3 functions that load everything' implementation: This still doesn't offer any auto completion when editing code (because all values are loaded dynamically), and because the structure is still defined in a JSON schema string it doesn't make it any easier to eventually write a config editor. Also, if I understand the code correctly, this removes the option of overriding individual values in profiles. That would probably make a few people rather unhappy who currently rely on configuring different starters, Discord webhooks, etc. per-profile. The code seems to imply that there are some settings that have to be configured globally, and other settings that have to be configured on a profile level. (If I'm misinterpreting that, sorry and please disregard this comment.) This doesn't currently hold true: Every setting can either be configured globally (in the |
Thanks for the feedback, I'm very new to the project and I have limited time available so there are quite a few things that I'm not familiar with yet so it's very helpful.
I think I misinterpreted a few things about the original intent. My intent here was just to setup a framework but since it was a big departure I didn't want to actually work on any of the actual improvements in case it wasn't welcome (and I'm glad I held off :P).
I was under the wrong impression that we wanted the original schemas, personally, I prefer pydantic schemas, in which case we'll have IDE integration.
That was a big miss on my end, I was going to implement that when I got to Profiles, and have them update the defaults or use their own settings if they have been set. But I would need to do everything at once. I'll go back to the drawing board and try to make a simpler, just in case a couple of questions:
Part of what made me approach this in such a different way was that in the back of my mind I had the idea of eventually adding a setting that would detect the CPU capabilities and allow |
Converted to draft showing the general idea of managing the config schemas with pydantic schemas. This is just a POC of what I could cobble together in a couple of hours to gather feedback before I invest further time, as touching the config means touching basically everything. I still have to override config with config from profiles but that shouldn't take too much work. And I have to rebase since this PR looks like I'm deleting random stuff from newer merges, lol. |
This looks quite nice! pydantic seems like a good fit for that. I have a couple more thoughts on this, but first to preface here are the issues that I'm seeing with the current config system:
So my thinking is:
|
I agree, I kind wanted to add the current defaults into the schema, then only modified values will be loaded in, allowing for a config file with say a single setting someone cares about regardless of it being in a global file (for legacy support purposes) or in a particular profile, where maybe the user just wants like a single webhook configuration file or something. This would solve (1) and (2), I didn't jump the gun because I wasn't sure if it was preferred but it looks like an improvement to me. Additionally, add the old config file definitions to
This also makes sense to me, when I was making the configuration trees I wasn't very happy about the user experience in general of using nested logic or Personally, the way I tend to approach these things is in approachable steps on different PRs, because it makes reverting easier and if something goes wrong, reduces friction with other developers that will start getting used to accessing information from the config in a slightly different way, and doing the most drastic change to moving to models as son as possible reduces the problems with merge conflicts in the future, since IDE refactor tools can be used instead of manually hunting down every access to config as a dict, so changing the shapes of those schemas becomes a lot easier once they have been implemented. So for example:
If you prefer 1 and 2 to be done together I think that's doable, but in general breaking it up into manageable chunks could allow easier collaboration since someone may only have the time to do one half of a big change and someone else could come along and complete it. |
4514a77
to
f5eefbd
Compare
Been busy, haven't had much time to properly read and catch up in this thread, but why And also, don't stress about transitioning changes, people understand this thing is under heavy development and it's still an early version, if they need to nuke their config and start from scratch, so be it. I think it's easier to just rip off the bandaid, don't be afraid! 😄 |
@unixtreme Yeah I didn't mean to do all those things in this PR, just thought I'd mention them here rather than the ticket to keep the discussion in one place. 🙂
I like that! So then, all existing config files would just continue working and there would be no breaking change? Nice.
I'm not sure I agree, at least in this case. For starters, there is going to be a need for a migration algorithm either way -- whether that's an automatic migration coded into the bot, or an explanatory section in the Readme or an update post in some Discord channel. I'd argue that it is easier to write and reliably test migration code than it is to write a good explanation on how to do that and then deal with all the follow-up confusion of people that are inevitably going to do it wrong anyway. Secondly, the code for loading the old config format already exists, so all that would be needed is a couple lines of code that check whether old files exist, load them, and store them in the new format. And perhaps a bit of mapping code. Lastly, I myself have about 20 profiles for various testing purposes. It'd be very nice if I didn't have to fix the config files everywhere. So even just for us some automatic conversion would be nice.
It's not so much about the file format itself and more about the structure of config values. If we had a simple key/value table of config options it would be easier to auto-generate a GUI for that. Because you'd just have to At the moment, we have a config tree rather than a table because some values are nested (mostly in This could easily be done with YAML as well, but if we change the config files anyway we might as well consider the file format at the same time. If we don't use YAML's nesting features, then INI would be a potential substitute that is more forgiving with its syntax. While I don't doubt that someone is going to manage messing up even that, the syntax rules are much more simple than for YAML (and also, I believe that on Windows |
e868642
to
fecc896
Compare
This ruins the placement of the bot mode selection, although if we keep it there (with some size adjustment) I guess we could just align the Bot Mode box to the top. |
Added some basic unit tests. |
There are a few other things that probably wouldn't get reloaded properly, such as Discord rich presence or the HTTP server. Which is not bad, just something to be aware of. From a UX perspective, this button might be a bit confusing to users. Unlike all the other controls this one has no apparent effect when clicked, and the way it is positioned might be misunderstood as a 'save' button for the other controls. While there is no harm in reloading the config if it has not changed, how about we drop the button for now and just hide that feature behind some keyboard shortcut such as |
Oh Right I completely forgot those two run in their own process and are setup at the start. Yeah basically only values that are accessed directly are really doing anything. Hiding it behind some shortcut instead of the UI button crossed my mind and it's probably better than cluttering the UI. |
c7679ea
to
c80f077
Compare
Rebased and solved conflicts, set the config reload to |
Code-wise this looks pretty good to me, though I haven't had a chance to actually test it yet. Nice work! 🙂 |
0283b56
to
d46cf62
Compare
Apologies for leaving this in the dark for a bit, been quite unmotivated lately... Going to start reviewing and merge this before #109 and #117 as they both have config related code, should be fairly straightforward to rebase them anyway. Just going to post anything I find as I test.
Seems to break the requirements check, imported before |
hey no worries we can't all have 100% energy all the time, this is a free-time side thing after all!
Oops my bad, I did all testing with confz already installed and didnt try a new venv without any dependencies triggering a fresh install. I moved this import to after the requirements check. |
#69 this will conflict with #109 if that merges earlier I have to update the temporary hard-coded modes.
As part of the final PR I plan to:
global_config.obs
notglobal_config['obs']
. This can also be done dynamically very easily and I'm quite familiar.