Skip to content

Commit

Permalink
Copy setup.py into place too.
Browse files Browse the repository at this point in the history
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 pypa#2195, pypa#2535, pypa#3176
  • Loading branch information
warner committed Apr 13, 2016
1 parent f1c6668 commit d3c47bb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pip/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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`
Expand Down

0 comments on commit d3c47bb

Please sign in to comment.