From 4f73032af0b0552cf4976182f5a53f511f8c1189 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 13 Mar 2015 09:15:55 -0700 Subject: [PATCH] Extract _copy_dist_from_dir from unpack_file_url Right now it's just a pretty simple `shutil.copytree`, but ideally we want it to do something more complex, involving building an sdist. Plus, this makes `unpack_file_url` fit on a single screen without scrolling for me. :-) See https://github.com/pypa/pip/issues/2195 --- pip/download.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pip/download.py b/pip/download.py index 0490150f4d9..0c84a713be3 100644 --- a/pip/download.py +++ b/pip/download.py @@ -692,9 +692,7 @@ def unpack_file_url(link, location, download_dir=None): # If it's a url to a local directory if os.path.isdir(link_path): - if os.path.isdir(location): - rmtree(location) - shutil.copytree(link_path, location, symlinks=True) + _copy_dist_from_dir(link_path, location) if download_dir: logger.info('Link is a directory, ignoring download_dir') return @@ -725,6 +723,27 @@ def unpack_file_url(link, location, download_dir=None): _copy_file(from_path, download_dir, content_type, link) +def _copy_dist_from_dir(link_path, location): + """Copy distribution files in `link_path` to `location`. + + Invoked when user requests to install a local directory. E.g.: + + pip install . + pip install ~/dev/git-repos/python-prompt-toolkit + + """ + + # Note: This is currently VERY SLOW if you have a lot of data in the + # directory, because it copies everything with `shutil.copytree`. + # What it should really do is build an sdist and install that. + # See https://github.com/pypa/pip/issues/2195 + + if os.path.isdir(location): + rmtree(location) + + shutil.copytree(link_path, location, symlinks=True) + + class PipXmlrpcTransport(xmlrpc_client.Transport): """Provide a `xmlrpclib.Transport` implementation via a `PipSession` object.