From 74ccfc4df6002bcbb44dc4ea65400b8b2dbef994 Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Thu, 7 Feb 2019 20:44:57 +0100 Subject: [PATCH] Added the possibility to specify the destination directory in autogen.py (#12220) * Added the possibility to specify the destination directory. * Running the docs tests only in one build. --- .travis.yml | 4 ++-- docs/autogen.py | 10 +++++++--- tests/test_doc_auto_generation.py | 9 +++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7f3909b7568..371e99d9a86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,7 +80,7 @@ script: - if [[ "$TEST_MODE" == "INTEGRATION_TESTS" ]]; then PYTHONPATH=$PWD:$PYTHONPATH py.test tests/integration_tests; elif [[ "$TEST_MODE" == "PEP8_DOC" ]]; then - PYTHONPATH=$PWD:$PYTHONPATH py.test --pep8 -m pep8 -n0 && py.test tests/test_documentation.py && cd docs && python autogen.py && mkdocs build; + PYTHONPATH=$PWD:$PYTHONPATH py.test --pep8 -m pep8 -n0 && py.test tests/test_documentation.py tests/test_doc_auto_generation.py; else - PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/test_documentation.py --ignore=tests/keras/legacy/layers_test.py --cov-config .coveragerc --cov=keras tests/; + PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/test_documentation.py --ignore=tests/test_doc_auto_generation.py --ignore=tests/keras/legacy/layers_test.py --cov-config .coveragerc --cov=keras tests/; fi diff --git a/docs/autogen.py b/docs/autogen.py index 82f729a77e8..901fa3619f5 100644 --- a/docs/autogen.py +++ b/docs/autogen.py @@ -369,8 +369,12 @@ def copy_examples(examples_dir, destination_dir): f_out.write('```') -def generate(): - sources_dir = os.path.join(keras_dir, 'docs', 'sources') +def generate(sources_dir): + """Generates the markdown files for the documentation. + + # Arguments + sources_dir: Where to put the markdown files. + """ template_dir = os.path.join(keras_dir, 'docs', 'templates') if K.backend() != 'tensorflow': @@ -464,4 +468,4 @@ def generate(): if __name__ == '__main__': - generate() + generate(os.path.join(keras_dir, 'docs', 'sources')) diff --git a/tests/test_doc_auto_generation.py b/tests/test_doc_auto_generation.py index 6cdb23f086e..1ad03eddd62 100644 --- a/tests/test_doc_auto_generation.py +++ b/tests/test_doc_auto_generation.py @@ -1,3 +1,4 @@ +import os from markdown import markdown from docs import autogen import pytest @@ -386,5 +387,13 @@ def test_doc_multiple_sections_code(): assert 'def dot(x, y):' in generated +def test_docs_in_custom_destination_dir(tmpdir): + autogen.generate(tmpdir) + assert os.path.isdir(os.path.join(tmpdir, 'layers')) + assert os.path.isdir(os.path.join(tmpdir, 'models')) + assert os.path.isdir(os.path.join(tmpdir, 'examples')) + assert os.listdir(os.path.join(tmpdir, 'examples')) + + if __name__ == '__main__': pytest.main([__file__])