tweaked Makefile to use either setup or twine to upload stuff onto pypi
[nepi.git] / Makefile
1 PYTHON      = python
2 SRCDIR      = $(CURDIR)/src
3 TESTDIR     = $(CURDIR)/test
4 TESTLIB     = $(TESTDIR)/lib
5 BUILDDIR    = $(CURDIR)/build/lib
6 DISTDIR     = $(CURDIR)/dist
7
8 PYPATH = $(BUILDDIR):$(TESTLIB):$(PYTHONPATH)
9 COVERAGE = $(or $(shell which coverage), $(shell which python-coverage), \
10            coverage)
11
12 all: clean
13         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" $(PYTHON) ./setup.py build
14
15 install: all
16         PYTHONPATH="$(PYTHONPATH):$(SRCDIR)" $(PYTHON) ./setup.py install
17
18 test: all
19         retval=0; \
20                for i in `find "$(TESTDIR)" -iname '*.py' -perm -u+x -type f`; do \
21                echo $$i; \
22                PYTHONPATH="$(PYPATH)" $(PYTHON) $$i -v || retval=$$?; \
23                done; exit $$retval
24
25 ifeq ($(file),)
26 test-one:
27         echo Run $(make) $@ file=test/some/path
28 else
29 test-one: all
30         echo $(file) $(case)
31         PYTHONPATH="$(PYPATH)" $(PYTHON) $(file) $(case)
32 endif
33
34
35 all-tests: test-app test-node
36
37 test-app:
38         $(MAKE) test-one file=test/resources/linux/application.py case=$(case)
39 test-node:
40         $(MAKE) test-one file=test/resources/linux/node.py case=$(case)
41
42 coverage: all
43         rm -f .coverage
44         for i in `find "$(TESTDIR)" -perm -u+x -type f`; do \
45                 set -e; \
46                 PYTHONPATH="$(PYPATH)" $(COVERAGE) -x $$i -v; \
47                 done
48         $(COVERAGE) -c
49         $(COVERAGE) -r -m `find "$(BUILDDIR)" -name \\*.py -type f`
50         rm -f .coverage
51
52 clean:
53         rm -f $$(find . -name '*.pyc') .coverage *.pcap
54         rm -rf "$(BUILDDIR)"
55
56 distclean: clean
57         rm -rf "$(DISTDIR)"
58
59 MANIFEST:
60         find . -path ./.hg\* -prune -o -path ./build -prune -o \
61                 -name \*.pyc -prune -o -name \*.swp -prune -o \
62                 -name MANIFEST -prune -o -type f -print | \
63                 sed 's#^\./##' | sort > MANIFEST
64
65 dist: MANIFEST
66         ./setup.py sdist
67
68 .PHONY: all clean distclean dist test coverage install MANIFEST
69
70 ########## for uploading onto pypi
71 # this assumes you have an entry 'pypi' in your .pypirc
72 # see pypi documentation on how to create .pypirc
73 LOCAL_ID=$(shell id)
74 ifneq "$(LOCAL_ID)" "$(filter $(LOCAL_ID),parmen)"
75 BUILD_ID=thierry
76 USE_TWINE=
77 else
78 BUILD_ID=mario
79 USE_TWINE=true
80 endif
81
82 PYPI_TARGET=pypi
83 PYPI_TARBALL_HOST=$(BUILD_ID)@build.onelab.eu
84 PYPI_TARBALL_TOPDIR=/build/nepi
85
86 VERSION=$(shell cat VERSION)
87 VERSIONTAG=nepi-$(VERSION)-pypi
88 VERSIONTAR=nepi-$(VERSION).tar.gz
89 ALREADY_SET=$(shell git tag | grep '^$(VERSIONTAG)$$')
90
91 ##########
92 # depending on the value of USE_TWINE, we either do the upload with setup.py itself,
93 # or with the help of twine which apparently is the only way that mario could find out on his setup
94 define upload_pypi
95 $(if $(USE_TWINE),./setup.py sdist && twine upload dist/* -r $(1),./setup.py sdist upload -r $(1))
96 endef
97
98 # run this only once the sources are in on the right tag
99 pypi:
100         @echo "Have you committed all changes (type Ctrl-c if not) ? " ; read _
101         @if [ -n "$(ALREADY_SET)" ] ; then echo "tag $(VERSIONTAG) already set"; false; fi
102         @echo "You are about to release $(VERSION) - OK (Ctrl-c if not) ? " ; read _
103         git tag $(VERSIONTAG)
104         $(call upload_pypi,pypi)
105         @if [ ssh $(PYPI_TARBALL_HOST) ls $(PYPI_TARBALL_TOPDIR)/$(VERSIONTAR) ] ;\
106           then echo "$(VERSIONTAR) already present on $(PYPI_TARBALL_HOST) - ignored" ;\
107           else rsync -av dist/$(VERSIONTAR) $(PYPI_TARBALL_HOST):$(PYPI_TARBALL_TOPDIR)/ ;\
108           fi
109
110
111 # it can be convenient to define a test entry, say testpypi
112 # that points at the testpypi public site
113 # in this case we do not want to upload anything on the build box though
114
115 testpypi:
116         $(call upload_pypi,testpypi)
117
118 #################### convenience, for debugging only
119 # make +foo : prints the value of $(foo)
120 # make ++foo : idem but verbose, i.e. foo=$(foo)
121 ++%: varname=$(subst +,,$@)
122 ++%:
123         @echo "$(varname)=$($(varname))"
124 +%: varname=$(subst +,,$@)
125 +%:
126         @echo "$($(varname))"