-
Notifications
You must be signed in to change notification settings - Fork 279
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
Validate config.yaml contents (#77) #107
Validate config.yaml contents (#77) #107
Conversation
RE: failing tests -- tests seem to be failing because the Is this desired? Checking out the
but I don't see anything about For these tests, it would be possible to mock out the |
Awesome!
Haha, no, this is not desired. But also not a surprise. When I proposed #61, we had an at-length discussion there about the config file being treated as a separate issue because it's just an intermediary weirdness and existing users expect it to sit in their current working directory anyways. The actual issue for taking care of config is #84 and I have not gotten around to implementing it. In fact I haven't touched it at all - if you're in the zone and this seems like a good fit, feel free to look into it, ... otherwise maybe @altendky has a good idea of how to hotfix the CI for now (he introduced it, it's mostly black magic to me) to make this one work in isolation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several specific comments and some general questions, but overall this is having exactly the effect I'd hoped for. Simple and complete definition of the configuration along with explicit errors for users rather than random code giving TypeError
or such. :]
Thanks for all the work on this. I have a few followup changes that I want to do that will be much more sensible because of this improvement.
-
For all (@jkbecker, @ericaltendorf), do we want to use
attrs
ordataclasses
? https://www.attrs.org/en/stable/why.html#data-classes gives a brief explanation. I default to attrs. It shouldn't make much of a difference to the PR. -
Yeah, we need to decide how to handle the config file. I haven't really made out a whole plan, but I'll write some stuff and see where we end up. We want to be able to, after installation, write out a file to a given location with a 'default' configuration. The content could be sourced from an existing file or from a function that creates instances of the new configuration classes. If it is a file, then yes, it should be validated in the tests as @chelseadole pointed out. I suppose it is pretty handy to have a file to link to in the repository and talk about. Maybe that's enough to make up my mind on using a file. I don't super care where it lives but I might default to something like
src/plotman/resources/config.yaml
(orplotman.yaml
). https://github.com/ericaltendorf/plotman/pull/93/files provides a reference for including data files and usingimportlib.resources
. Tests can get at the data and the runtime can get to it as well to write out the default config for the user.
I expect the options.data_files
will go away. I think MANIFEST.in
and include_package_data = True
in setup.cfg
will cover the data files we need.
Thanks again for making this big improvement here. The list of comments looks unrepresentatively long :[
but I think figuring out the config file location etc might be the biggest thing, and it shouldn't be too bad... :]
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Thank you both for the review, comments, and context. To unblock myself in this PR, I will change
My personal approach would be adding new args similar to what's suggested in #84, so when you There's a lot more detail discussed in #84, and I don't want to overcrowd this PR. How about I do the above work to unblock myself with testing, and leave additional commandline features with |
…into chelseadole/yaml-validation
…seadole/plotman into chelseadole/yaml-validation
Agreed that the various discussions about finding the config file should be addressed in a separate PR. |
@altendky Let me know what you think of the added changes. It now supports: $ plotman config show
$ plotman config generate For now, it only performs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these two sections still correct? They seem to be superseded by what the generate
command does?
This looks awesome! I feel like it's probably clean to stick with just one default config location in this PR, and address the overloadable config file situation mentioned in #84 in a separate follow-up PR (I'm happy to work on that one but I'm currently super maxed out with "work" work, so... not mad if you get to tackling it first - we can play by ear.) |
Yes, I wanted to start with a constant config location before adding complexity. I'm also ramping up on a new project at "work" work, so I'll see -- but if I have time I'll try to tackle it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping at this. :]
src/plotman/configuration.py
Outdated
except FileNotFoundError: | ||
raise ConfigurationException( | ||
f"No 'plotman.yaml' file exists at expected location: '{config_file_path}'. To generate " | ||
f"default config file, run: 'plotman config generate'" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted over in #107 (comment), I would rather keep at least the file object creation outside of this function, as it was before. This keeps a bit flatter structure and leaves control of at least the I/O mechanism at a higher level leaving more flexibility. For example, this would avoid the need for mocking to test this function. Do you have a reason that you prefer the present form instead that I should think about?
Wherever this lives...
except FileNotFoundError: | |
raise ConfigurationException( | |
f"No 'plotman.yaml' file exists at expected location: '{config_file_path}'. To generate " | |
f"default config file, run: 'plotman config generate'" | |
) | |
except FileNotFoundError as e: | |
raise ConfigurationException( | |
f"No 'plotman.yaml' file exists at expected location: '{config_file_path}'. To generate " | |
f"default config file, run: 'plotman config generate'" | |
) from e |
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
…plotman into chelseadole/yaml-validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chelseadole, definitely glad to see this change. Sorry for the wait.
Addresses #77
desert
-based dataclasses to configuration.py to deserialize config.yaml contentsIn the discussion for #77 , @jkbecker mentioned potentially making config-related changes discussed in #84 . I did not get to this, because the PR reached a critical length where I think it's safest to separate concerns. :)