-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Implement sphinx key from v2 config #4482
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
Conversation
I will wait until the base PR gets merged to review this. |
64cd38a
to
58adc35
Compare
@@ -232,7 +232,6 @@ def test_requirements_file(self, load_config): | |||
self.assertEqual(config.python.requirements, '__init__.py') | |||
|
|||
|
|||
@pytest.mark.skip |
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.
Tests are un-skipped here
Rebased and updated! I'll try to manually test this by morning monday |
Ok, I need to figure out how to keep the previous behavior that creates a conf.py file if no one is found and use that. |
I'll like to merge this first #4566, as I'm touching some related code and I want to make sure I'm not breaking that code. |
def test_create_conf_py( | ||
self, get_conf_py_path, _, get_config_params, | ||
@patch('readthedocs.projects.models.Project.checkout_path') | ||
def test_multiple_conf_py( |
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.
Silly me, left this test with a duplicated name...
@@ -97,14 +114,24 @@ def test_create_conf_py( | |||
""" | |||
|
|||
tmp_docs_dir = py.path.local(tempfile.mkdtemp()) | |||
tmp_docs_dir.join('conf.py').new() | |||
tmp_docs_dir.join('test').mkdir().join('conf.py').new() | |||
tmp_docs_dir.join('conf.py').write('') |
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 like new() doesn't create the files on disk
#4456 is merged, this needs a rebase. |
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 good so far! Noted a couple places that would be helpful to ensure our logic isn't changing, or at least is not likely to introduce tricky bugs.
outfile_path = ( | ||
self.config.sphinx.configuration or | ||
self.project.conf_file(self.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.
It seems here we're implying that if you set a sphinx configuration file, but it doesn't exist, we just create it? I feel like we should error out if you set up a config file and it doesn't actually exist, it will be confusing to the user for the build to pass in this case.
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.
This is to keep compatibility with the behavior when the user doesn't set a config file and rtd tries to find one.
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.
That part I understand, but this seemed to be creating a 3rd option, where the config was specified but not found, and therefore the config was generated instead. This might not be an issue, I interpreted self.config.sphinx.configuration
as defaulting to None
if the file is specified but doesn't exist, but that doesn't seem to be the logic used looking at it again.
config_file = ( | ||
self.config.sphinx.configuration or | ||
self.project.conf_file(self.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.
Same here. And I feel like we shouldn't be guessing here. If the config file was specified and it exists, that's when we should set the config file path. Likewise, if we're generating a config, we set a config file path when we find out the user doesn't have a config and didn't specify a config file path.
This will cut down on magical decisions that tend to hide errors from us.
cwd = self.project.conf_dir(self.version.slug) | ||
config_file = self.config.sphinx.configuration | ||
config_dir = os.path.dirname(config_file) if config_file else None | ||
cwd = config_dir or self.project.conf_dir(self.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.
This logic looks duplicated, is there a way to reduce this duplication if so?
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 knew you were not going to like it p: haha, so all this is to make sure that we are keeping the previous behavior. If a config file doesn't exist, we create one, and also we try to find one in the whole project. I guess we can do a big refactor to do this step early, before parsing the config file (but not sure if this worth it). Or maybe we can use a config_file
property inside the sphinx builder and modify that as we want
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, this could either be a property, or even just simply set the common values on __init__
in base?
sphinx_configuration = path.join( | ||
version.get_conf_py_path(), | ||
'conf.py' | ||
) |
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's not clear to me why this change is needed. Shouldn't the full path have already been returned by version.get_conf_py_path()
?
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 was bitten by the name here too, this only returns the directory name. There is a test unskipped that covers this case.
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.
huh. is there a reason why this was working then? It seems like it shouldn't have worked at all if it was just the 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 didn't have a test, but I added them in https://github.com/rtfd/readthedocs.org/pull/4456/files#diff-5a2cc4147895068b33fe5bf89e4e6e08R589 (skipped)
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.
Also currently we are reading this from the database, that's why the builds don't fail
outfile = codecs.open(outfile_path, encoding='utf-8', mode='a') | ||
self.config_file = ( | ||
self.config_file or | ||
self.project.conf_file(self.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.
I need to keep this one, as here we catch and re-raise the exception to the user
V1 is still working, I refactored the code. I'll be testing v2 in the morning. |
OK, v2 tested! It works :D |
Changes look good! |
This PR on top of #4456. It should be merged after.
New commits are from 6756b7f
Ref #4219