summaryrefslogtreecommitdiff
path: root/setuptools/build_meta.py
diff options
context:
space:
mode:
authorShashank Singh <shashanksingh28@gmail.com>2019-04-20 23:24:41 -0400
committerPaul Ganssle <paul@ganssle.io>2019-04-22 10:19:28 -0400
commit901f7cc2a036bfeb93bfbe480608e04c76c2c5ec (patch)
tree0962d11daf503ab65ecdce1f4c400768d1efebaa /setuptools/build_meta.py
parentab79268c792ce2a5f0ccaed65dd0bc668fbbdba3 (diff)
downloadpython-setuptools-git-901f7cc2a036bfeb93bfbe480608e04c76c2c5ec.tar.gz
Fix error when wheels already exist in dist/
`build_meta.build_wheel` assumes that the only wheel in its output directory is the one it builds, but prior to this, it also used the `dist/` folder as its working output directory. This commit uses a temporary directory instead, preventing an error that was triggered when previously-generated wheel files were still sitting in `dist/`. Fixes GH #1671
Diffstat (limited to 'setuptools/build_meta.py')
-rw-r--r--setuptools/build_meta.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py
index 47cbcbf6..e40904a5 100644
--- a/setuptools/build_meta.py
+++ b/setuptools/build_meta.py
@@ -35,6 +35,7 @@ import contextlib
import setuptools
import distutils
+from setuptools.py31compat import TemporaryDirectory
from pkg_resources import parse_requirements
@@ -182,14 +183,22 @@ class _BuildMetaBackend(object):
metadata_directory=None):
config_settings = self._fix_config(config_settings)
wheel_directory = os.path.abspath(wheel_directory)
- sys.argv = sys.argv[:1] + ['bdist_wheel'] + \
- config_settings["--global-option"]
- self.run_setup()
- if wheel_directory != 'dist':
- shutil.rmtree(wheel_directory)
- shutil.copytree('dist', wheel_directory)
- return _file_with_extension(wheel_directory, '.whl')
+ # Build the wheel in a temporary directory, then copy to the target
+ with TemporaryDirectory(dir=wheel_directory) as tmp_dist_dir:
+ sys.argv = (sys.argv[:1] +
+ ['bdist_wheel', '--dist-dir', tmp_dist_dir] +
+ config_settings["--global-option"])
+ self.run_setup()
+
+ wheel_basename = _file_with_extension(tmp_dist_dir, '.whl')
+ wheel_path = os.path.join(wheel_directory, wheel_basename)
+ if os.path.exists(wheel_path):
+ # os.rename will fail overwriting on non-unix env
+ os.remove(wheel_path)
+ os.rename(os.path.join(tmp_dist_dir, wheel_basename), wheel_path)
+
+ return wheel_basename
def build_sdist(self, sdist_directory, config_settings=None):
config_settings = self._fix_config(config_settings)