From b274b85f9682d6f3642a2e5762e4219c7abfde27 Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Mon, 21 Apr 2014 23:07:25 -0700 Subject: don't install empty dirs during wheel installs --- pip/wheel.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pip/wheel.py') diff --git a/pip/wheel.py b/pip/wheel.py index 839259df4..4e40657a2 100644 --- a/pip/wheel.py +++ b/pip/wheel.py @@ -134,10 +134,11 @@ def get_entrypoints(filename): def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, - pycompile=True): + pycompile=True, scheme=None): """Install a wheel""" - scheme = distutils_scheme(name, user=user, home=home, root=root) + if not scheme: + scheme = distutils_scheme(name, user=user, home=home, root=root) if root_is_purelib(name, wheeldir): lib_dir = scheme['purelib'] @@ -177,6 +178,7 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, for dir, subdirs, files in os.walk(source): basedir = dir[len(source):].lstrip(os.path.sep) + destdir = os.path.join(dest, basedir) if is_base and basedir.split(os.path.sep, 1)[0].endswith('.data'): continue for s in subdirs: @@ -190,8 +192,8 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, and s.lower().startswith(req.project_name.replace('-', '_').lower())): assert not info_dir, 'Multiple .dist-info directories' info_dir.append(destsubdir) - if not os.path.exists(destsubdir): - os.makedirs(destsubdir) + if files and not os.path.exists(destdir): + os.makedirs(destdir) for f in files: # Skip unwanted files if filter and filter(f): -- cgit v1.2.1 From b542c9906bfb8f700291ca6e16e10b7971a89dcb Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Tue, 22 Apr 2014 16:09:04 -0700 Subject: move directory creation below the file filtering --- pip/wheel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'pip/wheel.py') diff --git a/pip/wheel.py b/pip/wheel.py index 4e40657a2..82df2973f 100644 --- a/pip/wheel.py +++ b/pip/wheel.py @@ -192,14 +192,16 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, and s.lower().startswith(req.project_name.replace('-', '_').lower())): assert not info_dir, 'Multiple .dist-info directories' info_dir.append(destsubdir) - if files and not os.path.exists(destdir): - os.makedirs(destdir) for f in files: # Skip unwanted files if filter and filter(f): continue srcfile = os.path.join(dir, f) destfile = os.path.join(dest, basedir, f) + # directory creation is lazy and after the file filtering above + # to ensure we don't install empty dirs + if not os.path.exists(destdir): + os.makedirs(destdir) shutil.move(srcfile, destfile) changed = False if fixer: -- cgit v1.2.1 From 79408cbc6fa5d61b74b046105aee61f12311adc9 Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Wed, 23 Apr 2014 13:08:07 -0700 Subject: use copy2, not move, to ensure dirs are not copied --- pip/wheel.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pip/wheel.py') diff --git a/pip/wheel.py b/pip/wheel.py index 82df2973f..4e9803f23 100644 --- a/pip/wheel.py +++ b/pip/wheel.py @@ -199,10 +199,14 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None, srcfile = os.path.join(dir, f) destfile = os.path.join(dest, basedir, f) # directory creation is lazy and after the file filtering above - # to ensure we don't install empty dirs + # to ensure we don't install empty dirs; empty dirs can't be + # uninstalled. if not os.path.exists(destdir): os.makedirs(destdir) - shutil.move(srcfile, destfile) + # use copy2 (not move) to be extra sure we're not moving + # directories over; copy2 fails for directories. this would + # fail tests (not during released/user execution) + shutil.copy2(srcfile, destfile) changed = False if fixer: changed = fixer(destfile) -- cgit v1.2.1