.PHONY: all clean lint fmt check mirror-init mirror-sync index dist
.PHONY: build bootstrap
.PHONY: .github-token .bitbucket-credentials

PKG          = byteb4rb1e.sphinxcontrib.h5p.utils.pkg
SRC          = src
DATA_DIR     = data
H5P_MONOREPO = ../sphinxcontrib.h5p

all: check

# -------------------------------------------------------------------
# Linting and formatting
# -------------------------------------------------------------------

fmt:
	autopep8 $(SRC)

lint:
	pylint $(SRC)
	mypy $(SRC)

check: fmt lint

# -------------------------------------------------------------------
# Two-tier cache
# -------------------------------------------------------------------

mirror-init: .github-token .bitbucket-credentials
	python3 -m $(PKG).h5porg.repository mirror init \
		--mirror-base-url "git@bitbucket.org:$(BITBUCKET_WORKSPACE)" \
		--bb-project "$(BITBUCKET_PROJECT)"

mirror-sync:
	python3 -m $(PKG).h5porg.repository mirror sync

index:
	python3 -m $(PKG).h5porg.repository index

.github-token:
ifndef GITHUB_TOKEN
	$(error GITHUB_TOKEN is required)
endif

.bitbucket-credentials:
ifndef BITBUCKET_TOKEN
	$(error BITBUCKET_TOKEN is required)
endif
ifndef BITBUCKET_WORKSPACE
	$(error BITBUCKET_WORKSPACE is required)
endif

# -------------------------------------------------------------------
# Build pipeline
# -------------------------------------------------------------------

build:
	python3 -m $(PKG) build

bootstrap:
	python3 -m $(PKG).bootstrap --all --target $(H5P_MONOREPO)

# -------------------------------------------------------------------
# Build
# -------------------------------------------------------------------

dist:
	python3 -m build

clean:
	rm -rfv \
		build/ \
		dist/ \
		src/**.egg-info \
		src/**/__pycache__
