#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk # DEB_VERSION

# downloads from fromteamdigitale.github.io, see tests/data/openapi/refs.yaml
test_expr = not test_openapi_parser_parse_remote_ref
# ruff isn't currently in testing, and running these sorts of style checks
# as a downstream doesn't really make sense anyway.
test_expr += and not test_ruff
test_expr += and not test_type_checking_imports_default_to_runtime_imports_for_modular_pydantic_ruff
test_expr += and not test_generate_multi_module_pydantic_ruff_defaults_to_runtime_imports
test_expr += and not test_use_type_checking_imports_for_multi_module_pydantic_ruff
test_expr += and not test_openapi_parser_parse_modular_pydantic_v2_ruff_keeps_runtime_imports
test_expr += and not test_no_use_type_checking_imports
# Skip some tests that require ruff.  Unlike the above, these could
# reasonably be enabled once ruff is in testing.
test_expr += and not test_main_generate_pydantic_v2_dataclass_required_field_order

# Skip tests that only matter for upstream maintenance.
test_expr += and not docs_script
test_expr += and not skills
# Enable these once Debian's python3-grpc-tools version matches
# datamodel-code-generator[protobuf]'s requirements.
test_expr += and not test_main_protobuf
test_expr += and not test_main_asyncapi_protobuf_schema_format
# These tests are either very slow or hang forever.
test_expr += and not test_main_watch

export PYBUILD_TEST_ARGS= -k '$(test_expr)'

%:
	dh $@ --buildsystem=pybuild

B = $(CURDIR)/debian/tmp/usr/bin
M = $(CURDIR)/debian/tmp/usr/share/man/man1

execute_after_dh_auto_install:
ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
	mkdir -pv $(M)
	env PYTHONPATH=$(CURDIR)/src \
		help2man --no-info --version-string="$(DEB_VERSION)" \
		--help-option="--no-color --help" \
		-Idebian/datamodel-codegen.h2m \
		$(B)/datamodel-codegen -o $(M)/datamodel-codegen.1
endif
