#!/usr/bin/make -f

LIB3 := $(shell python3 -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print (b.build_purelib)")
PYTHON3 := $(shell py3versions -r)

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

override_dh_auto_clean:
	dh_auto_clean

	# Add here commands to clean up after the build process.
	rm -fr build networkx/version.py test.* doc/source/templates/gallery.html fontList.cache

	# Make sure that there's no .pyc left
	find . -name '*.pyc' -exec rm {} ';'

	rm -f doc/file.dot doc/fontlist-v330.json doc/path.png doc/path.to.file
	rm -f examples/advanced/edgelist.utf-8 examples/basic/grid.edgelist examples/pygraphviz/grid.dot examples/pygraphviz/k5.dot examples/pygraphviz/k5.ps examples/pygraphviz/k5_attributes.dot
	rm -rf .pytest_cache


override_dh_auto_test:
	PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="PYTHONPATH={build_dir} {interpreter} -m pytest --verbosity=2" dh_auto_test

override_dh_install:
	# Install w/o compiling *.pyc files
	# Install egg-info directories (--single-... option)
	python3 setup.py install --no-compile --root=$(CURDIR)/debian/python3-networkx \
		--single-version-externally-managed --install-layout=deb

	# fix test shebang
	sed 's|/usr/bin/env python|/usr/bin/python3|' -i debian/python3-networkx/usr/lib/*/*-packages/networkx/generators/tests/test_random_graphs.py

	# remove duplicate examples
	rm -rf debian/python3-networkx/usr/share/doc/python-networkx

	# don't ship python 2 code for _decorator because it can't be byte-compiled
	rm -f debian/python3-networkx/usr/lib/python3/dist-packages/networkx/external/decorator/_decorator.py

	dh_install


override_dh_installexamples:
	dh_installexamples examples/*

override_dh_compress:
	dh_compress -Xexamples/ -X.js -X.pdf -Xobjects.inv

override_dh_missing:
	echo "I: Skipping dh_missing"
