Last active
September 6, 2023 00:44
-
-
Save terrisgit/c2775fb1bc4308703897cb57b9cde4cc to your computer and use it in GitHub Desktop.
Python Pipfile-based Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.NOTPARALLEL : | |
# To make sure the Python virtual environment will be placed in the | |
# .venv directory: | |
# export PIPENV_VENV_IN_PROJECT=1 | |
# | |
# Get program help: | |
# make run | |
# | |
# Run the program: | |
# make -- run --arg-name arg-value ... | |
# | |
# Rules: | |
# 1. -- after make is required! | |
# 2. Omit the = after the argument names | |
# 3. If arg-value contains spaces, surround arg-value with "' and '" | |
# If the first argument is "run", package arguments into RUN_ARGS | |
ifeq (run,$(firstword $(MAKECMDGOALS))) | |
# See https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run | |
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) | |
endif | |
# This is the default target and must be first | |
.PHONY : help | |
help : | |
@cat Makefile | grep '^\#' | sed 's/^# //' | sed 's/^#//' | less | |
.PHONY : install | |
install : upgrade-setuptools pipenv pipenv-install | |
.PHONY : pipenv | |
pipenv : | |
@python3 -m pip install --upgrade --no-cache-dir pipenv | |
.PHONY : pipenv-install | |
pipenv-install : | |
@pipenv install | |
.PHONY : Pipfile | |
Pipfile : | |
@rm -f ~/environment/Pipfile | |
@rm -f ~/environment/Pipfile.lock | |
@rm -f Pipfile | |
@rm -f Pipfile.lock | |
@pipenv install argparse boto3 pymysql | |
.PHONY : upgrade-setuptools | |
upgrade-setuptools : | |
@python3 -m ensurepip --upgrade | |
@python3 -m pip install --upgrade --no-cache-dir pip | |
@pip3 install --upgrade setuptools | |
# Production file retrieval requires prod-s3 in ~/.aws/credentials | |
# @AWS_PROFILE=prod-s3 pipenv run python download_photos.py $(RUN_ARGS) > errors.txt | |
.PHONY: run | |
run : | |
@pipenv run python --version | |
@pipenv run python download_photos.py $(RUN_ARGS) > errors.txt | |
# Do nothing rule needed by RUN_ARGS | |
%: | |
@: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment