-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Refactor configuration object to class based #4298
Refactor configuration object to class based #4298
Conversation
readthedocs/config/config.py
Outdated
raise NotImplementedError() | ||
|
||
|
||
class BuildConfig(BuildConfigBase, dict): |
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.
I'm keeping the dict thing here for a while, so the refactor isn't too big
Please ignore the linter errors p: |
@@ -442,11 +613,6 @@ def validate(self): | |||
for build in self: | |||
build.validate() | |||
|
|||
def set_output_base(self, directory): |
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.
We weren't using this, and it's the only setter. We should keep all the config object as read-only I think.
I just removed the |
I have tested this with some projects from github that have a |
raise NotImplementedError() | ||
|
||
@property | ||
def python_interpreter(self): |
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.
Maybe we can move this to a function outside the config object
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.
Perhaps it makes somewhere else, yeah. We can probably leave for just now. Feel free to open an issue of you want to track this work.
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.
I opened #4343
self.validate_conda() | ||
self.validate_requirements_file() | ||
self.validate_conf_file() | ||
# TODO: this isn't used |
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.
I left some todos about things we aren't using right now.
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.
funny that we aren't attempting to use some of these yet, they could fix some buggy behavior. either way, we can add the functionality in v2.
I just left some comments about things we can remove (maybe in other PR), I think this is ready. Next step is creating the version2 and the class selector of the configuration object. |
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.
Looks great, i think this is close to merge.
I noted what I think could be improved with the attribute methods from configwrapper (configbase in this PR). We can talk about this more. There isn't anything wrong with the implementation now, but it feels like a lot of unnecessary code to maintain, when we could just map values to a struct. Not something that we need to fix here.
readthedocs/config/config.py
Outdated
super(ConfigNotSupportedError, self).__init__( | ||
template.format(self.configuration), | ||
CONFIG_NOT_SUPPORTED | ||
) |
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.
It sounds like this is describing an unsupported configuration option
instead perhaps? It's a little confusing referring to this as just unsupported configuration
, as that implies to me a whole file or something.
So perhaps this class would instead be ConfigOptionNotSupportError
, and the copy/docs can be updated
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.
Done
raise NotImplementedError() | ||
|
||
@property | ||
def python_interpreter(self): |
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.
Perhaps it makes somewhere else, yeah. We can probably leave for just now. Feel free to open an issue of you want to track this work.
self.validate_conda() | ||
self.validate_requirements_file() | ||
self.validate_conf_file() | ||
# TODO: this isn't used |
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.
funny that we aren't attempting to use some of these yet, they could fix some buggy behavior. either way, we can add the functionality in v2.
@@ -256,7 +317,7 @@ def validate_build(self): | |||
""" | |||
# Defaults | |||
if 'build' in self.env_config: | |||
build = self.env_config['build'] | |||
build = self.env_config['build'].copy() |
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.
👍
@property | ||
def build_image(self): | ||
"""The docker image used by the builders.""" | ||
return self._config['build']['image'] |
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.
A couple things about the config attribute and usage pattern, which we can probably push off an resolve with a future PR:
- There is a lot of repetition here, for code that we're just using to convert a dict -> object with attributes
- We have multiple patterns for option naming:
python_version
vsinstall_project
- This pattern flattens some of the options, from
['python']['version']
topython_version
, loss of nesting makes some of the options less obvious.
A couple of options here:
- Treat the config as a dictionary
- Rename some of the attributes now, so that they retain more contextual information -- ie, rename some of the nested options to
python_*
- Use a namedtuple or a package like
bunch
to create nested attribute accessor instances, instead of repeating the logic above for each accessor
I think we can make a new issue here and address this later though.
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.
Yeah, I was thinking the same, maybe a namedtuple is enough, right now I just copy the names from the ConfigWrapper object.
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.
I opened #4346
'output_base': '', | ||
'type': 'sphinx', | ||
'name': version.slug, | ||
}) |
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.
Is there anything you should do here before this is merged?
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.
I think this would be fixed if we delete this options, they aren't used anyway.
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.
So, having hard coded this options here isn't a problem right now, but isn't correct either p:
Hopefully, this will solve #3806 (or maybe it will be split in two PRs).
I'm refactoring the existing code to be class based instead of using a dictionary, this will allow us to extend the behavior and have a common interface for multiple versions of the configuration file.