#!/usr/bin/make -f

export PYBUILD_NAME=pip
#export PYBUILD_VERBOSE=1
#export DH_VERBOSE=1

export PIP_NO_VENDOR_FOR_DOWNSTREAM=1
export DIRTBIKE_DIRECTORY=\
    $(CURDIR)/debian/python-pip-whl/usr/share/python-wheels

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

# Patching DEBUNDLED=True in pip/_vendor/__init__.py is enough to disable
# vendoring.  We remove these files (as suggested by pip/_vendor/README.rst)
# as added insurance.  find/rm code adapted from upstream's travis run.sh.
override_dh_auto_build:
	find src/pip/_vendor -depth \
		-not -regex 'src/pip/_vendor/__init__\.py$$' \
		-not -regex 'src/pip/_vendor/vendor.txt$$' \
		-not -regex 'src/pip/_vendor$$' \
		-exec rm -rf {} \;
	dh_auto_build

# Upstream does not bundle enough of the source tree in the tarball to run the
# test suite.  https://github.com/pypa/pip/issues/3370
override_dh_auto_test:

override_dh_python3:
	dh_python3 -v
	rm -f debian/python3-pip/usr/bin/pip3.?
	rm -rf debian/python3-pip/usr/lib/python3.?

override_dh_auto_install:
	dh_auto_install
	mkdir -p $(CURDIR)/debian/python-pip-whl/usr/share/python-wheels
	dirtbike appdirs
	dirtbike CacheControl
	dirtbike certifi
	dirtbike chardet
	dirtbike colorama
	dirtbike distlib
	dirtbike distro
	dirtbike html5lib
	dirtbike idna
	dirtbike ipaddr
	dirtbike packaging
	dirtbike pep517
	dirtbike --py2 pkg_resources
	dirtbike progress
	dirtbike pyparsing
	dirtbike resolvelib
	dirtbike toml
	dirtbike requests
	dirtbike retrying
	dirtbike --py2 setuptools
	dirtbike six
	dirtbike urllib3
	dirtbike webencodings
	dirtbike wheel
	dirtbike contextlib2
	dirtbike msgpack
	python3 setup.py bdist_wheel \
		--universal \
		-d $(CURDIR)/debian/python-pip-whl/usr/share/python-wheels
	debian/genbuildusing.sh >> debian/python-pip-whl.substvars

override_dh_installchangelogs:
	dh_installchangelogs NEWS.rst

override_dh_installman:
	mkdir -p debian/tmp
	rst2man debian/pip-manpage.rst > debian/tmp/pip3.man
	dh_installman

override_dh_clean:
	dh_clean
	rm -rf debian/tmp
