Skip to content

Commit 388081d

Browse files
committed
Merge branch 'develop'
2 parents fd5d16b + 6d0c134 commit 388081d

File tree

5 files changed

+96
-80
lines changed

5 files changed

+96
-80
lines changed

docs/changes.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Release History
22
===============
33

4+
15.0.0 (2016-03-05)
5+
-------------------
6+
7+
* Remove the `virtualenv-N.N` script from the package; this can no longer be correctly created from a wheel installation.
8+
Resolves :issue:`851`, :issue:`692`
9+
10+
* Remove accidental runtime dependency on pip by extracting certificate in the
11+
subprocess.
12+
13+
* Upgrade setuptools 20.2.2.
14+
15+
* Upgrade pip to 8.1.0.
16+
17+
418
14.0.6 (2016-02-07)
519
-------------------
620

@@ -80,7 +94,7 @@ Release History
8094

8195
* Make sure not to run a --user install when creating the virtualenv (:pull:`803`)
8296

83-
* Remove virtualenv file's path from directory when executing with a new
97+
* Remove virtualenv.py's path from sys.path when executing with a new
8498
python. Fixes issue :issue:`779`, :issue:`763` (:pull:`805`)
8599

86100
* Remove use of () in .bat files so ``Program Files (x86)`` works :issue:`35`

setup.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def run_tests(self):
2929

