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

Remove logic around finding a configuration file inside directories #4714

Closed
wants to merge 7 commits into from

Conversation

srikant-ch5
Copy link
Contributor

@srikant-ch5 srikant-ch5 commented Oct 3, 2018

Fixes issue: #4669

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, we should fix the tests, and remove that code too and just use find_one

@srikant-ch5
Copy link
Contributor Author

Thanks alot @stsewd for reviewing. I wanted to know that if find_all is removed should the tests check number of files or check if there are multiple files?

@stsewd
Copy link
Member

stsewd commented Oct 3, 2018

@sriks123 I don't fully understand your question, but new tests should only find one top level file, no more finding files inside directories.

@srikant-ch5
Copy link
Contributor Author

@stsewd can you please review the changes that I made ?

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

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

I think we are close, just left some comments

I also like to have an extra case here

https://github.com/rtfd/readthedocs.org/blob/90b1e52cfd6a124bf7298a1b3cb1711fddd67ab8/readthedocs/config/tests/test_config.py#L106-L119

To check that we aren't finding a confi file on nested dirs


from .utils import apply_fs


def test_find_no_files(tmpdir):
with tmpdir.as_cwd():
paths = list(find_all(os.getcwd(), r'readthedocs.yml'))
paths = str(find_one(os.getcwd(), r'readthedocs.yml'))
assert len(paths) == 0
Copy link
Member

Choose a reason for hiding this comment

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

We need to change this to test that find_one returns None

str(tmpdir.join('first', '.readthedocs.yml')),
str(tmpdir.join('third', 'readthedocs.yml')),
}
paths = find_one(base, r'readthedocs\.yml')
Copy link
Member

Choose a reason for hiding this comment

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

paths -> path

]


def test_find_nested(tmpdir):
Copy link
Member

@stsewd stsewd Oct 8, 2018

Choose a reason for hiding this comment

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

I'd left this test to check that we are not finding nested files

str(tmpdir.join('third', 'readthedocs.yml')),
}
paths = find_one(base, r'readthedocs\.yml')
assert paths == str(os.path.abspath(os.path.join(base, 'readthedocs.yml')))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need str here

_path = os.path.abspath(path)
for filename in os.listdir(_path):
if re.match(filename_regex, filename):
return os.path.abspath(os.path.join(_path, filename))
Copy link
Member

Choose a reason for hiding this comment

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

I think we only need the asbpath of filename, no need to join it with _path or just join _path and filename (path is already an absolute path).

@srikant-ch5
Copy link
Contributor Author

srikant-ch5 commented Oct 9, 2018

@stsewd I made some changes as you suggested I am working on including on that extra case can you please review this ?

@@ -94,6 +94,22 @@ def test_load_no_config_file(tmpdir, files):
base = str(tmpdir)
with raises(ConfigError) as e:
load(base, env_config)
nested_files = {
'first': {
Copy link
Member

Choose a reason for hiding this comment

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

This case should be moved to the decorator, not inside the function

@@ -1089,12 +1098,12 @@ def test_python_requirements_default_value(self):
assert build.python.requirements is None

def test_python_requirements_allow_null(self):
build = self.get_build_config({'python': {'requirements': None}},)
build = self.get_build_config({'python': {'requirements': None}}, )
Copy link
Member

Choose a reason for hiding this comment

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

These modifications don't seem to belong to this PR

paths = list(find_all(os.getcwd(), r'readthedocs.yml'))
assert len(paths) == 0
paths = str(find_one(os.getcwd(), r'readthedocs.yml'))
assert paths == ''
Copy link
Member

Choose a reason for hiding this comment

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

No need to call str here, and we should rename the var name to just path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants