diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8466ad5a..67df585b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,12 @@ Unreleased `master`_ :Date: YYYY-MM-DD +Added +~~~~~ + +* Domain specific config options ``hawkmoth_clang_c`` and + ``hawkmoth_clang_cpp``. + Changed ~~~~~~~ diff --git a/doc/Makefile.local b/doc/Makefile.local index c4de44a6..ba5f6a2a 100644 --- a/doc/Makefile.local +++ b/doc/Makefile.local @@ -16,7 +16,7 @@ CLEAN := $(CLEAN) $(BUILDDIR) .PHONY: update-examples update-examples: - $(test_dir)/update-examples.py > $(doc_dir)/examples.rst + python3 -m $(test_dir).update_examples > $(doc_dir)/examples.rst # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). diff --git a/doc/extension.rst b/doc/extension.rst index c29e2382..c2df8aac 100644 --- a/doc/extension.rst +++ b/doc/extension.rst @@ -85,6 +85,18 @@ See also additional configuration options in the :ref:`built-in extensions You can also pass in the compiler to use, for example ``get_include_args('gcc')``. +.. py:data:: hawkmoth_clang_c + :type: list + + Arguments to pass to ``clang`` after :data:`hawkmoth_clang` in the C domain + only. + +.. py:data:: hawkmoth_clang_cpp + :type: list + + Arguments to pass to ``clang`` after :data:`hawkmoth_clang` in the C++ domain + only. + .. py:data:: hawkmoth_source_uri :type: str diff --git a/pyproject.toml b/pyproject.toml index ef8171b0..d376f7d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -71,11 +71,16 @@ exclude = [ ] [tool.mypy] -files = [ - "src", +mypy_path = "src:." +packages = [ + "hawkmoth", "test", ] -exclude = "(test/conf\\.py|test/update-examples\\.py)" +exclude = "(test/conf\\.py)" + +[[tool.mypy.overrides]] +module = "test.*" +follow_imports = "skip" [[tool.mypy.overrides]] module = "clang.*" diff --git a/src/hawkmoth/__init__.py b/src/hawkmoth/__init__.py index 1ddc82b7..7a05b24e 100644 --- a/src/hawkmoth/__init__.py +++ b/src/hawkmoth/__init__.py @@ -57,6 +57,11 @@ def __get_clang_args(self): clang_args.extend(self.env.config.hawkmoth_clang.copy()) + if self._domain == 'c': + clang_args.extend(self.env.config.hawkmoth_clang_c.copy()) + else: + clang_args.extend(self.env.config.hawkmoth_clang_cpp.copy()) + clang_args.extend(self.options.get('clang', [])) return clang_args @@ -353,6 +358,8 @@ def setup(app): app.add_config_value('hawkmoth_root', app.confdir, 'env', [str]) app.add_config_value('hawkmoth_clang', [], 'env', [list]) + app.add_config_value('hawkmoth_clang_c', [], 'env', [list]) + app.add_config_value('hawkmoth_clang_cpp', [], 'env', [list]) app.add_config_value('hawkmoth_transform_default', None, 'env', [str]) diff --git a/test/Makefile.local b/test/Makefile.local index bf130318..23500db7 100644 --- a/test/Makefile.local +++ b/test/Makefile.local @@ -17,7 +17,7 @@ test-verbose: # Ensure a) update-examples works, and b) examples have been updated. .PHONY: check-examples check-examples: - $(test_dir)/update-examples.py | diff -u $(doc_dir)/examples.rst - + python3 -m $(test_dir).update_examples | diff -u $(doc_dir)/examples.rst - .PHONY: quick-test quick-test: diff --git a/test/README.rst b/test/README.rst index 57b5d21a..64e8b46f 100644 --- a/test/README.rst +++ b/test/README.rst @@ -56,7 +56,7 @@ Test Cases as Examples The examples in the documentation are generated from test cases under the ``examples`` subdirectory, ensuring the examples actually work. -``make update-examples`` runs ``update-examples.py`` to generate +``make update-examples`` runs ``update_examples.py`` to generate ``doc/examples.rst`` from the example test cases. Running diff --git a/test/conf.py b/test/conf.py index f9143116..6b95fa7b 100644 --- a/test/conf.py +++ b/test/conf.py @@ -29,6 +29,11 @@ # The name of the Pygments (syntax highlighting) style to use. pygments_style = None +# -- Options for Hawkmoth ---------------------------------------------------- +# https://jnikula.github.io/hawkmoth/dev/extension.html#configuration + +hawkmoth_clang_c = ['-std=c17'] +hawkmoth_clang_cpp = ['-std=c++17'] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output diff --git a/test/cpp/template.yaml b/test/cpp/template.yaml index d85dcfd9..460dc87f 100644 --- a/test/cpp/template.yaml +++ b/test/cpp/template.yaml @@ -3,7 +3,4 @@ directives: directive: autodoc arguments: - template.cpp - options: - clang: - - --std=c++17 expected: template.rst diff --git a/test/testenv.py b/test/testenv.py index 4cadef11..77f6e88a 100644 --- a/test/testenv.py +++ b/test/testenv.py @@ -7,6 +7,8 @@ import pytest import strictyaml +from test import conf + testext = '.yaml' testdir = os.path.dirname(os.path.abspath(__file__)) rootdir = os.path.dirname(testdir) @@ -43,7 +45,12 @@ def get_directive_string(self): return directive_str def get_clang_args(self): - clang_args = [] + clang_args = getattr(conf, 'hawkmoth_clang', []) + + if self.domain == 'c': + clang_args.extend(getattr(conf, 'hawkmoth_clang_c', [])) + else: + clang_args.extend(getattr(conf, 'hawkmoth_clang_cpp', [])) clang_args.extend(self.options.get('clang', [])) diff --git a/test/update-examples.py b/test/update_examples.py similarity index 99% rename from test/update-examples.py rename to test/update_examples.py index 0c0e13bf..738c6231 100755 --- a/test/update-examples.py +++ b/test/update_examples.py @@ -6,7 +6,7 @@ import re import sys -import testenv +from test import testenv class ExampleTestcase(testenv.Testcase): pass