From 93cd6b16207d2eba201a7fc3126624b616f5e6f9 Mon Sep 17 00:00:00 2001 From: Kamal Bin Mustafa Date: Sun, 20 May 2012 11:18:36 +0800 Subject: [PATCH 1/3] add --egg option to opt out --single-version-externally-managed --- pip/commands/install.py | 7 +++++++ pip/req.py | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pip/commands/install.py b/pip/commands/install.py index 925d57feb4a..2ca7310d09b 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -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. @@ -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) diff --git a/pip/req.py b/pip/req.py index d42063a115f..0e506726e45 100644 --- a/pip/req.py +++ b/pip/req.py @@ -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) @@ -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: @@ -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: @@ -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 @@ -781,7 +785,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 @@ -798,6 +802,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() @@ -807,6 +812,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: From 66ff8e05688a2575a25ef53b67297f67d8a5fd24 Mon Sep 17 00:00:00 2001 From: Kamal Bin Mustafa Date: Tue, 22 May 2012 18:54:40 +0800 Subject: [PATCH 2/3] add test for --egg option --- tests/test_basic.py | 14 ++++++++++++++ tests/test_uninstall.py | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 8bdce9772d6..288647c9bae 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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 ('.'). diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py index c88c7a681f0..fc3f843ebb2 100644 --- a/tests/test_uninstall.py +++ b/tests/test_uninstall.py @@ -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 @@ -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']) + From becfb83e36b738108905d3c385581a8853e349e3 Mon Sep 17 00:00:00 2001 From: Kamal Bin Mustafa Date: Thu, 24 May 2012 07:36:14 +0800 Subject: [PATCH 3/3] do write installed-files.txt if using install --egg --- pip/req.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pip/req.py b/pip/req.py index 0e506726e45..8a309493fdc 100644 --- a/pip/req.py +++ b/pip/req.py @@ -589,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()