3030
setup_params = {
3131
'entry_points': {
32-
'console_scripts': [
33-
'virtualenv=virtualenv:main',
34-
'virtualenv-%s.%s=virtualenv:main' % sys.version_info[:2]
35-
],
32+
'console_scripts': ['virtualenv=virtualenv:main'],
3633
},
3734
'zip_safe': False,
3835
'cmdclass': {'test': PyTest},
@@ -46,9 +43,7 @@ def run_tests(self):
4643
setup_params = {}
4744
else:
4845
script = 'scripts/virtualenv'
49-
script_ver = script + '-%s.%s' % sys.version_info[:2]
50-
shutil.copy(script, script_ver)
51-
setup_params = {'scripts': [script, script_ver]}
46+
setup_params = {'scripts': [script]}
5247

5348

5449
def read_file(*paths):

virtualenv.py

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import subprocess
2828
import pkgutil
2929
import tempfile
30+
import textwrap
3031
from distutils.util import strtobool
3132
from os.path import join
3233

@@ -35,7 +36,7 @@
3536
except ImportError:
3637
import configparser as ConfigParser
3738

38-
__version__ = "14.0.6"
39+
__version__ = "15.0.0"
3940
virtualenv_version = __version__ # legacy
4041

4142
if sys.version_info < (2, 6):
@@ -353,22 +354,19 @@ def copyfile(src, dest, symlink=True):
353354
def writefile(dest, content, overwrite=True):
354355
if not os.path.exists(dest):
355356
logger.info('Writing %s', dest)
356-
f = open(dest, 'wb')
357-
f.write(content.encode('utf-8'))
358-
f.close()
357+
with open(dest, 'wb') as f:
358+
f.write(content.encode('utf-8'))
359359
return
360360
else:
361-
f = open(dest, 'rb')
362-
c = f.read()
363-
f.close()
361+
with open(dest, 'rb') as f:
362+
c = f.read()
364363
if c != content.encode("utf-8"):
365364
if not overwrite:
366365
logger.notify('File %s exists with different content; not overwriting', dest)
367366
return
368367
logger.notify('Overwriting %s with new content', dest)
369-
f = open(dest, 'wb')
370-
f.write(content.encode('utf-8'))
371-
f.close()
368+
with open(dest, 'wb') as f:
369+
f.write(content.encode('utf-8'))
372370
else:
373371
logger.info('Content %s already in place', dest)
374372

@@ -709,7 +707,7 @@ def main():
709707
def call_subprocess(cmd, show_stdout=True,
710708
filter_stdout=None, cwd=None,
711709
raise_on_returncode=True, extra_env=None,
712-
remove_from_env=None):
710+
remove_from_env=None, stdin=None):
713711
cmd_parts = []
714712
for part in cmd:
715713
if len(part) > 45:
@@ -739,7 +737,9 @@ def call_subprocess(cmd, show_stdout=True,
739737
env = None
740738
try:
741739
proc = subprocess.Popen(
742-
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
740+
cmd, stderr=subprocess.STDOUT,
741+
stdin=None if stdin is None else subprocess.PIPE,
742+
stdout=stdout,
743743
cwd=cwd, env=env)
744744
except Exception:
745745
e = sys.exc_info()[1]
@@ -748,6 +748,10 @@ def call_subprocess(cmd, show_stdout=True,
748748
raise
749749
all_output = []
750750
if stdout is not None:
751+
if stdin is not None:
752+
proc.stdin.write(stdin)
753+
proc.stdin.close()
754+
751755
stdout = proc.stdout
752756
encoding = sys.getdefaultencoding()
753757
fs_encoding = sys.getfilesystemencoding()
@@ -771,7 +775,7 @@ def call_subprocess(cmd, show_stdout=True,
771775
else:
772776
logger.info(line)
773777
else:
774-
proc.communicate()
778+
proc.communicate(stdin)
775779
proc.wait()
776780
if proc.returncode:
777781
if raise_on_returncode:
@@ -839,48 +843,56 @@ def space_path2url(p):
839843
return urljoin('file:', pathname2url(os.path.abspath(p)))
840844
findlinks = ' '.join(space_path2url(d) for d in search_dirs)
841845

842-
sys.path = pythonpath.split(os.pathsep) + sys.path
843-
cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
846+
SCRIPT = textwrap.dedent("""
847+
import sys
848+
import pkgutil
849+
import tempfile
850+
import os
844851
845-
if cert_data is not None:
846-
cert_file = tempfile.NamedTemporaryFile(delete=False)
847-
cert_file.write(cert_data)
848-
cert_file.close()
849-
else:
850-
cert_file = None
852+
import pip
851853
852-
try:
853-
cmd = [
854-
py_executable, '-c',
855-
'import sys, pip; sys.exit(pip.main(["install", "--ignore-installed"] + sys.argv[1:]))',
856-
] + project_names
857-
logger.start_progress('Installing %s...' % (', '.join(project_names)))
858-
logger.indent += 2
859-
860-
env = {
861-
"PYTHONPATH": pythonpath,
862-
"JYTHONPATH": pythonpath, # for Jython < 3.x
863-
"PIP_FIND_LINKS": findlinks,
864-
"PIP_USE_WHEEL": "1",
865-
"PIP_ONLY_BINARY": ":all:",
866-
"PIP_PRE": "1",
867-
"PIP_USER": "0",
868-
}
869-
870-
if not download:
871-
env["PIP_NO_INDEX"] = "1"
872-
873-
if cert_file is not None:
874-
env["PIP_CERT"] = cert_file.name
854+
cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
855+
if cert_data is not None:
856+
cert_file = tempfile.NamedTemporaryFile(delete=False)
857+
cert_file.write(cert_data)
858+
cert_file.close()
859+
else:
860+
cert_file = None
875861
876862
try:
877-
call_subprocess(cmd, show_stdout=False, extra_env=env)
863+
args = ["install", "--ignore-installed"]
864+
if cert_file is not None:
865+
args += ["--cert", cert_file.name]
866+
args += sys.argv[1:]
867+
868+
sys.exit(pip.main(args))
878869
finally:
879-
logger.indent -= 2
880-
logger.end_progress()
870+
if cert_file is not None:
871+
os.remove(cert_file.name)
872+
""").encode("utf8")
873+
874+
cmd = [py_executable, '-'] + project_names
875+
logger.start_progress('Installing %s...' % (', '.join(project_names)))
876+
logger.indent += 2
877+
878+
env = {
879+
"PYTHONPATH": pythonpath,
880+
"JYTHONPATH": pythonpath, # for Jython < 3.x
881+
"PIP_FIND_LINKS": findlinks,
882+
"PIP_USE_WHEEL": "1",
883+
"PIP_ONLY_BINARY": ":all:",
884+
"PIP_PRE": "1",
885+
"PIP_USER": "0",
886+
}
887+
888+
if not download:
889+
env["PIP_NO_INDEX"] = "1"
890+
891+
try:
892+
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
881893
finally:
882-
if cert_file is not None:
883-
os.remove(cert_file.name)
894+
logger.indent -= 2
895+
logger.end_progress()
884896

885897

886898
def create_environment(home_dir, site_packages=False, clear=False,
@@ -1583,16 +1595,14 @@ def fixup_scripts(home_dir, bin_dir):
15831595
if not os.path.isfile(filename):
15841596
# ignore subdirs, e.g. .svn ones.
15851597
continue
1586-
f = open(filename, 'rb')
1587-
try:
1598+
lines = None
1599+
with open(filename, 'rb') as f:
15881600
try:
15891601
lines = f.read().decode('utf-8').splitlines()
15901602
except UnicodeDecodeError:
15911603
# This is probably a binary program instead
15921604
# of a script, so just ignore it.
15931605
continue
1594-
finally:
1595-
f.close()
15961606
if not lines:
15971607
logger.warn('Script %s is an empty file' % filename)
15981608
continue
@@ -1611,9 +1621,9 @@ def fixup_scripts(home_dir, bin_dir):
16111621
continue
16121622
logger.notify('Making script %s relative' % filename)
16131623
script = relative_script([new_shebang] + lines[1:])
1614-
f = open(filename, 'wb')
1615-
f.write('\n'.join(script).encode('utf-8'))
1616-
f.close()
1624+
with open(filename, 'wb') as f:
1625+
f.write('\n'.join(script).encode('utf-8'))
1626+
16171627

16181628
def relative_script(lines):
16191629
"Return a script that'll work in a relocatable environment."
@@ -1660,9 +1670,8 @@ def fixup_pth_and_egg_link(home_dir, sys_path=None):
16601670
def fixup_pth_file(filename):
16611671
lines = []
16621672
prev_lines = []
1663-
f = open(filename)
1664-
prev_lines = f.readlines()
1665-
f.close()
1673+
with open(filename) as f:
1674+
prev_lines = f.readlines()
16661675
for line in prev_lines:
16671676
line = line.strip()
16681677
if (not line or line.startswith('#') or line.startswith('import ')
@@ -1677,22 +1686,19 @@ def fixup_pth_file(filename):
16771686
logger.info('No changes to .pth file %s' % filename)
16781687
return
16791688
logger.notify('Making paths in .pth file %s relative' % filename)
1680-
f = open(filename, 'w')
1681-
f.write('\n'.join(lines) + '\n')
1682-
f.close()
1689+
with open(filename, 'w') as f:
1690+
f.write('\n'.join(lines) + '\n')
16831691

16841692
def fixup_egg_link(filename):
1685-
f = open(filename)
1686-
link = f.readline().strip()
1687-
f.close()
1693+
with open(filename) as f:
1694+
link = f.readline().strip()
16881695
if os.path.abspath(link) != link:
16891696
logger.debug('Link in %s already relative' % filename)
16901697
return
16911698
new_link = make_relative_path(filename, link)
16921699
logger.notify('Rewriting link %s in %s as %s' % (link, filename, new_link))
1693-
f = open(filename, 'w')
1694-
f.write(new_link)
1695-
f.close()
1700+
with open(filename, 'w') as f:
1701+
f.write(new_link)
16961702

16971703
def make_relative_path(source, dest, dest_is_directory=True):
16981704
"""
@@ -1775,9 +1781,8 @@ def after_install(options, home_dir):
17751781
filename = __file__
17761782
if filename.endswith('.pyc'):
17771783
filename = filename[:-1]
1778-
f = codecs.open(filename, 'r', encoding='utf-8')
1779-
content = f.read()
1780-
f.close()
1784+
with codecs.open(filename, 'r', encoding='utf-8') as f:
1785+
content = f.read()
17811786
py_exe = 'python%s' % python_version
17821787
content = (('#!/usr/bin/env %s\n' % py_exe)
17831788
+ '## WARNING: This file is generated\n'
@@ -2297,7 +2302,9 @@ def do_file(file, offset=0, size=maxint):
22972302
do_macho(file, 64, LITTLE_ENDIAN)
22982303

22992304
assert(len(what) >= len(value))
2300-
do_file(open(path, 'r+b'))
2305+
2306+
with open(path, 'r+b') as f:
2307+
do_file(f)
23012308

23022309

23032310
if __name__ == '__main__':

0 commit comments

Comments
 (0)