#!/usr/bin/make -f

export PYBUILD_NAME=requests
export PYBUILD_TEST_PYTEST=1
export PYTHONWARNINGS=d
export PYBUILD_BEFORE_TEST=\
	set -e; \
	rm -rf {dir}/debian/certs.orig; \
	cp -a {dir}/tests/certs {dir}/debian/certs.orig; \
	for cert in expired mtls valid/server; do \
		$(MAKE) -C "{dir}/tests/certs/$$cert" clean all; \
	done
export PYBUILD_AFTER_TEST=\
	set -e; \
	rm -rf {dir}/tests/certs; \
	mv {dir}/debian/certs.orig {dir}/tests/certs
TESTS_TO_EXCLUDE="not test_use_proxy_from_environment and \
not TestGetEnvironProxies and \
not test_mixed_case_scheme_acceptable and \
not test_HTTP_200_OK_GET_ALTERNATIVE and \
not test_unicode_get and \
not test_HTTP_302_ALLOW_REDIRECT_GET and \
not test_HTTP_307_ALLOW_REDIRECT_POST and \
not test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE and \
not test_HTTP_302_TOO_MANY_REDIRECTS and \
not test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS and \
not test_http_301_changes_post_to_get and \
not test_http_301_doesnt_change_head_to_get and \
not test_http_302_changes_post_to_get and \
not test_http_302_doesnt_change_head_to_get and \
not test_http_303_changes_post_to_get and \
not test_http_303_doesnt_change_head_to_get and \
not test_header_and_body_removal_on_redirect and \
not test_transfer_enc_removal_on_redirect and \
not test_fragment_maintained_on_redirect and \
not test_HTTP_200_OK_GET_WITH_PARAMS and \
not test_HTTP_200_OK_GET_WITH_MIXED_PARAMS and \
not test_set_cookie_on_301 and \
not test_cookie_sent_on_redirect and \
not test_cookie_removed_on_expire and \
not test_cookie_quote_wrapped and \
not test_cookie_persists_via_api and \
not test_request_cookie_overrides_session_cookie and \
not test_request_cookies_not_persisted and \
not test_generic_cookiejar_works and \
not test_param_cookiejar_works and \
not test_cookielib_cookiejar_on_redirect and \
not test_requests_in_history_are_not_overridden and \
not test_history_is_always_a_list and \
not test_user_agent_transfers and \
not test_HTTP_200_OK_HEAD and \
not test_HTTP_200_OK_PUT and \
not test_BASICAUTH_TUPLE_HTTP_200_OK_GET and \
not test_proxy_authorization_preserved_on_request and \
not test_basicauth_with_netrc and \
not test_DIGEST_HTTP_200_OK_GET and \
not test_DIGEST_AUTH_RETURNS_COOKIE and \
not test_DIGEST_AUTH_SETS_SESSION_COOKIES and \
not test_DIGEST_STREAM and \
not test_DIGESTAUTH_WRONG_HTTP_401_GET and \
not test_DIGESTAUTH_QUOTES_QOP_VALUE and \
not test_POSTBIN_GET_POST_FILES and \
not test_invalid_files_input and \
not test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER and \
not test_POSTBIN_GET_POST_FILES_WITH_DATA and \
not test_post_with_custom_mapping and \
not test_conflicting_post_params and \
not test_request_ok_set and \
not test_status_raising and \
not test_decompress_gzip and \
not test_unicode_header_name and \
not test_pyopenssl_redirect and \
not test_http_with_certificate and \
not test_certificate_failure and \
not test_urlencoded_get_query_multivalued_param and \
not test_different_encodings_dont_break_post and \
not test_unicode_multipart_post and \
not test_unicode_method_name and \
not test_unicode_method_name_with_request_object and \
not test_custom_content_type and \
not test_hook_receives_request_arguments and \
not test_prepared_request_hook and \
not test_prepared_from_session and \
not test_request_with_bytestring_host and \
not test_time_elapsed_blank and \
not test_request_and_response_are_pickleable and \
not test_prepared_request_is_pickleable and \
not test_prepared_request_with_file_is_pickleable and \
not test_prepared_request_with_hook_is_pickleable and \
not test_session_pickling and \
not test_fixes_1329 and \
not test_uppercase_scheme_redirect and \
not test_header_remove_is_case_insensitive and \
not test_params_are_merged_case_sensitive and \
not test_header_validation and \
not test_auth_is_stripped_on_http_downgrade and \
not test_auth_is_retained_for_redirect_on_host and \
not test_manual_redirect_with_partial_body_read and \
not test_redirect_with_wrong_gzipped_header and \
not test_requests_history_is_saved and \
not test_json_param_post_content_type_works and \
not test_response_iter_lines and \
not test_response_context_manager and \
not test_unconsumed_session_response_closes_connection and \
not test_response_json_when_content_is_None and \
not test_custom_redirect_mixin and \
not test_stream_timeout and \
not test_none_timeout and \
not test_read_timeout and \
not test_connect_timeout and \
not test_total_timeout_connect and \
not test_encoded_methods and \
not test_proxy_env_vars_override_default and \
not test_urllib3_retries and \
not test_redirecting_to_bad_url and \
not test_json_decode_compatibility and \
not test_set_environ and \
not test_json_decode_persists_doc_attr and \
not test_header_with_subclass_types and \
not test_urllib3_pool_connection_closed"
export PYBUILD_TEST_ARGS=tests -k ${TESTS_TO_EXCLUDE}

BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "@$(SOURCE_DATE_EPOCH)")
SPHINXOPTS := -D html_last_updated_fmt="$(BUILD_DATE)"

%:
	dh $@ --with sphinxdoc --buildsystem=pybuild

override_dh_installchangelogs:
	dh_installchangelogs HISTORY.md

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=src python3 -m sphinx $(SPHINXOPTS) -N -bhtml docs/ \
		debian/python-requests-doc/usr/share/doc/python-requests-doc/html/

	dh_sphinxdoc
endif