# Makefile for uploading python packages to apple internal pypi.
#
# Recommended Use
# ---------------
# Requires python `twine` package.  Get it with `pip install --user --upgrade twine`.
#
# References
# ----------
# https://docs.pie.apple.com/artifactory/pypi.html#publishing-internal-packages
# https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents

# CONFIGURATIONS
PACKAGE_NAME = bluetoothautomation

# VERSIONING INFO
VERSION_INFO := $$(python -c 'from bluetoothautomation._metadata import __version__; print(__version__)')
BRANCH_INFO := $$(git rev-parse --short HEAD)
COMMIT_HASH := $$(git rev-parse --abbrev-ref HEAD | tr -d '/')

# COMMANDS
.PHONY: all version clean

default all: clean version

version:
	# Full release version
	git describe --always > ${PACKAGE_NAME}/__version__
	# Just the tag name
	git describe --always --abbrev=0 >> ${PACKAGE_NAME}/__version__

clean:
	# Clean intermediates and junk
	find . -name "*.pyc" -exec rm -rf {} \;
	rm -f ${PACKAGE_NAME}/__version__
	rm -rf build
	rm -rf dist
	rm -rf $(PACKAGE_NAME).egg-info
	-rm *.tgz
	-rm -rf POST_INSTALL_FIXUPS

tar: default
	# Create a tar of the build
	tar -czf ${PACKAGE_NAME}-v${VERSION_INFO}-${BRANCH_INFO}-${COMMIT_HASH}.tgz ${SUPER_PROJECT}

test: default
	python setup.py sdist

test_publish: default
	python setup.py sdist
	twine upload --config-file ~/.pypirc --repository apple-pypi-test dist/*

test_verify:
	pip install --extra-index-url https://artifacts.apple.com/api/pypi/apple-pypi-integration-local/simple/ ${PACKAGE_NAME}

sdist: default
	# Create a distribution of the build
	python setup.py sdist

publish: default
	# Upload a distribution of the build to production pypi, https://pypi.apple.com
	python setup.py sdist
	twine upload --config-file ~/.pypirc --repository apple-pypi dist/*
