Skip to content

Commit 673c709

Browse files
author
Carl Meyer
committed
Merge pull request #541 from k4ml/as-egg
Provide --egg option to opt out of --single-version-externally-managed
2 parents e0db44e + becfb83 commit 673c709

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

pip/commands/install.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def __init__(self):
165165
action='store_true',
166166
help='Install to user-site')
167167

168+
self.parser.add_option(
169+
'--egg',
170+
dest='as_egg',
171+
action='store_true',
172+
help="Install as self contained egg file, like easy_install does.")
173+
168174
def _build_package_finder(self, options, index_urls):
169175
"""
170176
Create a package finder appropriate to this install command.
@@ -206,6 +212,7 @@ def run(self, options, args):
206212
download_dir=options.download_dir,
207213
download_cache=options.download_cache,
208214
upgrade=options.upgrade,
215+
as_egg=options.as_egg,
209216
ignore_installed=options.ignore_installed,
210217
ignore_dependencies=options.ignore_dependencies,
211218
force_reinstall=options.force_reinstall)

pip/req.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
class InstallRequirement(object):
3636

3737
def __init__(self, req, comes_from, source_dir=None, editable=False,
38-
url=None, update=True):
38+
url=None, as_egg=False, update=True):
3939
self.extras = ()
4040
if isinstance(req, string_types):
4141
req = pkg_resources.Requirement.parse(req)
@@ -45,6 +45,7 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
4545
self.source_dir = source_dir
4646
self.editable = editable
4747
self.url = url
48+
self.as_egg = as_egg
4849
self._egg_info_path = None
4950
# This holds the pkg_resources.Distribution object if this requirement
5051
# is already available:
@@ -556,6 +557,7 @@ def install(self, install_options, global_options=()):
556557
if self.editable:
557558
self.install_editable(install_options, global_options)
558559
return
560+
559561
temp_location = tempfile.mkdtemp('-record', 'pip-')
560562
record_filename = os.path.join(temp_location, 'install-record.txt')
561563
try:
@@ -565,9 +567,11 @@ def install(self, install_options, global_options=()):
565567
"exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py] +\
566568
list(global_options) + [
567569
'install',
568-
'--single-version-externally-managed',
569570
'--record', record_filename]
570571

572+
if not self.as_egg:
573+
install_args += ['--single-version-externally-managed']
574+
571575
if running_under_virtualenv():
572576
## FIXME: I'm not sure if this is a reasonable location; probably not
573577
## but we can't put it in the default location, as that is a virtualenv symlink that isn't writable
@@ -585,6 +589,11 @@ def install(self, install_options, global_options=()):
585589
logger.notify('Record file %s not found' % record_filename)
586590
return
587591
self.install_succeeded = True
592+
if self.as_egg:
593+
# there's no --always-unzip option we can pass to install command
594+
# so we unable to save the installed-files.txt
595+
return
596+
588597
f = open(record_filename)
589598
for line in f:
590599
line = line.strip()
@@ -781,7 +790,7 @@ def __repr__(self):
781790
class RequirementSet(object):
782791

783792
def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
784-
upgrade=False, ignore_installed=False,
793+
upgrade=False, ignore_installed=False, as_egg=False,
785794
ignore_dependencies=False, force_reinstall=False):
786795
self.build_dir = build_dir
787796
self.src_dir = src_dir
@@ -798,6 +807,7 @@ def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
798807
self.successfully_downloaded = []
799808
self.successfully_installed = []
800809
self.reqs_to_cleanup = []
810+
self.as_egg = as_egg
801811

802812
def __str__(self):
803813
reqs = [req for req in self.requirements.values()
@@ -807,6 +817,7 @@ def __str__(self):
807817

808818
def add_requirement(self, install_req):
809819
name = install_req.name
820+
install_req.as_egg = self.as_egg
810821
if not name:
811822
self.unnamed_requirements.append(install_req)
812823
else:

tests/test_basic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ def test_install_from_local_directory_with_no_setup_py():
302302
assert "is not installable. File 'setup.py' not found." in result.stdout
303303

304304

305+
def test_install_as_egg():
306+
"""
307+
Test installing as egg, instead of flat install.
308+
"""
309+
env = reset_env()
310+
to_install = abspath(join(here, 'packages', 'FSPkg'))
311+
result = run_pip('install', to_install, '--egg', expect_error=False)
312+
fspkg_folder = env.site_packages/'fspkg'
313+
egg_folder = env.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
314+
assert fspkg_folder not in result.files_created, str(result.stdout)
315+
assert egg_folder in result.files_created, str(result)
316+
assert join(egg_folder, 'fspkg') in result.files_created, str(result)
317+
318+
305319
def test_install_curdir():
306320
"""
307321
Test installing current directory ('.').

tests/test_uninstall.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import textwrap
22
import sys
3-
from os.path import join
3+
from os.path import join, abspath
44
from tempfile import mkdtemp
5-
from tests.test_pip import reset_env, run_pip, assert_all_changes, write_file
5+
from tests.test_pip import here, reset_env, run_pip, assert_all_changes, write_file, pyversion
66
from tests.local_repos import local_repo, local_checkout
77

88
from pip.util import rmtree
@@ -137,3 +137,21 @@ def test_uninstall_from_reqs_file():
137137
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
138138
assert_all_changes(
139139
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
140+
141+
142+
def test_uninstall_as_egg():
143+
"""
144+
Test uninstall package installed as egg.
145+
146+
"""
147+
env = reset_env()
148+
to_install = abspath(join(here, 'packages', 'FSPkg'))
149+
result = run_pip('install', to_install, '--egg', expect_error=False)
150+
fspkg_folder = env.site_packages/'fspkg'
151+
egg_folder = env.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
152+
assert fspkg_folder not in result.files_created, str(result.stdout)
153+
assert egg_folder in result.files_created, str(result)
154+
155+
result2 = run_pip('uninstall', 'FSPkg', '-y', expect_error=True)
156+
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
157+

0 commit comments

Comments
 (0)