Skip to content

Commit

Permalink
Add build targets "format_md" and "test_format_md".
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-rapp committed Jan 3, 2024
1 parent 400502c commit cb34b35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
26 changes: 26 additions & 0 deletions scons/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def __clang_format(directory: str, enforce_changes: bool = False):
run_program('clang-format', *args, *cpp_header_files, *cpp_source_files)


def __mdformat(directory: str, enforce_changes: bool = False):
md_files = glob(path.join(directory, '*.md'))
args = ['--number', '--wrap', 'no']

if not enforce_changes:
args.append('--check')

run_program('mdformat', *args, *md_files)


def check_python_code_style(**_):
"""
Checks if the Python source files adhere to the code style definitions. If this is not the case, an error is raised.
Expand Down Expand Up @@ -82,3 +92,19 @@ def enforce_cpp_code_style(**_):
directory = CPP_MODULE.root_dir
print('Formatting C++ code in directory "' + directory + '"...')
__clang_format(directory, enforce_changes=True)


def check_md_code_style(**_):
"""
Check if the Markdown files adhere to the code style definitions. If this is not the case, an error is raised.
"""
print('Checking Markdown code style in the root directory...')
__mdformat('.')


def enforce_md_code_style(**_):
"""
Enforces the Markdown files to adhere to the code style definitions.
"""
print('Formatting Markdown code style in the root directory...')
__mdformat('.', enforce_changes=True)
24 changes: 15 additions & 9 deletions scons/sconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from functools import reduce
from os import path

from code_style import check_cpp_code_style, check_python_code_style, enforce_cpp_code_style, enforce_python_code_style
from code_style import check_cpp_code_style, check_md_code_style, check_python_code_style, enforce_cpp_code_style, \
enforce_md_code_style, enforce_python_code_style
from compilation import compile_cpp, compile_cython, install_cpp, install_cython, setup_cpp, setup_cython
from documentation import apidoc_cpp, apidoc_cpp_tocfile, apidoc_python, apidoc_python_tocfile, doc
from modules import BUILD_MODULE, CPP_MODULE, DOC_MODULE, PYTHON_MODULE
Expand All @@ -33,9 +34,11 @@ def __print_if_clean(environment, message: str):
TARGET_NAME_TEST_FORMAT = 'test_format'
TARGET_NAME_TEST_FORMAT_PYTHON = TARGET_NAME_TEST_FORMAT + '_python'
TARGET_NAME_TEST_FORMAT_CPP = TARGET_NAME_TEST_FORMAT + '_cpp'
TARGET_NAME_TEST_FORMAT_MD = TARGET_NAME_TEST_FORMAT + '_md'
TARGET_NAME_FORMAT = 'format'
TARGET_NAME_FORMAT_PYTHON = TARGET_NAME_FORMAT + '_python'
TARGET_NAME_FORMAT_CPP = TARGET_NAME_FORMAT + '_cpp'
TARGET_NAME_FORMAT_MD = TARGET_NAME_FORMAT + '_md'
TARGET_NAME_VENV = 'venv'
TARGET_NAME_COMPILE = 'compile'
TARGET_NAME_COMPILE_CPP = TARGET_NAME_COMPILE + '_cpp'
Expand All @@ -54,11 +57,12 @@ def __print_if_clean(environment, message: str):
TARGET_NAME_DOC = 'doc'

VALID_TARGETS = {
TARGET_NAME_TEST_FORMAT, TARGET_NAME_TEST_FORMAT_PYTHON, TARGET_NAME_TEST_FORMAT_CPP, TARGET_NAME_FORMAT,
TARGET_NAME_FORMAT_PYTHON, TARGET_NAME_FORMAT_CPP, TARGET_NAME_VENV, TARGET_NAME_COMPILE, TARGET_NAME_COMPILE_CPP,
TARGET_NAME_COMPILE_CYTHON, TARGET_NAME_INSTALL, TARGET_NAME_INSTALL_CPP, TARGET_NAME_INSTALL_CYTHON,
TARGET_NAME_BUILD_WHEELS, TARGET_NAME_INSTALL_WHEELS, TARGET_NAME_TESTS, TARGET_NAME_TESTS_CPP,
TARGET_NAME_TESTS_PYTHON, TARGET_NAME_APIDOC, TARGET_NAME_APIDOC_CPP, TARGET_NAME_APIDOC_PYTHON, TARGET_NAME_DOC
TARGET_NAME_TEST_FORMAT, TARGET_NAME_TEST_FORMAT_PYTHON, TARGET_NAME_TEST_FORMAT_CPP, TARGET_NAME_TEST_FORMAT_MD,
TARGET_NAME_FORMAT, TARGET_NAME_FORMAT_PYTHON, TARGET_NAME_FORMAT_CPP, TARGET_NAME_FORMAT_MD, TARGET_NAME_VENV,
TARGET_NAME_COMPILE, TARGET_NAME_COMPILE_CPP, TARGET_NAME_COMPILE_CYTHON, TARGET_NAME_INSTALL,
TARGET_NAME_INSTALL_CPP, TARGET_NAME_INSTALL_CYTHON, TARGET_NAME_BUILD_WHEELS, TARGET_NAME_INSTALL_WHEELS,
TARGET_NAME_TESTS, TARGET_NAME_TESTS_CPP, TARGET_NAME_TESTS_PYTHON, TARGET_NAME_APIDOC, TARGET_NAME_APIDOC_CPP,
TARGET_NAME_APIDOC_PYTHON, TARGET_NAME_DOC
}

DEFAULT_TARGET = TARGET_NAME_INSTALL_WHEELS
Expand All @@ -78,14 +82,16 @@ def __print_if_clean(environment, message: str):
# Define targets for checking code style definitions...
target_test_format_python = __create_phony_target(env, TARGET_NAME_TEST_FORMAT_PYTHON, action=check_python_code_style)
target_test_format_cpp = __create_phony_target(env, TARGET_NAME_TEST_FORMAT_CPP, action=check_cpp_code_style)
target_test_format_md = __create_phony_target(env, TARGET_NAME_TEST_FORMAT_MD, action=check_md_code_style)
target_test_format = __create_phony_target(env, TARGET_NAME_TEST_FORMAT)
env.Depends(target_test_format, [target_test_format_python, target_test_format_cpp])
env.Depends(target_test_format, [target_test_format_python, target_test_format_cpp, target_test_format_md])

# Define targets for enforcing code style definitions...
target_format_python = __create_phony_target(env, TARGET_NAME_FORMAT_PYTHON, action=enforce_python_code_style)
target_format_cpp = __create_phony_target(env, TARGET_NAME_FORMAT_CPP, action=enforce_cpp_code_style)
target_format = __create_phony_target(env, TARGET_NAME_FORMAT)
env.Depends(target_format, [target_format_python, target_format_cpp])
target_format_md = __create_phony_target(env, TARGET_NAME_FORMAT_MD, action=enforce_md_code_style)
target_format = __create_phony_target(env, TARGET_NAME_FORMAT, TARGET_NAME_FORMAT_MD)
env.Depends(target_format, [target_format_python, target_format_cpp, target_format_md])

# Define target for installing runtime dependencies...
target_venv = __create_phony_target(env, TARGET_NAME_VENV, action=install_runtime_dependencies)
Expand Down

0 comments on commit cb34b35

Please sign in to comment.