11PYMODULE := cityhash
22EXTENSION := $(PYMODULE ) .so
33SRC_DIR := src
4- EXTENSION_INTERMEDIATE := ./$(SRC_DIR ) /$(PYMODULE ) .cpp
5- EXTENSION_DEPS := ./$(SRC_DIR ) /$(PYMODULE ) .pyx
6- PYPI_URL := https://upload.pypi.org/legacy/
4+ PYPI_URL := https://test.pypi.org/legacy/
5+ EXTENSION_DEPS := $(shell find $(SRC_DIR ) -type f -name "* .pyx")
6+ EXTENSION_INTERMEDIATE := $(patsubst % .pyx,% .cpp,$(EXTENSION_DEPS ) )
7+ EXTENSION_OBJS := $(patsubst % .pyx,% .so,$(EXTENSION_DEPS ) )
78
8- DISTRIBUTE := sdist
9- ifeq ( $( shell uname -s) ,Darwin)
10- DISTRIBUTE += bdist_wheel
11- endif
9+ BUILD_STAMP = .build_stamp
10+ ENV_STAMP = env/bin/activate
11+
12+ DISTRIBUTE := sdist bdist_wheel
1213
1314PYENV := PYTHONPATH=. . env/bin/activate;
1415INTERPRETER := python3
@@ -26,37 +27,41 @@ BOLD := $(shell tput bold)
2627END := $(shell tput sgr0)
2728
2829.PHONY : package
29- package : env build_ext # # build package
30+ package : $(DISTRIBUTE ) # # package for distribution (deprecated)
31+ $(DISTRIBUTE ) : $(BUILD_STAMP ) | $(ENV_STAMP )
3032 @echo " Packaging using $( PYVERSION) "
3133 $(PYTHON ) setup.py $(DISTRIBUTE )
3234
33- # See https://packaging.python.org/guides/migrating-to-pypi-org/
3435.PHONY : release
35- release : env build_ext # # upload package to PyPI
36+ release : $( BUILD_STAMP ) | $( ENV_STAMP ) # # upload package to PyPI (deprecated)
3637 @echo " Releasing using $( PYVERSION) "
3738 $(PYTHON ) setup.py $(DISTRIBUTE ) upload -r $(PYPI_URL )
3839
3940.PHONY : shell
40- shell : build_ext # # open Python shell within the virtualenv
41+ shell : build # # open Python shell within the virtualenv
4142 @echo " Using $( PYVERSION) "
4243 $(PYENV ) ipython
4344
44- .PHONY : build_ext
45- build_ext : $(EXTENSION ) # # build C extension(s)
46- @echo " done building ' $( EXTENSION ) ' extension "
45+ .PHONY : build
46+ build : $(EXTENSION_OBJS ) # # build C extension(s)
47+ @echo " completed $@ target "
4748
48- $(EXTENSION ) : env $(EXTENSION_DEPS )
49+ $(BUILD_STAMP ) : $(EXTENSION_DEPS ) | $( ENV_STAMP )
4950 @echo " Building using $( PYVERSION) "
5051 $(PYTHON ) setup.py build_ext --inplace
52+ @echo " $( shell date --rfc-3339=seconds) " > $@
53+
54+ $(EXTENSION_OBJS ) : $(BUILD_STAMP )
55+ @echo " done building $@ "
5156
5257.PHONY : test
53- test : build_ext # # run Python unit tests
58+ test : build # # run Python unit tests
5459 $(PYENV ) pytest
5560 $(PYTHON ) -m doctest README.md && echo " $( BOLD) doctests passed$( END) "
5661
5762.PHONY : nuke
5863nuke : clean # # clean and remove virtual environment
59- rm -f $(EXTENSION_INTERMEDIATE )
64+ rm -f $(BUILD_STAMP ) $( EXTENSION_INTERMEDIATE )
6065 rm -rf * .egg * .egg-info env
6166 find $(SRC_DIR ) -depth -type d -name * .egg-info -exec rm -rf {} \;
6267
@@ -70,15 +75,15 @@ clean: ## remove temporary files
7075 find $(SRC_DIR ) -type f -name " *.so" -exec rm {} \;
7176
7277.PHONY : install
73- install : build_ext # # install package
78+ install : build # # install package
7479 @echo " Installing for " ` which pip`
7580 -pip uninstall --yes $(PYMODULE )
7681 pip install -e .
7782
78- .PRECIOUS : env/bin/activate
83+ .PRECIOUS : $( ENV_STAMP )
7984.PHONY : env
80- env : env/bin/activate # # set up a virtual environment
81- env/bin/activate : setup.py requirements.txt
85+ env : $( ENV_STAMP ) # # set up a virtual environment
86+ $( ENV_STAMP ) : setup.py requirements.txt
8287 test -f $@ || virtualenv $(VENV_OPTS ) env
8388 export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PYENV ) curl https://bootstrap.pypa.io/ez_setup.py | $(INTERPRETER )
8489 $(PIP ) install -U pip wheel
0 commit comments