Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit db4ad19

Browse files
authored
Merge pull request #17 from skirpichev/dotreadthedocs.yml
Support .readthedocs.yml (optionally)
2 parents ef2d919 + 0bf7aa6 commit db4ad19

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Running a build is simple::
2424

2525
rtd-build
2626

27-
This will search for all ``readthedocs.yml`` files below your current directory
28-
and will build your documentation.
27+
This will search for all ``readthedocs.yml`` (or ``.readthedocs.yml``) files
28+
below your current directory and will build your documentation.
2929

3030
You can set a specific a directory where the built documentation should be
3131
stored::

readthedocs_build/config/config.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'load', 'BuildConfig', 'ConfigError', 'InvalidConfig', 'ProjectConfig')
1818

1919

20-
CONFIG_FILENAME = 'readthedocs.yml'
20+
CONFIG_FILENAMES = ('readthedocs.yml', '.readthedocs.yml')
2121

2222

2323
BASE_INVALID = 'base-invalid'
@@ -346,11 +346,14 @@ def load(path, env_config):
346346
The config will be validated.
347347
"""
348348

349-
config_files = list(find_all(path, CONFIG_FILENAME))
349+
config_files = list(find_all(path, CONFIG_FILENAMES))
350350
if not config_files:
351-
raise ConfigError(
352-
'No {filename} found'.format(filename=CONFIG_FILENAME),
353-
code=CONFIG_REQUIRED)
351+
files = '{}'.format(', '.join(map(repr, CONFIG_FILENAMES[:-1])))
352+
if files:
353+
files += ' or '
354+
files += '{!r}'.format(CONFIG_FILENAMES[-1])
355+
raise ConfigError('No files {} found'.format(files),
356+
code=CONFIG_REQUIRED)
354357
build_configs = []
355358
for filename in config_files:
356359
with open(filename, 'r') as file:

readthedocs_build/config/find.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
22

33

4-
def find_all(path, filename):
4+
def find_all(path, filenames):
55
path = os.path.abspath(path)
66
for root, dirs, files in os.walk(path):
7-
if filename in files:
8-
yield os.path.abspath(os.path.join(root, filename))
7+
for filename in filenames:
8+
if filename in files:
9+
yield os.path.abspath(os.path.join(root, filename))

readthedocs_build/config/test_find.py

+37-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
def test_find_no_files(tmpdir):
88
with tmpdir.as_cwd():
9-
paths = list(find_all(os.getcwd(), 'readthedocs.yml'))
9+
paths = list(find_all(os.getcwd(), ('readthedocs.yml',)))
1010
assert len(paths) == 0
1111

1212

1313
def test_find_at_root(tmpdir):
1414
apply_fs(tmpdir, {'readthedocs.yml': '', 'otherfile.txt': ''})
1515

1616
base = str(tmpdir)
17-
paths = list(find_all(base, 'readthedocs.yml'))
17+
paths = list(find_all(base, ('readthedocs.yml',)))
1818
assert paths == [
1919
os.path.abspath(os.path.join(base, 'readthedocs.yml'))
2020
]
@@ -36,8 +36,42 @@ def test_find_nested(tmpdir):
3636
apply_fs(tmpdir, {'first/readthedocs.yml': ''})
3737

3838
base = str(tmpdir)
39-
paths = list(find_all(base, 'readthedocs.yml'))
39+
paths = list(find_all(base, ('readthedocs.yml',)))
4040
assert set(paths) == set([
4141
str(tmpdir.join('first', 'readthedocs.yml')),
4242
str(tmpdir.join('third', 'readthedocs.yml')),
4343
])
44+
45+
46+
def test_find_multiple_files(tmpdir):
47+
apply_fs(tmpdir, {
48+
'first': {
49+
'readthedocs.yml': '',
50+
'.readthedocs.yml': 'content',
51+
},
52+
'second': {
53+
'confuser.txt': 'content',
54+
},
55+
'third': {
56+
'readthedocs.yml': 'content',
57+
'Makefile': '',
58+
},
59+
})
60+
apply_fs(tmpdir, {'first/readthedocs.yml': ''})
61+
62+
base = str(tmpdir)
63+
paths = list(find_all(base, ('readthedocs.yml',
64+
'.readthedocs.yml')))
65+
assert paths == [
66+
str(tmpdir.join('first', 'readthedocs.yml')),
67+
str(tmpdir.join('first', '.readthedocs.yml')),
68+
str(tmpdir.join('third', 'readthedocs.yml')),
69+
]
70+
71+
paths = list(find_all(base, ('.readthedocs.yml',
72+
'readthedocs.yml')))
73+
assert paths == [
74+
str(tmpdir.join('first', '.readthedocs.yml')),
75+
str(tmpdir.join('first', 'readthedocs.yml')),
76+
str(tmpdir.join('third', 'readthedocs.yml')),
77+
]

0 commit comments

Comments
 (0)