Skip to content

Commit 044d76b

Browse files
committed
Dynamically discover requirements files
1 parent 75a0eb2 commit 044d76b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

readthedocs/projects/tasks.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,29 @@ def setup_environment(version):
290290
)
291291
)
292292

293-
if project.requirements_file:
294-
os.chdir(project.checkout_path(version.slug))
293+
# Handle requirements
294+
295+
requirements_file_path = project.requirements_file
296+
if not requirements_file_path:
297+
docs_dir = builder_loading.get(project.documentation_type)(version).docs_dir()
298+
checkout_path = project.checkout_path(version.slug)
299+
for path in [docs_dir, '']:
300+
for req_file in ['pip_requirements.txt', 'requirements.txt']:
301+
test_path = os.path.join(checkout_path, path, req_file)
302+
print('Testing %s' % test_path)
303+
if os.path.exists(test_path):
304+
requirements_file_path = test_path
305+
break
306+
307+
if requirements_file_path:
308+
os.chdir(checkout_path)
295309
ret_dict['requirements'] = run(
296310
'{cmd} install --exists-action=w -r {requirements}'.format(
297311
cmd=project.venv_bin(version=version.slug, bin='pip'),
298-
requirements=project.requirements_file))
312+
requirements=requirements_file_path))
313+
314+
# Handle setup.py
315+
299316
os.chdir(project.checkout_path(version.slug))
300317
if os.path.isfile("setup.py"):
301318
if getattr(settings, 'USE_PIP_INSTALL', False):
@@ -321,7 +338,6 @@ def build_docs(version, force, pdf, man, epub, dash, search, localmedia):
321338
project = version.project
322339
results = {}
323340

324-
325341
with project.repo_nonblockinglock(version=version,
326342
max_lock_age=getattr(settings, 'REPO_LOCK_SECONDS', 30)):
327343
html_builder = builder_loading.get(project.documentation_type)(version)

0 commit comments

Comments
 (0)