integration.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. # MkDocs Integration tests
  3. This is a simple integration test that builds the MkDocs
  4. documentation against all of the builtin themes.
  5. From the root of the MkDocs git repo, use:
  6. python -m mkdocs.tests.integration --help
  7. TODOs
  8. - Build with different configuration options.
  9. - Build documentation other than just MkDocs as it is relatively simple.
  10. """
  11. import click
  12. import logging
  13. import os
  14. import subprocess
  15. from mkdocs import utils
  16. log = logging.getLogger('mkdocs')
  17. DIR = os.path.dirname(__file__)
  18. MKDOCS_CONFIG = os.path.abspath(os.path.join(DIR, '../../mkdocs.yml'))
  19. MKDOCS_THEMES = utils.get_theme_names()
  20. TEST_PROJECTS = os.path.abspath(os.path.join(DIR, 'integration'))
  21. @click.command()
  22. @click.option('--output',
  23. help="The output directory to use when building themes",
  24. type=click.Path(file_okay=False, writable=True),
  25. required=True)
  26. def main(output=None):
  27. log.propagate = False
  28. stream = logging.StreamHandler()
  29. formatter = logging.Formatter(
  30. "\033[1m\033[1;32m *** %(message)s *** \033[0m")
  31. stream.setFormatter(formatter)
  32. log.addHandler(stream)
  33. log.setLevel(logging.DEBUG)
  34. base_cmd = ['mkdocs', 'build', '-s', '-v', '--site-dir', ]
  35. log.debug("Building installed themes.")
  36. for theme in sorted(MKDOCS_THEMES):
  37. log.debug("Building theme: {}".format(theme))
  38. project_dir = os.path.dirname(MKDOCS_CONFIG)
  39. out = os.path.join(output, theme)
  40. command = base_cmd + [out, '--theme', theme]
  41. subprocess.check_call(command, cwd=project_dir)
  42. log.debug("Building test projects.")
  43. for project in os.listdir(TEST_PROJECTS):
  44. log.debug("Building test project: {}".format(project))
  45. project_dir = os.path.join(TEST_PROJECTS, project)
  46. out = os.path.join(output, project)
  47. command = base_cmd + [out, ]
  48. subprocess.check_call(command, cwd=project_dir)
  49. log.debug("Theme and integration builds are in {}".format(output))
  50. if __name__ == '__main__':
  51. main()