Skip to content

Commit d395915

Browse files
committed
Update Python virtual environment to latest version (fixing an SSL pip vulnerability), and update build instructions to better cache the generated virtual environment.
1 parent d8f9c63 commit d395915

5 files changed

+75
-55
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
/_trial_temp*
88
Makefile.local
99
.cache/
10-
.pkg/
10+
.pkglist
11+
.pyenv/
1112
.coverage
1213
build/
1314
ltc_scrypt.so

Makefile

+73-53
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# === makefile ------------------------------------------------------------===
22

33
ROOT=$(shell pwd)
4-
CACHE_ROOT=${ROOT}/.cache
5-
PKG_ROOT=${ROOT}/.pkg
4+
CACHE=${ROOT}/.cache
5+
PYENV=${ROOT}/.pyenv
6+
CONF=${ROOT}/conf
7+
APP_NAME=p2pool
68

79
-include Makefile.local
810

911
.PHONY: all
10-
all: ${PKG_ROOT}/.stamp-h
12+
all: python-env
1113

1214
.PHONY: check
1315
check: all
14-
"${PKG_ROOT}"/bin/coverage run "${PKG_ROOT}"/bin/trial p2pool
15-
"${PKG_ROOT}"/bin/coverage xml -o build/report/coverage.xml
16+
"${PYENV}"/bin/coverage run "${PYENV}"/bin/trial p2pool
17+
"${PYENV}"/bin/coverage xml -o build/report/coverage.xml
1618

1719
.PHONY: run
1820
run: all
19-
"${PKG_ROOT}"/bin/python run_p2pool.py
21+
"${PYENV}"/bin/python run_p2pool.py
2022

2123
.PHONY: shell
2224
shell: all
23-
"${PKG_ROOT}"/bin/ipython
25+
"${PYENV}"/bin/ipython
2426

2527
.PHONY: mostlyclean
2628
mostlyclean:
@@ -29,11 +31,11 @@ mostlyclean:
2931

3032
.PHONY: clean
3133
clean: mostlyclean
32-
-rm -rf "${PKG_ROOT}"
34+
-rm -rf "${PYENV}"
3335

3436
.PHONY: distclean
3537
distclean: clean
36-
-rm -rf "${CACHE_ROOT}"
38+
-rm -rf "${CACHE}"
3739

3840
.PHONY: maintainer-clean
3941
maintainer-clean: distclean
@@ -45,55 +47,73 @@ dist:
4547

4648
# ===--------------------------------------------------------------------===
4749

48-
${CACHE_ROOT}/virtualenv/virtualenv-1.10.1.tar.gz:
49-
mkdir -p ${CACHE_ROOT}/virtualenv
50-
sh -c "cd ${CACHE_ROOT}/virtualenv && curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.1.tar.gz"
51-
52-
${PKG_ROOT}/.stamp-h: conf/requirements*.pip ${CACHE_ROOT}/virtualenv/virtualenv-1.10.1.tar.gz
53-
# Because build and run-time dependencies are not thoroughly tracked,
54-
# it is entirely possible that rebuilding the development environment
55-
# on top of an existing one could result in a broken build. For the
56-
# sake of consistency and preventing unnecessary, difficult-to-debug
57-
# problems, the entire development environment is rebuilt from scratch
58-
# everytime this make target is selected.
59-
${MAKE} clean
60-
61-
# The ``${PKG_ROOT}`` directory, if it exists, is removed by the
62-
# ``clean`` target. The PyPI cache is nonexistant if this is a freshly
63-
# checked-out repository, or if the ``distclean`` target has been run.
64-
# This might cause problems with build scripts executed later which
65-
# assume their existence, so they are created now if they don't
66-
# already exist.
67-
mkdir -p "${PKG_ROOT}"
68-
mkdir -p "${CACHE_ROOT}"/pypi
50+
${CACHE}/pyenv/virtualenv-1.11.6.tar.gz:
51+
mkdir -p "${CACHE}"/pyenv
52+
curl -L 'https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.6.tar.gz' >'$@' || { rm -f '$@'; exit 1; }
53+
54+
${CACHE}/pyenv/pyenv-1.11.6-base.tar.gz: ${CACHE}/pyenv/virtualenv-1.11.6.tar.gz
55+
-rm -rf "${PYENV}"
56+
mkdir -p "${PYENV}"
6957

