This repository was archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Check for readthedocs file with yaml extension #48
Closed
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f044969
Test for yaml config file extension (fails).
StefanoChiodino 9c000fb
Add a basic .yaml file and add it to the config filenames.
StefanoChiodino f1fa2db
Reduce test to just being able to load the file.
StefanoChiodino d4c888b
Use regex to find the readthedocs yaml file.
StefanoChiodino d87677c
Use sets for paths found now that order doesn't matter any more.
StefanoChiodino 887e0ea
Convert directly to sets
StefanoChiodino cc2ef31
Remove .yaml file that was not actually necessary.
StefanoChiodino 0f1f4a6
Add test for possible config filenames.
StefanoChiodino ec96e3b
Improve code readability
StefanoChiodino afffb2e
Improve file naming options
StefanoChiodino 1b1ae9a
Make config error more generic.
StefanoChiodino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
'load', 'BuildConfig', 'ConfigError', 'InvalidConfig', 'ProjectConfig') | ||
|
||
|
||
CONFIG_FILENAMES = ('readthedocs.yml', '.readthedocs.yml') | ||
CONFIG_FILENAME_REGEX = r'\.?readthedocs.ya?ml' | ||
|
||
|
||
BASE_INVALID = 'base-invalid' | ||
|
@@ -29,7 +29,7 @@ | |
|
||
DOCKER_DEFAULT_IMAGE = 'readthedocs/build' | ||
DOCKER_DEFAULT_VERSION = '2.0' | ||
# These map to coordisponding settings in the .org, | ||
# These map to corresponding settings in the .org, | ||
# so they haven't been renamed. | ||
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION) | ||
DOCKER_IMAGE_SETTINGS = { | ||
|
@@ -433,14 +433,10 @@ def load(path, env_config): | |
The config will be validated. | ||
""" | ||
|
||
filename = find_one(path, CONFIG_FILENAMES) | ||
filename = find_one(path, CONFIG_FILENAME_REGEX) | ||
|
||
if not filename: | ||
files = '{}'.format(', '.join(map(repr, CONFIG_FILENAMES[:-1]))) | ||
if files: | ||
files += ' or ' | ||
files += '{!r}'.format(CONFIG_FILENAMES[-1]) | ||
raise ConfigError('No files {} found'.format(files), | ||
raise ConfigError('No files with regex \'{}\' found'.format(CONFIG_FILENAME_REGEX), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to mention regex here as this is a user facing error. The error message should probably just be "No configuration file found." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
code=CONFIG_REQUIRED) | ||
build_configs = [] | ||
with open(filename, 'r') as file: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import os | ||
import re | ||
|
||
|
||
def find_all(path, filenames): | ||
def find_all(path, filename_regex): | ||
path = os.path.abspath(path) | ||
for root, dirs, files in os.walk(path, topdown=True): | ||
dirs.sort() | ||
for filename in filenames: | ||
if filename in files: | ||
for filename in files: | ||
if re.match(filename_regex, filename): | ||
yield os.path.abspath(os.path.join(root, filename)) | ||
|
||
|
||
def find_one(path, filenames): | ||
for _path in find_all(path, filenames): | ||
def find_one(path, filename_regex): | ||
for _path in find_all(path, filename_regex): | ||
return _path | ||
return '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if isn't better to test this regex (because right now we are hardcoding a regex in the tests)
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.
Sure, can do that too, is a very easy test, I'm just wondering what will I actually be testing? I can see 4 permutations that the regex need to test, but should I test that it doesn't match something else as well?
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 testing matching is enough