Fix -nonet targets (zope3-buildout)
[zope-bootstrap.git] / Makefile.pybase
index b9db381..75333a7 100644 (file)
@@ -13,6 +13,55 @@ EASY_INSTALL = $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
 PIP          = $(BASEDIR)/$(PYTHON_DIR)/bin/pip
 PASTER       = $(BASEDIR)/$(PYTHON_DIR)/bin/paster
 
+# Usage:
+#     @$(dlegg) <package>
+#
+# Downloads egg to '$(DLCACHE)/<package>-*.egg' unless a file with that name
+# already exists.
+#
+# THIS DOES NOT WORK WITH ALL PACKAGES !!! USE WITH CARE
+define dlegg
+    _dlegg() {                                                         \
+       if [ -r $(DLCACHE)/$$1-*.egg ]; then                            \
+           name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
+           echo "Fetching '$$name' from cache.";                       \
+       else                                                            \
+           [ -z "$(NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
+           $(EASY_INSTALL) -zmaxd $(DLCACHE) $$1;                      \
+           name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
+           if [ -d $(DLCACHE)/$$name ]; then                           \
+               cd $(DLCACHE)/$$name;                                   \
+               zip -r ../$$name.zip .;                                 \
+               cd ..;                                                  \
+               rm -r $$name;                                           \
+               mv $$name.zip $$name;                                   \
+           fi;                                                         \
+       fi;                                                             \
+    };                                                                 \
+    _dlegg
+endef
+
+# Usage:
+#     @$(install) <package>
+#
+# Downloads egg to '$(DLCACHE)/<package>-*.egg' and installs it unless a file
+# with that name already exists.
+define install
+    _install() {                                                                       \
+       echo $(PIP_CACHE_FILES);                                                        \
+       echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1";        \
+       $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1";             \
+       cd $(DLCACHE)/pip;                                                              \
+       for file in *.tar.gz; do                                                        \
+           name="$${file##*%2F}";                                                      \
+           if [ "$$name" != "$$file" -a ! -r "$$name" ]; then                          \
+               ln -s $$file $$name || exit 1;                                          \
+           fi;                                                                         \
+       done                                                                            \
+    };                                                                                 \
+    _install
+endef
+
 ###########################################################################
 
 python-unpack: $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README
@@ -63,6 +112,7 @@ pip: $(PIP)
 $(PIP):
        @$(dlegg) pip
        $(EASY_INSTALL) $(DLCACHE)/pip-*.egg
+.PHONY: pip
 
 pybase: python setuptools pip
 .PHONY: pybase
@@ -84,3 +134,13 @@ eggs::
 clean:: python-clean
 
 setup:: pybase
+
+PIP_CACHE_FILES := $(shell cd $(DLCACHE)/pip; ls *.tar.gz | grep -vF '%2F')
+
+init-nonet: PIP_OPTS  = --no-index $(patsubst %,--find-link=file://$(BASEDIR)/$(DLCACHE)/pip/%,$(PIP_CACHE_FILES))
+
+help::
+       @echo "    python-rebuild"
+       @echo "        recompile python from source. This may be needed after"
+       @echo "        upgrading the host distribution."
+       @echo
\ No newline at end of file