diff --git a/.gitattributes b/.gitattributes index d3559268a6..8c4e05e78a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,8 +8,6 @@ *.txt text=set eol=lf *.yml text=set eol=lf VERSION text=set eol=lf -*.mak text=set eol=lf -Makefile text=set eol=lf License text=set eol=lf *.rc text=set eol=lf *.mako text=set eol=lf diff --git a/.gitignore b/.gitignore index 12899a7278..e36cd9ef22 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,6 @@ generated/*/build/ generated/*/dist/ generated/*/log/ generated/*/*.egg-info/ -generated/driver_file_built -generated/printed_global_files generated/junit/ generated/*/coverage.xml @@ -33,7 +31,6 @@ nirfsaunittest.xml niscopeunittest.xml nitclkunittest.xml codegen.xml -commands.log .vscode/launch.json .vscode/settings.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b793106838..a1b9ddc68c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,12 +21,11 @@ In order to have the ability to build and run the tests you will need a few thin ### Windows: -- Install and enable [Windows Subsystem for Linux](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) -- Install the following in **Windows Subsystem for Linux**: - - GNU Make: ``sudo apt-get install make`` - - zip: ``sudo apt-get install zip`` - - 64-bit [Python](https://www.python.org/downloads/) - -- Use the version that `build_test` uses. See `envlist` definition in [tox.ini](./tox.ini) +- Install 64-bit [Python](https://www.python.org/downloads/) + - Use the version that `build_test` uses. See `envlist` definition in [tox.ini](./tox.ini) + + If you use pyenv-win, make sure the required interpreters are available. + Any version listed when you run `pyenv versions` is available. ### macOS: @@ -42,9 +41,14 @@ In order to have the ability to build and run the tests you will need a few thin ### All: -Once your system has been setup with the above, install required additional Python modules using PyPI. +Install tox using your Python package manager. For example: + + Windows: py -m pip install --upgrade tox + macOS/Linux: python3 -m pip install --user --upgrade tox - sudo pip install pytest tox --upgrade +Tox installs the dependencies for each environment. Install any additional Python versions listed in `envlist` if you want tox to run those test environments; missing interpreters are skipped. + +If you install tox with pipx, make sure its virtual environment uses a Python version supported by this project. If tox was installed while an older pyenv version was selected, uninstall and reinstall tox after selecting a supported version. Building **[`nimi-python`](https://github.com/ni/nimi-python)** @@ -78,6 +82,18 @@ Building **[`nimi-python`](https://github.com/ni/nimi-python)** tox -e clean +1. To generate the code for a subset of the Python bindings, pass arguments to the code generator through `tox`. For example: + + tox -e py312-codegen -- --driver nidmm --driver nitclk + + You can bypass `tox` and run the code generator directly if for some reason you prefer it. + In order to do this, you must install all dependencies as listed in the `deps` section of + [tox.ini](./tox.ini); then run: + + `python -m build.codegen generate [--driver DRIVER ...]` + + The code generator also supports `clean` and `installers` commands. Use `--help` for details. + Updating submodules ------------------- diff --git a/Makefile b/Makefile deleted file mode 100644 index 45a9696d28..0000000000 --- a/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# In alphabetical order except put nifake first and nimodinst/nitclk last -# - nifake first to get the most code generator coverage -# - nimodinst last so that the version from nimodinst is used for any global versions (docs/conf.py) -ALL_DRIVERS := nifake nidcpower nidigital nidmm nifgen nirfsa nirfsg niscope niswitch nise nimodinst nitclk -DRIVERS ?= $(ALL_DRIVERS) - -ROOT_DIR := $(abspath .) -export ROOT_DIR - -# build related source files -BUILD_HELPER_DIR := $(ROOT_DIR)/build -export BUILD_HELPER_DIR - -GENERATED_DIR := $(ROOT_DIR)/generated -export GENERATED_DIR - -include $(BUILD_HELPER_DIR)/Makefile - diff --git a/build.sh b/build.sh deleted file mode 100755 index 8b526bf55a..0000000000 --- a/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Python 3 is required for build.py - -make clean -make - diff --git a/build/Makefile b/build/Makefile deleted file mode 100644 index 0ff8e645a0..0000000000 --- a/build/Makefile +++ /dev/null @@ -1,168 +0,0 @@ -include $(BUILD_HELPER_DIR)/tools.mak - -DEFAULT_TARGETS := module doc_files -export DEFAULT_TARGETS - -GENERATED_DIR := $(ROOT_DIR)/generated -export GENERATED_DIR - -COMMAND_LOG := $(ROOT_DIR)/commands.log -export COMMAND_LOG - -DOCS_DIR := $(ROOT_DIR)/docs -export DOCS_DIR - -STATIC_DOCS_DIR := $(DOCS_DIR)/_static -export STATIC_DOCS_DIR - -ifeq (,$(PRINT)) -_hide_cmds := @ -endif - -# We only add root files if we are building the 'all' target (nothing on the command line) -ifeq (,$(MAKECMDGOALS)) -ROOT_FILES := \ - $(ROOT_DIR)/README.rst \ - -endif - -all: $(DRIVERS) $(ROOT_FILES) - -define per_driver_per_target -$1_$2: start - @echo - @echo "Making $1" - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 MKDIR - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 $2 -endef - -define per_driver_all -$1: start - @echo - @echo "Making $1" - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 MKDIR - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 -endef - -$(foreach d,$(ALL_DRIVERS),$(eval $(call per_driver_all,$(d)))) -$(foreach d,$(ALL_DRIVERS),\ - $(foreach t,$(DEFAULT_TARGETS),\ - $(eval $(call per_driver_per_target,$(d),$(t))))) - -define per_target -$1: - $(foreach d,$(DRIVERS),make --no-print-directory -f src/$(d)/$(d).mak DRIVER=$(d) $1 &&) echo -endef - -$(foreach t,$(DEFAULT_TARGETS),$(eval $(call per_target,$(t)))) - -define per_driver_installers -$1_installers: start - @echo - @echo "Making $1 installers" - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 MKDIR - $(_hide_cmds)make --no-print-directory -s -f src/$1/$1.mak DRIVER=$1 installers -endef - -$(foreach d,$(ALL_DRIVERS),$(eval $(call per_driver_installers,$(d)))) -installers: $(foreach d,$(ALL_DRIVERS), $(d)_installers) - -SUPPRESS_ERROR_OUTPUT ?= 2> /dev/null - -# Keep the generated directory available for CI builds -clean: start - @echo 'Cleaning...' - -$(_hide_cmds)rm -Rf $(GENERATED_DIR)/ $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)find $(ROOT_DIR)/build -path '*/__pycache__/*' -exec rm {} \; $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)find $(ROOT_DIR)/build -name __pycache__ -exec rmdir {} \; $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)find $(ROOT_DIR)/build -name '*.pyc' -exec rm {} \; $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)rm $(foreach d,$(DRIVERS), $(ROOT_DIR)/docs/$(d)/*) $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)rm $(foreach d,$(DRIVERS), $(ROOT_DIR)/docs/$(d)/.readthedocs.yaml) $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)rm -Rf $(ROOT_DIR)/.coverage $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)rm -Rf $(ROOT_DIR)/README.rst $(SUPPRESS_ERROR_OUTPUT) ||: - -$(_hide_cmds)mkdir $(GENERATED_DIR) $(SUPPRESS_ERROR_OUTPUT) ||: - -start: - -@echo "# This is the list of commands that make invoked in order to build nimi-python. If" > $(COMMAND_LOG) - -@echo "# you want to reproduce the build but don't have GNU Make setup in your system, you" >> $(COMMAND_LOG) - -@echo "# can use the commands in this log file." >> $(COMMAND_LOG) - - -# From https://stackoverflow.com/questions/14760124/how-to-split-in-gnu-makefile-list-of-files-into-separate-lines -DRIVER_ALL_TARGETS_HELP := echo Drivers: $(addprefix && echo - ,$(ALL_DRIVERS)) -TARGETS_HELP := echo Targets: $(addprefix && echo - ,$(DEFAULT_TARGETS)) -PER_DRIVER_PER_TARGET := \ - $(foreach d,$(ALL_DRIVERS),\ - $(foreach t,$(DEFAULT_TARGETS),\ - $(d)_$(t))) -DRIVER_TARGETS_HELP := echo Per driver, per target: $(addprefix && echo - ,$(PER_DRIVER_PER_TARGET)) -help: - @echo 'Supported targets:' - @echo '* help' - @echo '* clean' - @echo '* print- (only top level variables)' - @echo '* printvar VAR= (per driver print variable)' - @echo '' - @echo 'Any/multiple target(s) listed below:' - @$(DRIVER_ALL_TARGETS_HELP) - @echo '' - @$(TARGETS_HELP) - @echo '' - @$(DRIVER_TARGETS_HELP) - @echo '' - -# From https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile -print-%: ; $(info $* is $(flavor $*) variable set to [$($*)]) @true - -# Per driver variable printing -per_driver_variable_print = make --no-print-directory -f src/$1/$1.mak DRIVER=$1 print-$2 -.PHONY: -printvar: - $(_hide_cmds)$(foreach d,$(DRIVERS),$(call per_driver_variable_print,$(d),$(VAR)) && ) echo - - -PYTHON_CMD ?= python - -.PHONY: help Makefile - -# For the global files, instead of trying to keep track of which files from the driver builds matter for any target, -# we just say that if anything from any driver built, we will rebuld the global files -export DRIVER_FILE_BUILT = $(GENERATED_DIR)/driver_file_built - -GLOBAL_FILES_STARTED_FILE = $(GENERATED_DIR)/printed_global_files -$(GLOBAL_FILES_STARTED_FILE): $(DRIVER_FILE_BUILT) - @echo - @echo "Making Global Files" - @touch $(GLOBAL_FILES_STARTED_FILE) - -# Executes a command, then logs it to $(COMMAND_LOG). -# $1 is the command. -# We need our own copy that does not touch DRIVER_FILE_BUILT -define global_log_command - $1 - @echo '$1' >> $(COMMAND_LOG) -endef - -$(ROOT_DIR)/README.rst: $(GLOBAL_FILES_STARTED_FILE) - $(call trace_to_console, "Creating Root",$(notdir $@)) - $(_hide_cmds)$(call global_log_command,cat $(STATIC_DOCS_DIR)/status_project.inc \ - $(STATIC_DOCS_DIR)/about.inc \ - $(DOCS_DIR)/*/status.inc \ - $(STATIC_DOCS_DIR)/installation.inc \ - $(STATIC_DOCS_DIR)/contributing.inc \ - $(STATIC_DOCS_DIR)/nidmm_usage.inc \ - $(STATIC_DOCS_DIR)/support.inc \ - $(STATIC_DOCS_DIR)/documentation.inc \ - $(STATIC_DOCS_DIR)/license.inc > $@) - -# Any step that any driver build does that would invalidate unit testing, flake8 or generated html -# needs to delete this file. This will trigger a tox run. -TOX_RUN_DONE := $(GENERATED_DIR)/tox_run_done -export TOX_RUN_DONE - -test: $(TOX_RUN_DONE) - -$(TOX_RUN_DONE): - @echo - $(call trace_to_console, "Running tox",$@) - $(_hide_cmds)$(call make_with_tracking_file,$@,tox) diff --git a/build/__main__.py b/build/__main__.py deleted file mode 100644 index 1d83a615d7..0000000000 --- a/build/__main__.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/python3 - -import argparse -import logging -import os -import pprint -import sys - -# Part of this package -import generate_template -import utilities - -pp = pprint.PrettyPrinter(indent=4) - -# Setup the required arguments for this script -usage = "Codegen driver files" - -parser = argparse.ArgumentParser(description=usage, prog='build') -verbosity_group = parser.add_argument_group("Verbosity, Logging & Debugging") -verbosity_group.add_argument( - "-v", "--verbose", - action="count", dest="verbose", default=0, - help="Verbose output") -verbosity_group.add_argument( - "--test", - action="store_true", dest="test", default=False, - help="Run doctests and quit") -verbosity_group.add_argument( - "--log-file", - action="store", dest="logfile", default=None, - help="Send logging to listed file instead of stdout") -build_group = parser.add_argument_group("Build") -build_group.add_argument( - "--metadata", - action='append', dest='metadata', default=[], - help='Absolute or relative path to metadata package. Multiple allowed. Will build in order added to command line.') -build_group.add_argument( - "--include-grpc-support", - action='store_true', dest='include_grpc_support', default=[], - help='Include gRPC support in the generated files.') -utility_group = parser.add_argument_group("Utility") -utility_group.add_argument( - "--template", - action="store", dest="template", default=None, required=True, - help="Mako template to use. Can only be used if no actions.") -utility_group.add_argument( - "--dest-dir", - action="store", dest="dest_dir", default=None, required=False, - help="Output folder.") -utility_group.add_argument( - "--dest-file", - action="store", dest="dest_file", default=None, required=False, - help="Output file name. Optional. If not set, file will be named based on mako template name.") -args = parser.parse_args() - -if args.verbose > 1: - utilities.configure_logging(logging.DEBUG, args.logfile) -elif args.verbose == 1: - utilities.configure_logging(logging.INFO, args.logfile) -else: - utilities.configure_logging(logging.WARNING, args.logfile) - -logging.info(pp.pformat(args)) - -for m in args.metadata: - if not os.path.isabs(m): - m = os.path.normpath(os.path.join(os.getcwd(), m)) - metadata = utilities.load_build(m) - - if args.dest_dir is None: - logging.error('--dest-dir is required when using --template') - sys.exit(1) - - template_params = {} - template_params['metadata'] = metadata - template_params['include_grpc_support'] = args.include_grpc_support - - logging.debug(pp.pformat(template_params)) - - file_name = args.dest_file - if file_name is None: - file_name = os.path.basename(args.template).replace('.mako', '') - dest_file = os.path.join(args.dest_dir, file_name) - generate_template.generate_template(args.template, template_params, dest_file) diff --git a/build/codegen.py b/build/codegen.py new file mode 100644 index 0000000000..cfef930134 --- /dev/null +++ b/build/codegen.py @@ -0,0 +1,446 @@ +"""Generate the Python bindings, documentation and installers. + +Run from anywhere with ``python -m build.codegen {generate,clean,installers}``. +""" + +import argparse +from collections.abc import Iterable, Sequence +from dataclasses import dataclass +import logging +import os +from pathlib import Path +import re +import shutil +import subprocess +import sys +from types import ModuleType +import zipfile + +from build import configure_logging +from build import generate_template +from build.helper import metadata_add_all +from build.utilities import load_build + +ROOT_DIR = Path(__file__).resolve().parent.parent +BUILD_HELPER_DIR = ROOT_DIR / 'build' +TEMPLATES_DIR = BUILD_HELPER_DIR / 'templates' +GENERATED_DIR = ROOT_DIR / 'generated' +DOCS_DIR = ROOT_DIR / 'docs' +STATIC_DOCS_DIR = DOCS_DIR / '_static' +SRC_DIR = ROOT_DIR / 'src' +SHARED_PROTOS_DIR = SRC_DIR / 'shared_protos' +NI_APIS_PROTOS_DIR = ROOT_DIR / 'third_party' / 'ni-apis' / 'ni' / 'grpcdevice' / 'v1' + +_bindings_with_processed_metadata: set[str] = set() + +DEFAULT_PY_FILES_TO_GENERATE = ( + '_attributes.py', + 'enums.py', + '_library.py', + '_library_interpreter.py', + '_library_singleton.py', + 'session.py', + 'errors.py', + 'unit_tests/_mock_helper.py', + 'unit_tests/_matchers.py', + '__init__.py', + '_converters.py', + 'VERSION', +) + +GRPC_PY_FILES_TO_GENERATE = ( + '_grpc_stub_interpreter.py', + 'grpc_session_options.py', +) + +DEFAULT_PY_FILES_TO_COPY = ( + '_visatype.py', +) + +# Documentation files that are generated for every binding, as (file name, template name). +# {driver} is replaced by the name of the binding (API). +DEFAULT_DOC_FILES_TO_GENERATE = ( + ('about_{driver}.inc', 'about_driver.inc.mako'), + ('index.rst', 'index.rst.mako'), + ('{driver}.rst', 'driver.rst.mako'), + ('enums.rst', 'enums.rst.mako'), + ('examples.rst', 'examples.rst.mako'), + ('installation.inc', 'installation.inc.mako'), + ('status.inc', 'status.inc.mako'), + ('class.rst', 'class.rst.mako'), + ('toc.inc', 'toc.inc.mako'), + ('errors.rst', 'errors.rst.mako'), + ('rep_caps.rst', 'rep_caps.rst.mako'), +) + +GRPC_DOC_FILES_TO_GENERATE = ( + ('grpc_session_options.rst', 'grpc_session_options.rst.mako'), +) + +DOC_CONFIG_FILES_TO_GENERATE = ( + ('conf.py', 'conf.py.mako'), + ('.readthedocs.yaml', '.readthedocs.yaml.mako'), +) + + +@dataclass(frozen=True) +class PythonBindingConfig: + """Configuration and resource lookup for a Python binding.""" + name: str + extra_py_files: tuple[str, ...] = () + omit_py_files: tuple[str, ...] = () + omit_doc_files: tuple[str, ...] = () + custom_types: tuple[str, ...] = () + has_docs: bool = True + proto_file_name: str | None = None + + @property + def src_dir(self) -> Path: + return SRC_DIR / self.name + + @property + def metadata_dir(self) -> Path: + return self.src_dir / 'metadata' + + @property + def output_dir(self) -> Path: + return GENERATED_DIR / self.name + + @property + def module_dir(self) -> Path: + return self.output_dir / self.name + + @property + def docs_dir(self) -> Path: + return DOCS_DIR / self.name + + @property + def proto_file(self) -> Path: + return self.metadata_dir / (self.proto_file_name or f'{self.name}.proto') + + @property + def grpc_supported(self) -> bool: + return self.proto_file.exists() + + def get_template(self, template_name: str) -> Path: + """Use the binding's own template if it has one, otherwise the shared one.""" + binding_template = self.src_dir / 'templates' / template_name + if binding_template.exists(): + return binding_template + return TEMPLATES_DIR / template_name + + def py_files_to_generate(self) -> tuple[str, ...]: + files = DEFAULT_PY_FILES_TO_GENERATE + self.extra_py_files + if self.grpc_supported: + stem = self.proto_file.stem + files += GRPC_PY_FILES_TO_GENERATE + (f'{stem}_pb2.py', f'{stem}_pb2_grpc.py', 'nidevice_pb2.py', 'nidevice_pb2_grpc.py') + return tuple(f for f in files if f not in self.omit_py_files) + + def doc_files_to_generate(self) -> tuple[tuple[str, str], ...]: + """Returns (file name, template name) pairs.""" + files = DEFAULT_DOC_FILES_TO_GENERATE + if self.grpc_supported: + files += GRPC_DOC_FILES_TO_GENERATE + return tuple( + (name.format(driver=self.name), template) + for name, template in files + if name not in self.omit_doc_files) + + def unit_test_files_to_copy(self) -> tuple[Path, ...]: + return tuple(sorted((self.src_dir / 'unit_tests').glob('*.py'))) + + def example_files(self) -> tuple[Path, ...]: + examples_dir = self.src_dir / 'examples' + if not examples_dir.is_dir(): + return () + return tuple( + f for f in sorted(examples_dir.rglob('*')) + if f.is_file() and '__pycache__' not in f.parts and f.suffix != '.pyc') + + def readme_parts(self) -> tuple[Path, ...]: + """Files that are concatenated to create the binding's README.rst.""" + return ( + STATIC_DOCS_DIR / 'status_project.inc', + self.docs_dir / f'about_{self.name}.inc', + self.docs_dir / 'status.inc', + self.docs_dir / 'installation.inc', + STATIC_DOCS_DIR / 'contributing.inc', + STATIC_DOCS_DIR / f'{self.name}_usage.inc', + STATIC_DOCS_DIR / 'support.inc', + STATIC_DOCS_DIR / f'{self.name}_documentation.inc', + STATIC_DOCS_DIR / 'license.inc', + ) + + +# In alphabetical order except put nifake first +# - nifake first to serve as the canary in the coal mine for codegen issues. +BINDING_CONFIGS = {d.name: d for d in ( + PythonBindingConfig( + 'nifake', + extra_py_files=('_complextype.py',), + custom_types=('custom_struct.py', 'custom_struct_typedef.py', 'custom_struct_nested_typedef.py'), + has_docs=False), + PythonBindingConfig( + 'nidcpower', + custom_types=('lcr_load_compensation_spot.py', 'lcr_measurement.py')), + PythonBindingConfig( + 'nidigital', + custom_types=('history_ram_cycle_information.py',), + proto_file_name='nidigitalpattern.proto'), + PythonBindingConfig( + 'nidmm', + omit_doc_files=('rep_caps.rst',)), + PythonBindingConfig('nifgen'), + PythonBindingConfig( + 'nimodinst', + omit_py_files=('enums.py', '_attributes.py'), + omit_doc_files=('rep_caps.rst', 'enums.rst')), + PythonBindingConfig( + 'nirfsa', + extra_py_files=('_complextype.py',), + custom_types=('coefficient_info_type.py', 'waveform_info.py', 'spectrum_info_type.py')), + PythonBindingConfig( + 'nirfsg', + extra_py_files=('_complextype.py',)), + PythonBindingConfig( + 'niscope', + custom_types=('waveform_info.py', 'measurement_stats.py')), + PythonBindingConfig('niswitch'), + PythonBindingConfig( + 'nise', + omit_py_files=('_attributes.py',), + omit_doc_files=('rep_caps.rst',)), + PythonBindingConfig( + 'nitclk', + omit_py_files=('enums.py',), + omit_doc_files=('rep_caps.rst', 'enums.rst')), +)} + + +def _trace(action: str, path: Path) -> None: + path = Path(path) + try: + path = path.relative_to(ROOT_DIR) + except ValueError: + pass + print(f'{action:>15}: {path}') + + +def root_readme_parts() -> tuple[Path, ...]: + binding_status_files = tuple(sorted(DOCS_DIR.glob('*/status.inc'))) + return ( + STATIC_DOCS_DIR / 'status_project.inc', + STATIC_DOCS_DIR / 'about.inc', + *binding_status_files, + STATIC_DOCS_DIR / 'installation.inc', + STATIC_DOCS_DIR / 'contributing.inc', + STATIC_DOCS_DIR / 'nidmm_usage.inc', + STATIC_DOCS_DIR / 'support.inc', + STATIC_DOCS_DIR / 'documentation.inc', + STATIC_DOCS_DIR / 'license.inc', + ) + + +def rewrite_pb2_imports(contents: bytes, proto_stem: str) -> bytes: + """Make the generated modules import each other as part of the binding package.""" + for stem in ('nidevice', proto_stem): + contents = re.sub(rb'^import ' + stem.encode() + rb'_pb2', b'from . import ' + stem.encode() + rb'_pb2', contents, flags=re.MULTILINE) + return contents + + +def _load_metadata(binding_config: PythonBindingConfig) -> ModuleType: + # Every template must start from freshly loaded metadata because loading it modifies it in place. + for name in [n for n in sys.modules if n == 'metadata' or n.startswith('metadata.')]: + del sys.modules[name] + # The processed metadata files are the same every time, so only write them once per binding. + metadata_add_all.write_processed_metadata = binding_config.name not in _bindings_with_processed_metadata + _bindings_with_processed_metadata.add(binding_config.name) + return load_build(str(binding_config.metadata_dir)) + + +def render_template(binding_config: PythonBindingConfig, template: Path, dest_file: Path) -> None: + _trace('Generating', dest_file) + Path(dest_file).parent.mkdir(parents=True, exist_ok=True) + template_params = { + 'metadata': _load_metadata(binding_config), + 'include_grpc_support': binding_config.grpc_supported, + } + generate_template(str(template), template_params, str(dest_file)) + + +def copy_file(source: Path, dest_file: Path) -> None: + _trace('Copying', dest_file) + Path(dest_file).parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source, dest_file) + + +def concatenate_files(sources: Iterable[Path], dest_file: Path) -> None: + _trace('Creating', dest_file) + Path(dest_file).parent.mkdir(parents=True, exist_ok=True) + with open(dest_file, 'wb') as dest: + for source in sources: + dest.write(Path(source).read_bytes()) + + +def generate_pb2_files(binding_config: PythonBindingConfig) -> None: + stem = binding_config.proto_file.stem + proto_dirs = (binding_config.metadata_dir, SHARED_PROTOS_DIR, NI_APIS_PROTOS_DIR) + for proto_stem in (stem, 'nidevice'): + _trace('Generating', binding_config.module_dir / f'{proto_stem}_pb2.py and {proto_stem}_pb2_grpc.py') + command = [sys.executable, '-m', 'grpc_tools.protoc'] + command += [f'-I={d}' for d in proto_dirs] + command += [f'--python_out={binding_config.module_dir}', f'--grpc_python_out={binding_config.module_dir}', f'{proto_stem}.proto'] + subprocess.run(command, cwd=ROOT_DIR, check=True) + for suffix in ('_pb2.py', '_pb2_grpc.py'): + for proto_stem in (stem, 'nidevice'): + pb2_file = binding_config.module_dir / f'{proto_stem}{suffix}' + pb2_file.write_bytes(rewrite_pb2_imports(pb2_file.read_bytes(), stem)) + + +def zip_examples(binding_config: PythonBindingConfig) -> None: + files = binding_config.example_files() + if not files: + return + examples_dir = binding_config.src_dir / 'examples' + zip_path = GENERATED_DIR / 'examples' / f'{binding_config.name}_examples.zip' + _trace('Zipping', zip_path) + zip_path.parent.mkdir(parents=True, exist_ok=True) + with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as zip_file: + for f in files: + zip_file.write(f, f.relative_to(examples_dir).as_posix()) + + +def generate_python_binding(binding_config: PythonBindingConfig) -> None: + print() + print(f'Making {binding_config.name}') + + for file_name in binding_config.py_files_to_generate(): + if file_name.endswith(('_pb2.py', '_pb2_grpc.py')): + continue + dest = binding_config.module_dir / file_name + render_template(binding_config, binding_config.get_template(Path(file_name).name + '.mako'), dest) + if binding_config.grpc_supported: + generate_pb2_files(binding_config) + + for file_name in DEFAULT_PY_FILES_TO_COPY: + copy_file(TEMPLATES_DIR / file_name, binding_config.module_dir / file_name) + for file_name in binding_config.custom_types: + copy_file(binding_config.src_dir / 'custom_types' / file_name, binding_config.module_dir / file_name) + for source in binding_config.unit_test_files_to_copy(): + copy_file(source, binding_config.module_dir / 'unit_tests' / source.name) + + render_template(binding_config, TEMPLATES_DIR / 'setup.py.mako', binding_config.output_dir / 'setup.py') + render_template(binding_config, TEMPLATES_DIR / 'tox-system_tests.ini.mako', binding_config.output_dir / 'tox-system_tests.ini') + + if binding_config.has_docs: + for file_name, template_name in binding_config.doc_files_to_generate(): + render_template(binding_config, binding_config.get_template(template_name), binding_config.docs_dir / file_name) + for file_name, template_name in DOC_CONFIG_FILES_TO_GENERATE: + render_template(binding_config, binding_config.get_template(template_name), binding_config.docs_dir / file_name) + + # We can't build the actual readme for nifake since not all the files are created. + # A placeholder is needed for inclusion into the wheel that will never be used. + if binding_config.has_docs: + concatenate_files(binding_config.readme_parts(), binding_config.output_dir / 'README.rst') + else: + copy_file(ROOT_DIR / 'LICENSE', binding_config.output_dir / 'README.rst') + + zip_examples(binding_config) + + +def generate(binding_configs: Iterable[PythonBindingConfig], include_root_readme: bool) -> None: + # The templates and metadata processing use paths relative to the root of the repository. + os.chdir(ROOT_DIR) + GENERATED_DIR.mkdir(exist_ok=True) + for bc in binding_configs: + generate_python_binding(bc) + if include_root_readme: + print() + print('Making Global Files') + concatenate_files(root_readme_parts(), ROOT_DIR / 'README.rst') + + +def clean(binding_configs: Iterable[PythonBindingConfig]) -> None: + print('Cleaning...') + shutil.rmtree(GENERATED_DIR, ignore_errors=True) + for pycache_dir in BUILD_HELPER_DIR.rglob('__pycache__'): + shutil.rmtree(pycache_dir, ignore_errors=True) + for pyc_file in BUILD_HELPER_DIR.rglob('*.pyc'): + pyc_file.unlink() + for bc in binding_configs: + if bc.docs_dir.is_dir(): + for doc_file in bc.docs_dir.iterdir(): + if doc_file.is_file(): + doc_file.unlink() + (ROOT_DIR / '.coverage').unlink(missing_ok=True) + (ROOT_DIR / 'README.rst').unlink(missing_ok=True) + # Keep the generated directory available for CI builds + GENERATED_DIR.mkdir(exist_ok=True) + + +def installers(binding_configs: Iterable[PythonBindingConfig], verbose: bool) -> None: + for bc in binding_configs: + print() + print(f'Making {bc.name} installers') + log_file = bc.output_dir / 'log' / 'sdist_wheel.log' + log_file.parent.mkdir(parents=True, exist_ok=True) + _trace('Creating sdist and wheel', bc.output_dir / 'dist') + result = subprocess.run( + [sys.executable, '-m', 'build'], + cwd=bc.output_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + log_file.write_bytes(result.stdout) + if verbose or result.returncode != 0: + sys.stdout.write(result.stdout.decode(errors='replace')) + if result.returncode != 0: + sys.exit(f'Building the installers for {bc.name} failed. See {log_file}') + + +def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace: + common = argparse.ArgumentParser(add_help=False) + common.add_argument( + '-v', '--verbose', action='count', default=0, + help='Verbose output') + common.add_argument( + '--log-file', default=None, + help='Send logging to listed file instead of stdout') + + drivers_parent = argparse.ArgumentParser(add_help=False) + drivers_parent.add_argument( + '--driver', action='append', choices=list(BINDING_CONFIGS), dest='drivers', metavar='DRIVER', + help=f'Driver to process. Can be repeated. Default is all drivers: {", ".join(BINDING_CONFIGS)}') + + parser = argparse.ArgumentParser(prog='build.codegen', description=__doc__.splitlines()[0]) + subparsers = parser.add_subparsers(dest='command', required=True) + subparsers.add_parser( + 'generate', parents=[common, drivers_parent], + help='Generate bindings, documentation and READMEs. The root README.rst is only generated for all drivers.') + subparsers.add_parser( + 'clean', parents=[common, drivers_parent], + help='Delete generated files') + subparsers.add_parser( + 'installers', parents=[common, drivers_parent], + help='Build the sdist and wheel for each driver from generated/. Run generate first.') + return parser.parse_args(argv) + + +def main(argv: Sequence[str] | None = None) -> None: + args = parse_args(argv) + + if args.verbose > 1: + configure_logging(logging.DEBUG, args.log_file) + elif args.verbose == 1: + configure_logging(logging.INFO, args.log_file) + else: + configure_logging(logging.WARNING, args.log_file) + + binding_configs = [BINDING_CONFIGS[name] for name in args.drivers] if args.drivers else list(BINDING_CONFIGS.values()) + if args.command == 'generate': + generate(binding_configs, include_root_readme=not args.drivers) + elif args.command == 'clean': + clean(binding_configs) + elif args.command == 'installers': + installers(binding_configs, args.verbose > 0) + + +if __name__ == '__main__': + main() diff --git a/build/defines.mak b/build/defines.mak deleted file mode 100644 index be6c10fe90..0000000000 --- a/build/defines.mak +++ /dev/null @@ -1,97 +0,0 @@ -OUTPUT_DIR := $(GENERATED_DIR)/$(DRIVER) -LOG_DIR := $(OUTPUT_DIR)/log -MODULE_DIR := $(OUTPUT_DIR)/$(DRIVER) -UNIT_TEST_DIR := $(MODULE_DIR)/unit_tests -TEMPLATE_DIR := $(BUILD_HELPER_DIR)/templates -TOX_INI := $(OUTPUT_DIR)/tox.ini - -DRIVER_DIR := $(ROOT_DIR)/src/$(DRIVER) -METADATA_DIR := $(DRIVER_DIR)/metadata -METADATA_FILES := $(wildcard $(METADATA_DIR)/*.py) -SHARED_PROTOS_DIR := $(ROOT_DIR)/src/shared_protos -NI_APIS_PROTOS_DIR := $(ROOT_DIR)/third_party/ni-apis/ni/grpcdevice/v1 -PROTO_DIRS := $(METADATA_DIR) $(SHARED_PROTOS_DIR) $(NI_APIS_PROTOS_DIR) -PROTO_FILE ?= $(METADATA_DIR)/$(DRIVER).proto - -BUILD_HELPER_SCRIPTS := $(wildcard $(BUILD_HELPER_DIR)/*.py $(BUILD_HELPER_DIR)/helper/*.py) - -DRIVER_DOCS_DIR := $(DOCS_DIR)/$(DRIVER) - -MKDIRECTORIES += \ - $(DRIVER_DOCS_DIR) \ - $(OUTPUT_DIR) \ - $(MODULE_DIR) \ - $(UNIT_TEST_DIR) \ - $(LOG_DIR) \ - -VPATH = $(TEMPLATE_DIR) - -true := T -false := -GRPC_SUPPORTED := $(if $(wildcard $(PROTO_FILE)),$(true)) - -PYTHON_CMD ?= python -GRPC_SUPPORT_PARAM := $(if $(GRPC_SUPPORTED),--include-grpc-support) -define GENERATE_SCRIPT -$(PYTHON_CMD) -m build --template $1 --dest-dir $2 --metadata $3 $(if $4,--dest-file $4) $(if $(PRINT),-v,) $(GRPC_SUPPORT_PARAM) -endef - -ifeq (,$(PRINT)) -_hide_cmds := @ -LOG_OUTPUT := > -else -LOG_OUTPUT := | tee -endif - -TARGETS := $(filter-out run_unit_tests,$(DEFAULT_TARGETS)) - -.PHONY: -all: $(TARGETS) - -DEFAULT_PY_FILES_TO_GENERATE := \ - _attributes.py \ - enums.py \ - _library.py \ - _library_interpreter.py \ - _library_singleton.py \ - session.py \ - errors.py \ - unit_tests/_mock_helper.py \ - unit_tests/_matchers.py \ - __init__.py \ - _converters.py \ - VERSION \ - $(if $(GRPC_SUPPORTED), \ - _grpc_stub_interpreter.py \ - grpc_session_options.py \ - $(basename $(notdir $(PROTO_FILE)))_pb2.py \ - $(basename $(notdir $(PROTO_FILE)))_pb2_grpc.py \ - nidevice_pb2.py \ - nidevice_pb2_grpc.py \ - ) \ - -DEFAULT_PY_FILES_TO_COPY := \ - _visatype.py \ - -DEFAULT_RST_FILES_TO_GENERATE := \ - about_$(DRIVER).inc \ - index.rst \ - $(DRIVER).rst \ - enums.rst \ - examples.rst \ - installation.inc \ - status.inc \ - class.rst \ - toc.inc \ - errors.rst \ - rep_caps.rst \ - $(if $(GRPC_SUPPORTED), \ - grpc_session_options.rst \ - ) \ - -DEFAULT_SPHINX_CONF_PY := $(DRIVER_DOCS_DIR)/conf.py -DEFAULT_READTHEDOCS_CONFIG := $(DRIVER_DOCS_DIR)/.readthedocs.yaml - -# Files for tracking parts of the build -SDIST_WHEEL_BUILD_DONE := $(LOG_DIR)/sdist_wheel_build_done -GENERATED_FILES_COPY_DONE := $(LOG_DIR)/generated_files_copy_done diff --git a/build/helper/metadata_add_all.py b/build/helper/metadata_add_all.py index 3d85e7f97b..432ffe543e 100644 --- a/build/helper/metadata_add_all.py +++ b/build/helper/metadata_add_all.py @@ -23,6 +23,10 @@ pp = pprint.PrettyPrinter(indent=4, width=80) +# Writing generated/processed_metadata is a debugging aid and is slow. Code generation turns this off +# when it loads the same metadata again. +write_processed_metadata = True + # Functions to add information to metadata structures that are specific to our codegen needs. @@ -804,6 +808,11 @@ def add_all_metadata(functions, attributes, enums, config, persist_output=True): if not persist_output: return config + if not write_processed_metadata: + # The files are only a debugging aid, but keep the metadata the same as when they are written + del config['modules'] + return config + if not os.path.exists(metadata_dir): os.makedirs(metadata_dir) diff --git a/build/rules.mak b/build/rules.mak deleted file mode 100644 index 03a9bcbf93..0000000000 --- a/build/rules.mak +++ /dev/null @@ -1,160 +0,0 @@ - -include $(BUILD_HELPER_DIR)/tools.mak - -README := $(OUTPUT_DIR)/README.rst -SETUP := $(OUTPUT_DIR)/setup.py -TOX_INI := $(OUTPUT_DIR)/tox-system_tests.ini - -MODULE_FILES := \ - $(addprefix $(MODULE_DIR)/,$(MODULE_FILES_TO_GENERATE)) \ - $(addprefix $(MODULE_DIR)/,$(MODULE_FILES_TO_COPY)) \ - $(addprefix $(MODULE_DIR)/,$(CUSTOM_TYPES_TO_COPY)) \ - $(README) \ - $(SETUP) \ - $(TOX_INI) \ - -RST_FILES := \ - $(addprefix $(DRIVER_DOCS_DIR)/,$(RST_FILES_TO_GENERATE)) \ - -EXAMPLE_FILES := $(if $(wildcard src/$(DRIVER)/examples/*),$(shell find src/$(DRIVER)/examples/* -type f -print),) - -# If there are any examples, we will need to build the examples zip file for this driver -ifneq (,$(EXAMPLE_FILES)) - -EXAMPLES_DIR := $(GENERATED_DIR)/examples -MKDIRECTORIES += $(EXAMPLES_DIR) -DRIVER_EXAMPLES_ZIP_FILE := $(EXAMPLES_DIR)/$(DRIVER)_examples.zip -MODULE_FILES += $(DRIVER_EXAMPLES_ZIP_FILE) - -endif # ifneq (,$(EXAMPLE_FILES)) - -MKDIR: $(MKDIRECTORIES) - -define mkdir_rule -$1: - $(call trace_to_console, "Making dir",$1) - $(_hide_cmds)$(call log_command,mkdir -p $1) -endef -$(foreach d,$(MKDIRECTORIES),$(eval $(call mkdir_rule,$(d)))) - -# We set up some additional dependencies for specific files -# examples.rst needs to use find since there may be folders of files and it needs to be recursive. wildcard is not recursive -$(MODULE_DIR)/session.py: $(wildcard $(TEMPLATE_DIR)/session.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/session.py/*.mako) -$(MODULE_DIR)/_grpc_stub_interpreter.py: $(wildcard $(TEMPLATE_DIR)/_grpc_stub_interpreter.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/_grpc_stub_interpreter.py/*.mako) -$(MODULE_DIR)/_library_interpreter.py: $(wildcard $(TEMPLATE_DIR)/_library_interpreter.py/*.mako) $(wildcard $(DRIVER_DIR)/templates/_library_interpreter.py/*.mako) -$(DRIVER_DOCS_DIR)/class.rst: $(wildcard $(TEMPLATE_DIR)/functions.rst/*.mako) $(wildcard $(DRIVER_DIR)/templates/functions.rst/*.mako) -$(DRIVER_DOCS_DIR)/examples.rst: $(EXAMPLE_FILES) $(MODULE_DIR)/VERSION - -$(MODULE_DIR)/%.py: %.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(MODULE_DIR)/unit_tests/%.py: %.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(MODULE_DIR)/%: %.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(MODULE_DIR)/%_pb2.py: %.proto - $(call trace_to_console, "Generating",$@ and $(notdir $*)_pb2_grpc.py) - $(_hide_cmds)$(call log_command,python -m grpc_tools.protoc $(addprefix -I=,$(PROTO_DIRS)) --python_out=$(MODULE_DIR) --grpc_python_out=$(MODULE_DIR) $*.proto) - $(_hide_cmds)$(call log_command,sed -i 's/^import nidevice_pb2/from . import nidevice_pb2/' $(MODULE_DIR)/$*_pb2*.py) - $(_hide_cmds)$(call log_command,sed -i 's/^import $(notdir $*)_pb2/from . import $(notdir $*)_pb2/' $(MODULE_DIR)/$*_pb2*.py) - -vpath %.proto $(PROTO_DIRS) - -$(MODULE_DIR)/%_pb2_grpc.py: $(MODULE_DIR)/%_pb2.py - -$(MODULE_DIR)/%.py: %.py - $(call trace_to_console, "Copying",$@) - $(_hide_cmds)cp $< $@ - -$(MODULE_DIR)/%.py: $(DRIVER_DIR)/custom_types/%.py - $(call trace_to_console, "Copying",$@) - $(_hide_cmds)cp $< $@ - -$(DRIVER_DOCS_DIR)/%.rst: %.rst.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(DRIVER_DOCS_DIR)/$(DRIVER).rst: driver.rst.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR), $(notdir $@))) - -$(DRIVER_DOCS_DIR)/%.inc: %.inc.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(DRIVER_DOCS_DIR)/about_$(DRIVER).inc: about_driver.inc.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR), $(notdir $@))) - -$(SPHINX_CONF_PY): $(TEMPLATE_DIR)/conf.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(READTHEDOCS_CONFIG): $(TEMPLATE_DIR)/.readthedocs.yaml.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(DRIVER_EXAMPLES_ZIP_FILE): $(EXAMPLE_FILES) - $(call trace_to_console, "Zipping",$@) - $(_hide_cmds)$(call log_command,cd src/$(DRIVER)/examples && zip -u -r -9 $@ * || ([ $$? -eq 12 ] && exit 0) || exit) - -UNIT_TEST_FILES_TO_COPY := $(wildcard $(DRIVER_DIR)/unit_tests/*.py) -UNIT_TEST_FILES := $(addprefix $(UNIT_TEST_DIR)/,$(notdir $(UNIT_TEST_FILES_TO_COPY))) - -$(UNIT_TEST_DIR)/%.py: $(DRIVER_DIR)/unit_tests/%.py - $(call trace_to_console, "Copying",$@) - $(_hide_cmds)$(call log_command,cp $< $@) - -clean: - -.PHONY: module doc_files sdist wheel installers -module: $(MODULE_FILES) $(UNIT_TEST_FILES) -doc_files: $(RST_FILES) $(SPHINX_CONF_PY) $(READTHEDOCS_CONFIG) -installers: sdist wheel - -$(UNIT_TEST_FILES): $(MODULE_FILES) - -$(SETUP): $(TEMPLATE_DIR)/setup.py.mako $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -$(TOX_INI): $(TEMPLATE_DIR)/tox-system_tests.ini.mako $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call log_command,$(call GENERATE_SCRIPT, $<, $(dir $@), $(METADATA_DIR))) - -sdist wheel: $(SDIST_WHEEL_BUILD_DONE) - -$(SDIST_WHEEL_BUILD_DONE): # codegen should have already run or just use what is in git - $(call trace_to_console, "Creating sdist and wheel",$(OUTPUT_DIR)/dist) - $(_hide_cmds)$(call log_command_no_tracking,cd $(OUTPUT_DIR) && $(PYTHON_CMD) -m build $(LOG_OUTPUT) $(LOG_DIR)/sdist_wheel.log) - $(_hide_cmds)$(call log_command_no_tracking,touch $@) - -# If we are building nifake, we just need a placeholder file for inclusion into the wheel that will never be used. We can't build the actual readme since not all the files are created -ifeq (nifake,$(DRIVER)) -$(README): - $(call trace_to_console, "Copying",$@) - $(_hide_cmds)$(call log_command,cp $(ROOT_DIR)/LICENSE $@) - -else -# We piece together the readme files instead of relying on the rst include directive because we need these files to be standalone and not require any additional files that are in specific locations. -$(README): $(RST_FILES) $(wildcard $(STATIC_DOCS_DIR)/*) - $(call trace_to_console, "Creating",$@) - $(_hide_cmds)$(call log_command,cat $(STATIC_DOCS_DIR)/status_project.inc \ - $(DRIVER_DOCS_DIR)/about_$(DRIVER).inc \ - $(DRIVER_DOCS_DIR)/status.inc \ - $(DRIVER_DOCS_DIR)/installation.inc \ - $(STATIC_DOCS_DIR)/contributing.inc \ - $(STATIC_DOCS_DIR)/$(DRIVER)_usage.inc \ - $(STATIC_DOCS_DIR)/support.inc \ - $(STATIC_DOCS_DIR)/$(DRIVER)_documentation.inc \ - $(STATIC_DOCS_DIR)/license.inc > $@) - -endif - -# From https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile -print-%: ; $(info $(DRIVER): $* is $(flavor $*) variable set to [$($*)]) @true diff --git a/build/tools.mak b/build/tools.mak deleted file mode 100644 index 8471717a4f..0000000000 --- a/build/tools.mak +++ /dev/null @@ -1,40 +0,0 @@ -# Useful functions - -CURRENT_DIR := $(shell pwd) - -# Traces to console, nicely formatted. -# $1 is the Action, for example: "Generating" -# $2 is a Path. -# Action will be padded on the left so colons align, for readability. -# Path will be turned from absolute to relative, for readability. -define trace_to_console - @echo "$(shell printf '%15s' $1): $(subst $(CURRENT_DIR)/,,$2)" -endef - -# Executes a command, logs it to $(COMMAND_LOG), updates tracking file to show module file generated. -# $1 is the command. -define log_command - $1 - @echo '$1' >> $(COMMAND_LOG) - @touch $(DRIVER_FILE_BUILT) -endef - -# Executes a command, then logs it to $(COMMAND_LOG). -# $1 is the command. -define log_command_no_tracking - $1 - @echo '$1' >> $(COMMAND_LOG) -endef - -# Helper function for running a command with a tracking file -# created/updated upon completion -# $1 is tracking file path -# $2 is command to run -define make_with_tracking_file - $(_hide_cmds)$(call log_command,touch $1) - $(_hide_cmds)$(call log_command,rm $1) - $(_hide_cmds)$(call log_command,$2) - $(_hide_cmds)$(call log_command,touch $1) -endef - - diff --git a/build/unit_tests/test_codegen.py b/build/unit_tests/test_codegen.py new file mode 100644 index 0000000000..4ead024fb5 --- /dev/null +++ b/build/unit_tests/test_codegen.py @@ -0,0 +1,197 @@ +from build import codegen + + +def test_bindings_match_source_folders(): + src_bindings = {d.name for d in codegen.SRC_DIR.iterdir() if (d / 'metadata').is_dir()} + + assert set(codegen.BINDING_CONFIGS) == src_bindings + + +def test_nifake_is_first(): + names = list(codegen.BINDING_CONFIGS) + + assert names[0] == 'nifake' + + +def test_grpc_supported_follows_proto_file(): + assert codegen.BINDING_CONFIGS['nidmm'].grpc_supported + assert codegen.BINDING_CONFIGS['nidigital'].proto_file.name == 'nidigitalpattern.proto' + assert not codegen.BINDING_CONFIGS['nitclk'].grpc_supported + + +def test_py_files_to_generate_default_binding_with_grpc(): + files = codegen.BINDING_CONFIGS['nidmm'].py_files_to_generate() + + assert 'session.py' in files + assert 'unit_tests/_mock_helper.py' in files + assert 'nidmm_pb2.py' in files + assert 'nidevice_pb2_grpc.py' in files + assert '_grpc_stub_interpreter.py' in files + assert '_complextype.py' not in files + + +def test_py_files_to_generate_uses_proto_file_name(): + files = codegen.BINDING_CONFIGS['nidigital'].py_files_to_generate() + + assert 'nidigitalpattern_pb2.py' in files + assert 'nidigitalpattern_pb2_grpc.py' in files + assert 'nidigital_pb2.py' not in files + + +def test_py_files_to_generate_extra_and_omitted_files(): + assert '_complextype.py' in codegen.BINDING_CONFIGS['nifake'].py_files_to_generate() + assert '_complextype.py' in codegen.BINDING_CONFIGS['nirfsa'].py_files_to_generate() + assert '_attributes.py' not in codegen.BINDING_CONFIGS['nise'].py_files_to_generate() + assert 'enums.py' in codegen.BINDING_CONFIGS['nise'].py_files_to_generate() + assert 'enums.py' not in codegen.BINDING_CONFIGS['nitclk'].py_files_to_generate() + assert '_attributes.py' in codegen.BINDING_CONFIGS['nitclk'].py_files_to_generate() + nimodinst_files = codegen.BINDING_CONFIGS['nimodinst'].py_files_to_generate() + assert 'enums.py' not in nimodinst_files + assert '_attributes.py' not in nimodinst_files + + +def test_py_files_to_generate_without_grpc_has_no_pb2_files(): + files = codegen.BINDING_CONFIGS['nitclk'].py_files_to_generate() + + assert not [f for f in files if 'pb2' in f or 'grpc' in f] + + +def test_doc_files_to_generate_names_are_binding_specific(): + files = dict(codegen.BINDING_CONFIGS['nidmm'].doc_files_to_generate()) + + assert files['about_nidmm.inc'] == 'about_driver.inc.mako' + assert files['nidmm.rst'] == 'driver.rst.mako' + assert files['grpc_session_options.rst'] == 'grpc_session_options.rst.mako' + assert 'rep_caps.rst' not in files + + +def test_doc_files_to_generate_omitted_files(): + nitclk_files = dict(codegen.BINDING_CONFIGS['nitclk'].doc_files_to_generate()) + + assert 'enums.rst' not in nitclk_files + assert 'rep_caps.rst' not in nitclk_files + assert 'grpc_session_options.rst' not in nitclk_files + assert 'rep_caps.rst' in dict(codegen.BINDING_CONFIGS['niswitch'].doc_files_to_generate()) + + +def test_get_template_prefers_binding_template(): + nitclk = codegen.BINDING_CONFIGS['nitclk'] + + assert nitclk.get_template('session.py.mako') == nitclk.src_dir / 'templates' / 'session.py.mako' + assert nitclk.get_template('errors.py.mako') == codegen.TEMPLATES_DIR / 'errors.py.mako' + assert codegen.BINDING_CONFIGS['nidmm'].get_template('session.py.mako') == codegen.TEMPLATES_DIR / 'session.py.mako' + + +def test_custom_types_exist(): + for binding_config in codegen.BINDING_CONFIGS.values(): + for custom_type in binding_config.custom_types: + assert (binding_config.src_dir / 'custom_types' / custom_type).is_file() + + +def test_nifake_has_no_docs_or_examples(): + nifake = codegen.BINDING_CONFIGS['nifake'] + + assert not nifake.has_docs + assert nifake.example_files() == () + + +def test_example_files_are_sorted_and_skip_bytecode(): + files = codegen.BINDING_CONFIGS['nidmm'].example_files() + + assert files + assert list(files) == sorted(files) + assert all(f.suffix != '.pyc' and '__pycache__' not in f.parts for f in files) + + +def test_readme_parts_for_binding(): + parts = codegen.BINDING_CONFIGS['nidmm'].readme_parts() + + assert [p.name for p in parts] == [ + 'status_project.inc', + 'about_nidmm.inc', + 'status.inc', + 'installation.inc', + 'contributing.inc', + 'nidmm_usage.inc', + 'support.inc', + 'nidmm_documentation.inc', + 'license.inc', + ] + + +def test_root_readme_parts_include_each_binding_status_in_order(monkeypatch, tmp_path): + for name in ('nitclk', 'nidmm', 'niscope'): + (tmp_path / name).mkdir() + (tmp_path / name / 'status.inc').write_text('') + (tmp_path / 'nise').mkdir() + monkeypatch.setattr(codegen, 'DOCS_DIR', tmp_path) + + status_files = [p for p in codegen.root_readme_parts() if p.name == 'status.inc'] + + assert [p.parent.name for p in status_files] == ['nidmm', 'niscope', 'nitclk'] + + +def test_rewrite_pb2_imports(): + contents = b'import session_pb2 as s\nimport nidevice_pb2 as n\nimport nifake_pb2 as f\nimport nidevice_pb2_grpc\n# import nifake_pb2\n' + + assert codegen.rewrite_pb2_imports(contents, 'nifake') == ( + b'import session_pb2 as s\n' + b'from . import nidevice_pb2 as n\n' + b'from . import nifake_pb2 as f\n' + b'from . import nidevice_pb2_grpc\n' + b'# import nifake_pb2\n') + + +def test_concatenate_files_is_binary_exact(tmp_path): + (tmp_path / 'a.inc').write_bytes(b'first\n') + (tmp_path / 'b.inc').write_bytes(b'second\r\nthird') + dest = tmp_path / 'out' / 'README.rst' + + codegen.concatenate_files([tmp_path / 'a.inc', tmp_path / 'b.inc'], dest) + + assert dest.read_bytes() == b'first\nsecond\r\nthird' + + +def test_clean_removes_generated_files_but_not_doc_subfolders(monkeypatch, tmp_path): + root = tmp_path + generated = root / 'generated' + docs = root / 'docs' + build = root / 'build' + (generated / 'nidmm').mkdir(parents=True) + (generated / 'nidmm' / 'setup.py').write_text('') + (docs / 'nidmm' / 'subfolder').mkdir(parents=True) + (docs / 'nidmm' / 'index.rst').write_text('') + (docs / 'nidmm' / '.readthedocs.yaml').write_text('') + (docs / 'nidcpower').mkdir() + (docs / 'nidcpower' / 'index.rst').write_text('') + (build / '__pycache__').mkdir(parents=True) + (build / '__pycache__' / 'x.pyc').write_text('') + (root / 'README.rst').write_text('') + (root / '.coverage').write_text('') + for name, value in (('ROOT_DIR', root), ('GENERATED_DIR', generated), ('DOCS_DIR', docs), ('BUILD_HELPER_DIR', build)): + monkeypatch.setattr(codegen, name, value) + + codegen.clean([codegen.BINDING_CONFIGS['nidmm']]) + + assert generated.is_dir() + assert not list(generated.iterdir()) + assert [p.name for p in (docs / 'nidmm').iterdir()] == ['subfolder'] + assert (docs / 'nidcpower' / 'index.rst').exists() + assert not (build / '__pycache__').exists() + assert not (root / 'README.rst').exists() + assert not (root / '.coverage').exists() + + +def test_parse_args_defaults_to_all_drivers(): + args = codegen.parse_args(['generate']) + + assert args.command == 'generate' + assert args.drivers is None + + +def test_parse_args_repeated_driver(): + args = codegen.parse_args(['installers', '--driver', 'nidmm', '--driver', 'nitclk', '-v']) + + assert args.command == 'installers' + assert args.drivers == ['nidmm', 'nitclk'] + assert args.verbose == 1 diff --git a/build/unit_tests/test_metadata_add_all.py b/build/unit_tests/test_metadata_add_all.py index 252155c66f..44374a0284 100644 --- a/build/unit_tests/test_metadata_add_all.py +++ b/build/unit_tests/test_metadata_add_all.py @@ -1,3 +1,4 @@ +from build.helper import metadata_add_all from build.helper.metadata_add_all import * from build.helper.metadata_add_all import _add_enum_codegen_method from build.helper.metadata_add_all import _get_attributes_that_use_enums @@ -1106,6 +1107,23 @@ def test_add_all_metadata(): expected=expected) +def test_add_all_metadata_without_writing_processed_metadata_matches_persisted_config(monkeypatch, tmp_path): + monkeypatch.chdir(tmp_path) + + def _processed_config(write): + monkeypatch.setattr(metadata_add_all, 'write_processed_metadata', write) + config = copy.deepcopy(config_input) + return add_all_metadata(copy.deepcopy(functions_input), copy.deepcopy(attributes_input), copy.deepcopy(enums_input), config) + + skipped = _processed_config(write=False) + assert not (tmp_path / 'generated').exists() + written = _processed_config(write=True) + assert (tmp_path / 'generated' / 'processed_metadata').is_dir() + + assert 'modules' not in skipped + _compare_dicts(skipped, written) + + def _setup_inputs_for_enum_codegen_method_tests(): actual_enums = copy.deepcopy(enums_input) actual_config = copy.deepcopy(config_input) diff --git a/src/nidcpower/nidcpower.mak b/src/nidcpower/nidcpower.mak deleted file mode 100644 index 11f41d27d0..0000000000 --- a/src/nidcpower/nidcpower.mak +++ /dev/null @@ -1,19 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -CUSTOM_TYPES_TO_COPY += \ - lcr_load_compensation_spot.py \ - lcr_measurement.py \ - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nidigital/nidigital.mak b/src/nidigital/nidigital.mak deleted file mode 100644 index ed238f1f3b..0000000000 --- a/src/nidigital/nidigital.mak +++ /dev/null @@ -1,17 +0,0 @@ -PROTO_FILE = $(METADATA_DIR)/nidigitalpattern.proto - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -CUSTOM_TYPES_TO_COPY += \ - history_ram_cycle_information.py \ - -include $(BUILD_HELPER_DIR)/rules.mak diff --git a/src/nidmm/nidmm.mak b/src/nidmm/nidmm.mak deleted file mode 100644 index 874324a800..0000000000 --- a/src/nidmm/nidmm.mak +++ /dev/null @@ -1,15 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(filter-out rep_caps.rst,$(DEFAULT_RST_FILES_TO_GENERATE)) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nifake/nifake.mak b/src/nifake/nifake.mak deleted file mode 100644 index 85386b617a..0000000000 --- a/src/nifake/nifake.mak +++ /dev/null @@ -1,19 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) _complextype.py - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -# We are not building any nifake documentation -# RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) -# SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) - -CUSTOM_TYPES_TO_COPY += \ - custom_struct.py \ - custom_struct_typedef.py \ - custom_struct_nested_typedef.py \ - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nifgen/nifgen.mak b/src/nifgen/nifgen.mak deleted file mode 100644 index 010defb466..0000000000 --- a/src/nifgen/nifgen.mak +++ /dev/null @@ -1,15 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nimodinst/nimodinst.mak b/src/nimodinst/nimodinst.mak deleted file mode 100644 index 6d99daa012..0000000000 --- a/src/nimodinst/nimodinst.mak +++ /dev/null @@ -1,23 +0,0 @@ -include $(BUILD_HELPER_DIR)/defines.mak -include $(BUILD_HELPER_DIR)/tools.mak - -# We want everything but enums.py -MODULE_FILES_TO_GENERATE := $(filter-out enums.py _attributes.py,$(DEFAULT_PY_FILES_TO_GENERATE)) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(filter-out rep_caps.rst enums.rst,$(DEFAULT_RST_FILES_TO_GENERATE)) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - -# We need to override the default rule for generating session since we have -# a specialized copy for ModInst -$(MODULE_DIR)/session.py: $(DRIVER_DIR)/templates/session.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call GENERATE_SCRIPT, $<, $(MODULE_DIR), $(METADATA_DIR)) -# Need to signal the top level makefile to run tests again - $(_hide_cmds)$(call trigger_unit_tests) - diff --git a/src/nirfsa/nirfsa.mak b/src/nirfsa/nirfsa.mak deleted file mode 100644 index d1e78df16f..0000000000 --- a/src/nirfsa/nirfsa.mak +++ /dev/null @@ -1,20 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) _complextype.py - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -CUSTOM_TYPES_TO_COPY += \ - coefficient_info_type.py \ - waveform_info.py \ - spectrum_info_type.py \ - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nirfsg/nirfsg.mak b/src/nirfsg/nirfsg.mak deleted file mode 100644 index 3570d3638f..0000000000 --- a/src/nirfsg/nirfsg.mak +++ /dev/null @@ -1,15 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) _complextype.py - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/niscope/niscope.mak b/src/niscope/niscope.mak deleted file mode 100644 index 2fb2b94cc7..0000000000 --- a/src/niscope/niscope.mak +++ /dev/null @@ -1,19 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -CUSTOM_TYPES_TO_COPY += \ - waveform_info.py \ - measurement_stats.py \ - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nise/nise.mak b/src/nise/nise.mak deleted file mode 100644 index 45a9a6b5fd..0000000000 --- a/src/nise/nise.mak +++ /dev/null @@ -1,16 +0,0 @@ -include $(BUILD_HELPER_DIR)/defines.mak -include $(BUILD_HELPER_DIR)/tools.mak - -# We want everything but _attributes.py -MODULE_FILES_TO_GENERATE := $(filter-out _attributes.py,$(DEFAULT_PY_FILES_TO_GENERATE)) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(filter-out rep_caps.rst,$(DEFAULT_RST_FILES_TO_GENERATE)) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - - diff --git a/src/niswitch/niswitch.mak b/src/niswitch/niswitch.mak deleted file mode 100644 index 010defb466..0000000000 --- a/src/niswitch/niswitch.mak +++ /dev/null @@ -1,15 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(DEFAULT_PY_FILES_TO_GENERATE) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(DEFAULT_RST_FILES_TO_GENERATE) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - diff --git a/src/nitclk/nitclk.mak b/src/nitclk/nitclk.mak deleted file mode 100644 index 139b836058..0000000000 --- a/src/nitclk/nitclk.mak +++ /dev/null @@ -1,25 +0,0 @@ - - -include $(BUILD_HELPER_DIR)/defines.mak - -MODULE_FILES_TO_GENERATE := $(filter-out enums.py,$(DEFAULT_PY_FILES_TO_GENERATE)) - -MODULE_FILES_TO_COPY := $(DEFAULT_PY_FILES_TO_COPY) - -RST_FILES_TO_GENERATE := $(filter-out rep_caps.rst enums.rst,$(DEFAULT_RST_FILES_TO_GENERATE)) - -SPHINX_CONF_PY := $(DEFAULT_SPHINX_CONF_PY) -READTHEDOCS_CONFIG := $(DEFAULT_READTHEDOCS_CONFIG) - -include $(BUILD_HELPER_DIR)/rules.mak - -# We need to override the default rule for generating session since we have -# a specialized copy for TClk -$(MODULE_DIR)/session.py: $(DRIVER_DIR)/templates/session.py.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call GENERATE_SCRIPT, $<, $(MODULE_DIR), $(METADATA_DIR)) - -$(DRIVER_DOCS_DIR)/class.rst: $(DRIVER_DIR)/templates/class.rst.mako $(BUILD_HELPER_SCRIPTS) $(METADATA_FILES) - $(call trace_to_console, "Generating",$@) - $(_hide_cmds)$(call GENERATE_SCRIPT, $<, $(DRIVER_DOCS_DIR), $(METADATA_DIR)) - diff --git a/tox.ini b/tox.ini index 8369db4a84..37df05574e 100644 --- a/tox.ini +++ b/tox.ini @@ -45,7 +45,7 @@ commands = # doctest validation of code docstrings build_test: coverage run --rcfile=tools/coverage_unit_tests.rc --source build.helper -m pytest --pyargs build.helper # actual unit tests - build_test: coverage run --append --rcfile=tools/coverage_unit_tests.rc --source build.helper -m pytest build/unit_tests {posargs} -s + build_test: coverage run --append --rcfile=tools/coverage_unit_tests.rc --source build.helper,build.codegen -m pytest build/unit_tests {posargs} -s # Display the report on console build_test: coverage report # Create the report to upload @@ -87,15 +87,15 @@ commands = test: coverage html --directory=generated/htmlcov/unit_tests/nitclk clean: python --version clean: python -c "import platform; print(platform.architecture())" - clean: make clean {posargs} + clean: python -m build.codegen clean {posargs} codegen: python --version codegen: python -c "import platform; print(platform.architecture())" codegen: python -m pip install --disable-pip-version-check --upgrade pip - codegen: make {posargs} + codegen: python -m build.codegen generate {posargs} installers: python --version installers: python -c "import platform; print(platform.architecture())" installers: python -m pip install --disable-pip-version-check --upgrade pip - installers: make installers {posargs} + installers: python -m build.codegen installers {posargs} flake8: python --version flake8: python -c "import platform; print(platform.architecture())" flake8: python -m pip install --disable-pip-version-check --upgrade pip @@ -156,11 +156,15 @@ deps = build_test: mako build_test: hacking build_test: pep8-naming + clean: mako + clean: packaging codegen: mako codegen: packaging codegen: setuptools < 82 # grpcio-tools 1.59.0 needs pkg_resources which was removed in setuptools v82 codegen: grpcio-tools == 1.59.0 # First version to support Python 3.12 installers: build + installers: mako + installers: packaging flake8: hacking flake8: pep8-naming docs: sphinx @@ -181,9 +185,6 @@ depends = allowlist_externals = build_test: mv test: mv - codegen: make - installers: make - clean: make [flake8] show_source = true