@@ -702,6 +702,45 @@ def unpack_file_url(link, location, download_dir=None, hashes=None):
702
702
_copy_file (from_path , download_dir , content_type , link )
703
703
704
704
705
+ def _copy_dist_from_dir (link_path , location ):
706
+ """Copy distribution files in `link_path` to `location`.
707
+
708
+ Invoked when user requests to install a local directory. E.g.:
709
+
710
+ pip install .
711
+ pip install ~/dev/git-repos/python-prompt-toolkit
712
+
713
+ """
714
+
715
+ # Note: This is currently VERY SLOW if you have a lot of data in the
716
+ # directory, because it copies everything with `shutil.copytree`.
717
+ # What it should really do is build an sdist and install that.
718
+ # See https://github.com/pypa/pip/issues/2195
719
+
720
+ if os .path .isdir (location ):
721
+ rmtree (location )
722
+
723
+ # build an sdist
724
+ setup_py = 'setup.py'
725
+ sdist_args = [sys .executable ]
726
+ sdist_args .append ('-c' )
727
+ sdist_args .append (
728
+ "import setuptools, tokenize;__file__=%r;"
729
+ "exec(compile(getattr(tokenize, 'open', open)(__file__).read()"
730
+ ".replace('\\ r\\ n', '\\ n'), __file__, 'exec'))" % setup_py )
731
+ sdist_args .append ('sdist' )
732
+ sdist_args += ['--dist-dir' , location ]
733
+ logger .info ('Running setup.py sdist for %s' , link_path )
734
+
735
+ with indent_log ():
736
+ call_subprocess (sdist_args , cwd = link_path , show_stdout = False )
737
+
738
+ # unpack sdist into `location`
739
+ sdist = os .path .join (location , os .listdir (location )[0 ])
740
+ logger .info ('Unpacking sdist %s into %s' , sdist , location )
741
+ unpack_file (sdist , location , content_type = None , link = None )
742
+
743
+
705
744
class PipXmlrpcTransport (xmlrpc_client .Transport ):
706
745
"""Provide a `xmlrpclib.Transport` implementation via a `PipSession`
707
746
object.
0 commit comments