Skip to content

Commit

Permalink
make install-pip: fix installation on python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 8, 2024
1 parent 54cf4ae commit 34bac08
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ uninstall: ## Uninstall this package.
cd ..; $(PYTHON) -m pip uninstall -y -v pyftpdlib || true
$(PYTHON) scripts/internal/purge_installation.py

install-pip: ## (only if necessary)
$(PYTHON) -c \
install-pip: ## Install pip (no-op if already installed).
@$(PYTHON) -c \
"import sys, ssl, os, pkgutil, tempfile, atexit; \
sys.exit(0) if pkgutil.find_loader('pip') else None; \
pyexc = 'from urllib.request import urlopen' if sys.version_info[0] >= 3 else 'from urllib2 import urlopen'; \
PY3 = sys.version_info[0] == 3; \
pyexc = 'from urllib.request import urlopen' if PY3 else 'from urllib2 import urlopen'; \
exec(pyexc); \
ctx = ssl._create_unverified_context() if hasattr(ssl, '_create_unverified_context') else None; \
url = 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' if not PY3 else 'https://bootstrap.pypa.io/get-pip.py'; \
kw = dict(context=ctx) if ctx else {}; \
req = urlopen('https://bootstrap.pypa.io/get-pip.py', **kw); \
req = urlopen(url, **kw); \
data = req.read(); \
f = tempfile.NamedTemporaryFile(suffix='.py'); \
atexit.register(f.close); \
f.write(data); \
f.flush(); \
print('downloaded %s' % f.name); \
code = os.system('%s %s --user' % (sys.executable, f.name)); \
code = os.system('%s %s --user --upgrade' % (sys.executable, f.name)); \
f.close(); \
sys.exit(code);"

Expand Down

0 comments on commit 34bac08

Please sign in to comment.