From f1c666803e7ec53b44ddda211f1dc5726d840f79 Mon Sep 17 00:00:00 2001 From: Xavier Fernandez Date: Sun, 11 Oct 2015 21:33:49 +0200 Subject: [PATCH 1/2] Fix/use 4e6d935eafa commit --- pip/download.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pip/download.py b/pip/download.py index bbef9ea89fe..1de8fcf6a34 100644 --- a/pip/download.py +++ b/pip/download.py @@ -671,9 +671,7 @@ def unpack_file_url(link, location, download_dir=None, hashes=None): # If it's a url to a local directory if is_dir_url(link): - 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 From d3c47bbbb51189435e039b64a8bdacc565592897 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 13 Apr 2016 13:23:58 -0700 Subject: [PATCH 2/2] Copy setup.py into place too. This works around a problem with the new sdist-based "pip install .": * when creating the sdist, we don't run a literal "setup.py sdist" * instead, sys.argv[0] is a complicated shim that injects setuptools even into distutils-based projects * as a result, distutils.command.sdist.add_defaults() doesn't realize that "setup.py" is the name of its setup script (it gets confused because sys.argv[0] is not a real file). * so add_defaults() doesn't include setup.py in the generated tarball. (projects could add "include setup.py" to their MANIFEST.in, but this is not common practice because usually it's automatic) * so the unpacked sdist (from which pip will make a wheel) lacks the critical setup.py This copies the setup.py from source tree to unpacked target tree. The patch also removes a performance comment that was obsoleted by switching to _copy_dist_from_dir(). refs #2195, #2535, #3176 --- pip/download.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pip/download.py b/pip/download.py index 1de8fcf6a34..e55738c7aa3 100644 --- a/pip/download.py +++ b/pip/download.py @@ -717,11 +717,6 @@ def _copy_dist_from_dir(link_path, location): """ - # 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) @@ -742,6 +737,13 @@ def _copy_dist_from_dir(link_path, location): logger.info('Unpacking sdist %s into %s', sdist, location) unpack_file(sdist, location, content_type=None, link=None) + # copy the original setup.py into `location`, since the shim's + # sys.argv[0] confuses distutils.command.sdist.add_defaults() into not + # automatically adding setup.py to the tarball + logger.info('Copying setup.py from original into %s', location) + shutil.copy(os.path.join(link_path, setup_py), + os.path.join(location, "setup.py")) + class PipXmlrpcTransport(xmlrpc_client.Transport): """Provide a `xmlrpclib.Transport` implementation via a `PipSession`