70-
# ``virtualenv`` is used to create a separate Python installation for
71-
# this project in ``${PKG_ROOT}``.
58+
# virtualenv is used to create a separate Python installation
59+
# for this project in ${PYENV}.
7260
tar \
73-
-C "${CACHE_ROOT}"/virtualenv --gzip \
74-
-xf "${CACHE_ROOT}"/virtualenv/virtualenv-1.10.1.tar.gz
75-
python "${CACHE_ROOT}"/virtualenv/virtualenv-1.10.1/virtualenv.py \
76-
--clear \
77-
--distribute \
78-
--never-download \
79-
--prompt="(p2pool) " \
80-
"${PKG_ROOT}"
81-
-rm -rf "${CACHE_ROOT}"/virtualenv/virtualenv-1.10.1
61+
-C "${CACHE}"/pyenv --gzip \
62+
-xf "${CACHE}"/pyenv/virtualenv-1.11.6.tar.gz
63+
python "${CACHE}"/pyenv/virtualenv-1.11.6/virtualenv.py \
64+
--clear \
65+
--distribute \
66+
--never-download \
67+
--prompt="(${APP_NAME}) " \
68+
"${PYENV}"
69+
-rm -rf "${CACHE}"/pyenv/virtualenv-1.11.6
70+
71+
# Snapshot the Python environment
72+
tar -C "${PYENV}" --gzip -cf "$@" .
73+
rm -rf "${PYENV}"
74+
75+
${CACHE}/pyenv/pyenv-1.11.6-extras.tar.gz: ${CACHE}/pyenv/pyenv-1.11.6-base.tar.gz ${ROOT}/requirements.txt ${CONF}/requirements*.txt
76+
-rm -rf "${PYENV}"
77+
mkdir -p "${PYENV}"
78+
mkdir -p "${CACHE}"/pypi
79+
80+
# Uncompress saved Python environment
81+
tar -C "${PYENV}" --gzip -xf "${CACHE}"/pyenv/pyenv-1.11.6-base.tar.gz
82+
find "${PYENV}" -not -type d -print0 >"${ROOT}"/.pkglist
8283

83-
# readline is installed here to get around a bug on Mac OS X which is
84-
# causing readline to not build properly if installed from pip.
85-
"${PKG_ROOT}"/bin/easy_install readline
84+
# readline is installed here to get around a bug on Mac OS X
85+
# which is causing readline to not build properly if installed
86+
# from pip, and the fact that a different package must be used
87+
# to support it on Windows/Cygwin.
88+
if [ "x`uname -s`" = "xCygwin" ]; then \
89+
"${PYENV}"/bin/pip install pyreadline; \
90+
else \
91+
"${PYENV}"/bin/easy_install readline; \
92+
fi
8693

8794
# pip is used to install Python dependencies for this project.
88-
for reqfile in conf/requirements*.pip; do \
89-
"${PKG_ROOT}"/bin/python "${PKG_ROOT}"/bin/pip install \
90-
--download-cache="${CACHE_ROOT}"/pypi \
91-
-r $$reqfile; \
95+
for reqfile in "${ROOT}"/requirements.txt \
96+
"${CONF}"/requirements*.txt; do \
97+
"${PYENV}"/bin/python "${PYENV}"/bin/pip install \
98+
--download-cache="${CACHE}"/pypi \
99+
-r "$$reqfile" || exit 1; \
92100
done
93101

94-
# All done!
95-
touch "${PKG_ROOT}"/.stamp-h
102+
# Snapshot the Python environment
103+
cat "${ROOT}"/.pkglist | xargs -0 rm -rf
104+
tar -C "${PYENV}" --gzip -cf "$@" .
105+
rm -rf "${PYENV}" "${ROOT}"/.pkglist
96106

97-
# ===--------------------------------------------------------------------===
98-
# End of File
99-
# ===--------------------------------------------------------------------===
107+
.PHONY:
108+
python-env: ${PYENV}/.stamp-h
109+
110+
${PYENV}/.stamp-h: ${CACHE}/pyenv/pyenv-1.11.6-base.tar.gz ${CACHE}/pyenv/pyenv-1.11.6-extras.tar.gz
111+
-rm -rf "${PYENV}"
112+
mkdir -p "${PYENV}"
113+
114+
# Uncompress saved Python environment
115+
tar -C "${PYENV}" --gzip -xf "${CACHE}"/pyenv/pyenv-1.11.6-base.tar.gz
116+
tar -C "${PYENV}" --gzip -xf "${CACHE}"/pyenv/pyenv-1.11.6-extras.tar.gz
117+
118+
# All done!
119+
touch "$@"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
ipdb==0.7
22
ipython==0.13.1
3-
readline>=6.2.4.1
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)