Last active
December 14, 2015 06:29
-
-
Save dgvncsz0f/5042947 to your computer and use it in GitHub Desktop.
python devmakefile
This file contains hidden or 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
# -*- mode: makefile-gmake; -*- | |
# variables you must define: | |
# project = ... | |
# srcroot = $(CURDIR) | |
# home_virtenv = ... | |
# rcfile = ... | |
# variables you should define | |
# env_pyenv = ... | |
bin_find = find | |
bin_virtualenv = virtualenv | |
bin_env = env | |
bin_find = find | |
bin_python = $(home_virtenv)/bin/python | |
bin_ipython = $(home_virtenv)/bin/ipython | |
bin_pip = $(home_virtenv)/bin/pip | |
-include $(rcfile) | |
.PHONY: scaffold | |
scaffold: | |
@echo "project = CHANGEME!" | |
@echo | |
@echo "srcroot = \$$(CURDIR)" | |
@echo "home_virtenv = \$$(HOME)/pyenv/\$$(project)" | |
@echo "rcfile = \$$(HOME)/.\$$(project).rc" | |
@echo | |
@echo "env_pyenv = CHANGEME!" | |
@echo | |
@echo include /usr/share/python/devmakefile.include | |
@echo | |
@echo bootstrap: _boostrap | |
@echo | |
@echo clean: _clean_pyc | |
.PHONY: _bootstrap | |
_bootstrap: | |
$(call check_bin,virtualenv) | |
echo "" >$(rcfile) | |
echo "bin_virtualenv = $(bin_virtualenv)" >>$(rcfile) | |
echo "bin_env = $(bin_env)" >>$(rcfile) | |
echo "bin_find = $(bin_find)" >>$(rcfile) | |
echo "bin_python = $(bin_python)" >>$(rcfile) | |
echo "bin_ipython = $(bin_ipython)" >>$(rcfile) | |
test -d "$(virtenvroot)" || $(bin_virtualenv) $(virtenvroot) | |
$(call check_bin,pip) | |
$(bin_pip) install -q -r $(srcroot)/pip-requires.txt | |
$(bin_pip) install -q ipython | |
$(call check_bin,python) | |
$(call check_bin,ipython) | |
.PHONY: _clean_pyc | |
_clean_pyc: | |
$(call check_bin,find) | |
$(bin_find) $(srcroot) -type f -name \*.pyc -exec rm -f \{\} \; | |
.PHONY: ipython | |
ipython: | |
$(call check_bin,ipython) | |
$(bin_env) $(env_pyenv) $(bin_ipython) | |
check_bin = @command -v $(bin_$(1)) >/dev/null || { \ | |
echo "bin_$(1) not found!!!"; \ | |
echo; \ | |
echo "Use bin_$(1) variable to fix this, as follows: "; \ | |
echo " $$ $(MAKE) ... bin_$(1)=/path/to/file"; \ | |
echo; \ | |
echo "Additionally, you also change the file:"; \ | |
echo " $(rcfile)"; \ | |
echo; \ | |
echo "so that it gets remembered next time"; \ | |
exit 1; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment