PYTHON ?= python3

.PHONY: setup doctor clean data python-analysis r-verify parity manuscript reader-environment-check reader-first-run reader-first-run-receipt reader-platform-contract reader-platform-contract-check reader-adaptation-guide reader-starter-package public-reader-release public-starter-repo-seed public-starter-repo-seed-check proof-bundle manuscript-qa-check reader-adaptation-check reader-starter-check public-reader-release-check clean-reader-install-proof test all python-smoke create-private-repo bridge-receipt-check pystatsv1-required-check

setup:
	$(PYTHON) -m pip install --upgrade pip
	$(PYTHON) -m pip install -e '.[dev]'

doctor:
	$(PYTHON) scripts/check_environment.py --require-r --require-pystatsv1

pystatsv1-required-check:
	$(PYTHON) scripts/check_environment.py --require-pystatsv1

reader-environment-check:
	$(PYTHON) scripts/check_environment.py --require-pystatsv1

clean:
	rm -rf outputs/*.json outputs/*.md outputs/*.txt outputs/*.sha256 outputs/*.docx outputs/*.pdf outputs/*.zip outputs/tables/*.csv outputs/figures/*.png build
	mkdir -p outputs/tables outputs/figures
	touch outputs/.gitkeep outputs/tables/.gitkeep outputs/figures/.gitkeep

data:
	$(PYTHON) scripts/generate_synthetic_data.py

python-analysis:
	$(PYTHON) scripts/analyze_with_pystatsv1.py

r-verify:
	Rscript r/verify_results.R

parity:
	$(PYTHON) scripts/compare_python_r_results.py

manuscript:
	$(PYTHON) scripts/build_manuscript.py

reader-first-run:
	$(PYTHON) scripts/check_environment.py --require-pystatsv1
	$(PYTHON) scripts/generate_synthetic_data.py
	$(PYTHON) scripts/analyze_with_pystatsv1.py
	$(PYTHON) scripts/build_manuscript.py
	$(PYTHON) scripts/build_reader_first_run.py

reader-first-run-receipt:
	$(PYTHON) scripts/build_reader_first_run.py

reader-platform-contract:
	$(PYTHON) scripts/build_reader_platform_contract.py

reader-platform-contract-check:
	$(PYTHON) scripts/check_reader_platform_contract.py

reader-adaptation-guide:
	$(PYTHON) scripts/build_reader_adaptation_guide.py

reader-starter-package:
	$(PYTHON) scripts/build_reader_starter_package.py

public-reader-release:
	$(PYTHON) scripts/build_public_reader_release.py

public-starter-repo-seed: public-reader-release
	$(PYTHON) scripts/build_public_starter_repo_seed.py

public-starter-repo-seed-check: public-starter-repo-seed
	$(PYTHON) scripts/check_public_starter_repo_seed.py

proof-bundle:
	$(PYTHON) scripts/build_proof_bundle.py

manuscript-qa-check:
	$(PYTHON) scripts/check_manuscript_qa.py

reader-adaptation-check:
	$(PYTHON) scripts/check_reader_adaptation_guide.py

reader-starter-check:
	$(PYTHON) scripts/check_reader_starter_package.py

public-reader-release-check:
	$(PYTHON) scripts/check_public_reader_release.py

clean-reader-install-proof:
	$(PYTHON) scripts/check_clean_reader_install.py

test:
	$(PYTHON) -m pytest -q

all: clean doctor data python-analysis r-verify parity manuscript reader-first-run-receipt reader-platform-contract reader-platform-contract-check reader-adaptation-guide reader-starter-package public-reader-release public-starter-repo-seed public-starter-repo-seed-check proof-bundle manuscript-qa-check reader-adaptation-check reader-starter-check public-reader-release-check test
	@echo APA_PAPER_LAB_ALL_OK

python-smoke: clean data
	APA_LAB_ALLOW_PYSTATSV1_FALLBACK=1 $(PYTHON) scripts/analyze_with_pystatsv1.py
	$(PYTHON) scripts/build_manuscript.py
	@echo APA_PAPER_LAB_PYTHON_SMOKE_OK

create-private-repo:
	bash scripts/create_private_github_repo.sh

bridge-receipt-check:
	$(PYTHON) -m pytest -q tests/test_pystatsv1_bridge_receipt.py tests/test_pystatsv1_environment_receipt.py tests/test_model_receipt.py tests/test_proof_bundle_receipt.py
