Skip to content

Commit 4c405a0

Browse files
committed
Restore deleted _copy_dist_from_dir().
This reverts commit 62ac258. pypa#3176 is about to add the missing piece that makes this code useful (and not dead), so let's not delete it.
1 parent 9e5e34e commit 4c405a0

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pip/download.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,45 @@ def unpack_file_url(link, location, download_dir=None, hashes=None):
702702
_copy_file(from_path, download_dir, content_type, link)
703703

704704

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+
705744
class PipXmlrpcTransport(xmlrpc_client.Transport):
706745
"""Provide a `xmlrpclib.Transport` implementation via a `PipSession`
707746
object.

0 commit comments

Comments
 (0)