From 0a18db27ba8b6de3005a1aa6716aba0d9d7ae3f1 Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Sat, 18 Aug 2012 12:03:22 -0700 Subject: [PATCH 1/2] edited and repackaged to exclude twisted import --- tests/packages/parent-0.1.tar.gz | Bin 569 -> 483 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/packages/parent-0.1.tar.gz b/tests/packages/parent-0.1.tar.gz index 7d8673cacaac2ff27fd8f3daf4b0fd847a3b3c08..130e756f49136d23a05f84a4e1d57df200e12e7c 100644 GIT binary patch literal 483 zcmV<90UZ7xiwFo*6)#W%18`w-Wo~pWFfK7JbYXG;?U+qV61`lX@o*gBB*QU@Q!m0X&WMMI*8{b&Oe5s|`CC*o{`zxo-T$Jfwg1br zAk_`I)F#e}gQ3^YqhU&4W{@?h=lxA_3y3z0a6G9{C z|HJrKi+V0fvp;106P!?}|6%=auMfOg{}`|Qrx|trsav7``(S6O8@5%j|7+|2W_yGG z!}C9Na{%gp82{{Z_{ZSCXa9!VT5VnafB44~Z}?9r2LHWqt1F3S!r0o1g$avFb0nmy zv_(xm_|0+GM~;$7J{h$cGumrH5ADC9$;c(pGNf2>&*t1rey<)y%d>E~*%)1agZ%~o Z0000000000002Ng`~zFy9?k$L004c__c#Cm literal 569 zcmV-90>=FxiwFqe+WAic|72-%bT4pWa%FCGEif)IE_7jX0PUDvYuhjshJEc{A=pI{ zXi~|sWeDVAF!n*WG%&Valp?f5O~hHnUO8(*R-6|K!|Souj!dTqN?|dPO@%45o+RO$fD;H7~ zots`5057cmtLX{az|;5t7^gAp|Ly3%snPQ`^-nyYf4llKCY5xI{ktPL*8igz@uSZP@zV)4@BX@^%h<{$FxKn&)jZ1> zLt}J(gC5}(Qra!0S|F#r+Yo3etT;otz7vRNS}peHU>F*zfBx*B0LSWoyZ`U}KaIiv zx1|5`?fZYPKP8lc{_W`h?M2jo0{y>f{ihf2`X455FB|{=6Vd3v{|{3P`ZvNS;rN_8 z-v3(t$r&Lsz~RJOxDl#yBivr`NfLf8^PJoJ5&AN@m|R{>!uL8CedF!lF7&!|OKlI& z`y%Hu+eJUhnNY>vZEr*|v(mWrv+Ce9 Date: Sat, 18 Aug 2012 15:26:17 -0700 Subject: [PATCH 2/2] handle __pycache__ file removal --- pip/backwardcompat.py | 3 +++ pip/req.py | 17 ++++++++--------- pip/util.py | 1 - tests/test_uninstall.py | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/pip/backwardcompat.py b/pip/backwardcompat.py index 7f81c370d31..788023fae90 100644 --- a/pip/backwardcompat.py +++ b/pip/backwardcompat.py @@ -1,11 +1,14 @@ """Stuff that differs in different Python versions""" import os +import imp import sys import site __all__ = ['WindowsError'] +uses_pycache = hasattr(imp,'cache_from_source') + try: WindowsError = WindowsError except NameError: diff --git a/pip/req.py b/pip/req.py index f413b28e27c..4179f7ad893 100644 --- a/pip/req.py +++ b/pip/req.py @@ -1,5 +1,6 @@ from email.parser import FeedParser import os +import imp import pkg_resources import re import sys @@ -13,13 +14,13 @@ DistributionNotFound) from pip.vcs import vcs from pip.log import logger -from pip.util import display_path, rmtree, is_pypy +from pip.util import display_path, rmtree from pip.util import ask, ask_path_exists, backup_dir from pip.util import is_installable_dir, is_local, dist_is_local, dist_in_usersite from pip.util import renames, normalize_path, egg_link_path, dist_in_site_packages from pip.util import make_path_relative from pip.util import call_subprocess -from pip.backwardcompat import (urlparse, urllib, +from pip.backwardcompat import (urlparse, urllib, uses_pycache, ConfigParser, string_types, HTTPError, get_python_version, b) from pip.index import Link @@ -448,6 +449,8 @@ def uninstall(self, auto_confirm=False): for installed_file in dist.get_metadata('installed-files.txt').splitlines(): path = os.path.normpath(os.path.join(egg_info_path, installed_file)) paths_to_remove.add(path) + #FIXME: need a test for this elif block + #occurs with --single-version-externally-managed/--record outside of pip elif dist.has_metadata('top_level.txt'): if dist.has_metadata('namespace_packages.txt'): namespaces = dist.get_metadata('namespace_packages.txt') @@ -1435,13 +1438,9 @@ def add(self, path): else: self._refuse.add(path) - #workaround for pip issue #626 (debian pypy creates __pycache__ folders) - if is_pypy: - head, tail = os.path.split(path) - tail_root, tail_ext = os.path.splitext(tail) - if tail_ext == '.py': - pycache_path = os.path.join(head, '__pycache__', tail_root + '.pypy-%d%d.pyc' % sys.pypy_version_info[:2]) - self.add(pycache_path) + # __pycache__ files can show up after 'installed-files.txt' is created, due to imports + if os.path.splitext(path)[1] == '.py' and uses_pycache: + self.add(imp.cache_from_source(path)) def add_pth(self, pth_file, entry): diff --git a/pip/util.py b/pip/util.py index 8237db78adc..833a7adcc7a 100644 --- a/pip/util.py +++ b/pip/util.py @@ -172,7 +172,6 @@ def is_svn_page(html): return (re.search(r'[^<]*Revision \d+:', html) and re.search(r'Powered by (?:<a[^>]*?>)?Subversion', html, re.I)) -is_pypy = hasattr(sys, 'pypy_version_info') def file_contents(filename): fp = open(filename, 'rb') diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py index 408847487b4..28339a6152d 100644 --- a/tests/test_uninstall.py +++ b/tests/test_uninstall.py @@ -18,6 +18,8 @@ def test_simple_uninstall(): env = reset_env() result = run_pip('install', 'INITools==0.2') assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys()) + #the import forces the generation of __pycache__ if the version of python supports it + env.run('python', '-c', "import initools") result2 = run_pip('uninstall', 'INITools', '-y') assert_all_changes(result, result2, [env.venv/'build', 'cache']) @@ -36,6 +38,19 @@ def test_uninstall_with_scripts(): assert_all_changes(result, result2, [env.venv/'build', 'cache']) +def test_uninstall_easy_install_after_import(): + """ + Uninstall an easy_installed package after it's been imported + + """ + env = reset_env() + result = env.run('easy_install', 'INITools==0.2', expect_stderr=True) + #the import forces the generation of __pycache__ if the version of python supports it + env.run('python', '-c', "import initools") + result2 = run_pip('uninstall', 'INITools', '-y') + assert_all_changes(result, result2, [env.venv/'build', 'cache']) + + def test_uninstall_namespace_package(): """ Uninstall a distribution with a namespace package without clobbering @@ -66,6 +81,8 @@ def test_uninstall_overlapping_package(): result2 = run_pip('install', child_pkg, expect_error=False) assert join(env.site_packages, 'child') in result2.files_created, sorted(result2.files_created.keys()) assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result2.files_created, sorted(result2.files_created.keys()) + #the import forces the generation of __pycache__ if the version of python supports it + env.run('python', '-c', "import parent.plugins.child_plugin, child") result3 = run_pip('uninstall', '-y', 'child', expect_error=False) assert join(env.site_packages, 'child') in result3.files_deleted, sorted(result3.files_created.keys()) assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result3.files_deleted, sorted(result3.files_deleted.keys())