<commit_before>find_program(SPHINX_EXECUTABLE
  NAMES sphinx-build
  HINTS $ENV{SPHINX_DIR}
  PATH_SUFFIXES bin
  DOC "Sphinx documentation generator")

SET(SWIFT_SPHINX_PAPER_SIZE "letter"
  CACHE STRING "Paper size for generated documentation")

SET(SPHINX_ARGS
  -Q
  -D latex_paper_size=${SWIFT_SPHINX_PAPER_SIZE}
  -d ${CMAKE_BINARY_DIR}/doctrees)

if(SPHINX_EXECUTABLE)
  add_custom_target(docs_html ALL
    ${SPHINX_EXECUTABLE} ${SPHINX_ARGS} -b html
      . ${CMAKE_BINARY_DIR}/docs/html
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docs
    COMMENT "Building HTML documentation")

  # Selectively install docs intended for general consumption.
  install(
    FILES
      ${CMAKE_BINARY_DIR}/docs/html/LangRef.html
    DESTINATION share/swift/docs/html)

  install(
    DIRECTORY
      ${CMAKE_BINARY_DIR}/docs/html/_static
      ${CMAKE_BINARY_DIR}/docs/html/whitepaper
    DESTINATION share/swift/docs/html)

else(SPHINX_EXECUTABLE)
  message(WARNING "Unable to find sphinx-build program. Not building docs")
endif(SPHINX_EXECUTABLE)

## Example testing

find_program(LITRE_EXECUTABLE
  NAMES litre
  DOC "LitRe literate programming tool for docutils")

if(LITRE_EXECUTABLE)
  execute_process(
    COMMAND ${LITRE_EXECUTABLE} --cmake_module_path
    OUTPUT_VARIABLE litre_cmake_module_path
    OUTPUT_STRIP_TRAILING_WHITESPACE
    )
  list(APPEND CMAKE_MODULE_PATH ${litre_cmake_module_path})

  file(GLOB_RECURSE rst_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.rst)
  foreach(rst ${rst_files})
    set(test_dir ${CMAKE_CURRENT_BINARY_DIR}/litre-tests/${rst}.litre-tests)
    execute_process(
      COMMAND ${CMAKE_COMMAND} -E make_directory "${test_dir}"
      COMMAND ${LITRE_EXECUTABLE} --dump_dir=${test_dir} --traceback ${CMAKE_CURRENT_SOURCE_DIR}/${rst}
      )
    add_subdirectory(${test_dir} ${test_dir}/build)
  endforeach()
else()
  message(WARNING "LitRe not found; code examples won't be tested.")
endif()

<commit_msg>docs/CMakeLists.txt: documentation<commit_after>find_program(SPHINX_EXECUTABLE
  NAMES sphinx-build
  HINTS $ENV{SPHINX_DIR}
  PATH_SUFFIXES bin
  DOC "Sphinx documentation generator")

SET(SWIFT_SPHINX_PAPER_SIZE "letter"
  CACHE STRING "Paper size for generated documentation")

SET(SPHINX_ARGS
  -Q
  -D latex_paper_size=${SWIFT_SPHINX_PAPER_SIZE}
  -d ${CMAKE_BINARY_DIR}/doctrees)

if(SPHINX_EXECUTABLE)
  add_custom_target(docs_html ALL
    ${SPHINX_EXECUTABLE} ${SPHINX_ARGS} -b html
      . ${CMAKE_BINARY_DIR}/docs/html
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docs
    COMMENT "Building HTML documentation")

  # Selectively install docs intended for general consumption.
  install(
    FILES
      ${CMAKE_BINARY_DIR}/docs/html/LangRef.html
    DESTINATION share/swift/docs/html)

  install(
    DIRECTORY
      ${CMAKE_BINARY_DIR}/docs/html/_static
      ${CMAKE_BINARY_DIR}/docs/html/whitepaper
    DESTINATION share/swift/docs/html)

else(SPHINX_EXECUTABLE)
  message(WARNING "Unable to find sphinx-build program. Not building docs")
endif(SPHINX_EXECUTABLE)

## Example testing

find_program(LITRE_EXECUTABLE
  NAMES litre
  DOC "LitRe literate programming tool for docutils")

if(LITRE_EXECUTABLE)
  # Make the LitreTesting cmake module available
  execute_process(
    COMMAND ${LITRE_EXECUTABLE} --cmake_module_path
    OUTPUT_VARIABLE litre_cmake_module_path
    OUTPUT_STRIP_TRAILING_WHITESPACE
    )
  list(APPEND CMAKE_MODULE_PATH ${litre_cmake_module_path})

  # Find all the .rst files
  file(GLOB_RECURSE rst_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.rst)

  foreach(rst ${rst_files})
    # Prepare a testing directory containing a CMakeLists.txt 
    # and example files extracted from the .rst
    set(test_dir ${CMAKE_CURRENT_BINARY_DIR}/litre-tests/${rst}.litre-tests)
    execute_process(
      COMMAND ${CMAKE_COMMAND} -E make_directory "${test_dir}"
      COMMAND ${LITRE_EXECUTABLE} --dump_dir=${test_dir} --traceback ${CMAKE_CURRENT_SOURCE_DIR}/${rst}
      )
    # Make that directory part of the build
    add_subdirectory(${test_dir} ${test_dir}/build)
  endforeach()
else()
  message(WARNING "LitRe not found; code examples won't be tested.")
endif()


{'fraction_non_alphanumeric': 0.094581519109821, 'fraction_numerical': 0.0, 'mean_word_length': 4.7751396648044695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3905322', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1482, 'n_words': 285}