Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide --egg option to opt out --single-version-externally-managed #541

Merged
merged 3 commits into from
May 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def __init__(self):
action='store_true',
help='Install to user-site')

self.parser.add_option(
'--egg',
dest='as_egg',
action='store_true',
help="Install as self contained egg file, like easy_install does.")

def _build_package_finder(self, options, index_urls):
"""
Create a package finder appropriate to this install command.
Expand Down Expand Up @@ -206,6 +212,7 @@ def run(self, options, args):
download_dir=options.download_dir,
download_cache=options.download_cache,
upgrade=options.upgrade,
as_egg=options.as_egg,
ignore_installed=options.ignore_installed,
ignore_dependencies=options.ignore_dependencies,
force_reinstall=options.force_reinstall)
Expand Down
17 changes: 14 additions & 3 deletions pip/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class InstallRequirement(object):

def __init__(self, req, comes_from, source_dir=None, editable=False,
url=None, update=True):
url=None, as_egg=False, update=True):
self.extras = ()
if isinstance(req, string_types):
req = pkg_resources.Requirement.parse(req)
Expand All @@ -45,6 +45,7 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
self.source_dir = source_dir
self.editable = editable
self.url = url
self.as_egg = as_egg
self._egg_info_path = None
# This holds the pkg_resources.Distribution object if this requirement
# is already available:
Expand Down Expand Up @@ -556,6 +557,7 @@ def install(self, install_options, global_options=()):
if self.editable:
self.install_editable(install_options, global_options)
return

temp_location = tempfile.mkdtemp('-record', 'pip-')
record_filename = os.path.join(temp_location, 'install-record.txt')
try:
Expand All @@ -565,9 +567,11 @@ def install(self, install_options, global_options=()):
"exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py] +\
list(global_options) + [
'install',
'--single-version-externally-managed',
'--record', record_filename]

if not self.as_egg:
install_args += ['--single-version-externally-managed']

if running_under_virtualenv():
## FIXME: I'm not sure if this is a reasonable location; probably not
## but we can't put it in the default location, as that is a virtualenv symlink that isn't writable
Expand All @@ -585,6 +589,11 @@ def install(self, install_options, global_options=()):
logger.notify('Record file %s not found' % record_filename)
return
self.install_succeeded = True
if self.as_egg:
# there's no --always-unzip option we can pass to install command
# so we unable to save the installed-files.txt
return

f = open(record_filename)
for line in f:
line = line.strip()
Expand Down Expand Up @@ -781,7 +790,7 @@ def __repr__(self):
class RequirementSet(object):

def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
upgrade=False, ignore_installed=False,
upgrade=False, ignore_installed=False, as_egg=False,
ignore_dependencies=False, force_reinstall=False):
self.build_dir = build_dir
self.src_dir = src_dir
Expand All @@ -798,6 +807,7 @@ def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
self.successfully_downloaded = []
self.successfully_installed = []
self.reqs_to_cleanup = []
self.as_egg = as_egg

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

def add_requirement(self, install_req):
name = install_req.name
install_req.as_egg = self.as_egg
if not name:
self.unnamed_requirements.append(install_req)
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ def test_install_from_local_directory_with_no_setup_py():
assert "is not installable. File 'setup.py' not found." in result.stdout


def test_install_as_egg():
"""
Test installing as egg, instead of flat install.
"""
env = reset_env()
to_install = abspath(join(here, 'packages', 'FSPkg'))
result = run_pip('install', to_install, '--egg', expect_error=False)
fspkg_folder = env.site_packages/'fspkg'
egg_folder = env.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
assert fspkg_folder not in result.files_created, str(result.stdout)
assert egg_folder in result.files_created, str(result)
assert join(egg_folder, 'fspkg') in result.files_created, str(result)


def test_install_curdir():
"""
Test installing current directory ('.').
Expand Down
22 changes: 20 additions & 2 deletions tests/test_uninstall.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import textwrap
import sys
from os.path import join
from os.path import join, abspath
from tempfile import mkdtemp
from tests.test_pip import reset_env, run_pip, assert_all_changes, write_file
from tests.test_pip import here, reset_env, run_pip, assert_all_changes, write_file, pyversion
from tests.local_repos import local_repo, local_checkout

from pip.util import rmtree
Expand Down Expand Up @@ -137,3 +137,21 @@ def test_uninstall_from_reqs_file():
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
assert_all_changes(
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])


def test_uninstall_as_egg():
"""
Test uninstall package installed as egg.

"""
env = reset_env()
to_install = abspath(join(here, 'packages', 'FSPkg'))
result = run_pip('install', to_install, '--egg', expect_error=False)
fspkg_folder = env.site_packages/'fspkg'
egg_folder = env.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
assert fspkg_folder not in result.files_created, str(result.stdout)
assert egg_folder in result.files_created, str(result)

result2 = run_pip('uninstall', 'FSPkg', '-y', expect_error=True)
assert_all_changes(result, result2, [env.venv/'build', 'cache'])