From 526c5543e525eba2f55fb60da5e90dd6b5d308b9 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 9 Jun 2022 12:21:42 -0500 Subject: [PATCH 1/3] fix overwriting wheel on macos When I run on macOS, I get the following error: ``` Traceback (most recent call last): File "/Users/david/.local/pipx/.cache/fd54e06d50697e7/bin/cibuildwheel", line 8, in sys.exit(main()) File "/Users/david/.local/pipx/.cache/fd54e06d50697e7/lib/python3.10/site-packages/cibuildwheel/__main__.py", line 128, in main build_in_directory(args) File "/Users/david/.local/pipx/.cache/fd54e06d50697e7/lib/python3.10/site-packages/cibuildwheel/__main__.py", line 252, in build_in_directory cibuildwheel.macos.build(options, tmp_path) File "/Users/david/.local/pipx/.cache/fd54e06d50697e7/lib/python3.10/site-packages/cibuildwheel/macos.py", line 538, in build shutil.move(str(repaired_wheel), build_options.output_dir) File "/opt/homebrew/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 811, in move raise Error("Destination path '%s' already exists" % real_dst) shutil.Error: Destination path '/Users/david/Documents/GitHub/python-mpy-cross/wheelhouse/mpy_cross_v5-1.0.0-py3-none-macosx_11_0_arm64.whl' already exists ``` The comment in the code says that it should overwrite the file, so this removes the file if it exists first before trying to move the file. --- cibuildwheel/macos.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 7100cd05a..3ae2d2040 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -535,6 +535,11 @@ def build(options: Options, tmp_path: Path) -> None: # we're all done here; move it to output (overwrite existing) if abi3_wheel is None: + try: + os.remove(build_options.output_dir / repaired_wheel.name) + except OSError: + pass + shutil.move(str(repaired_wheel), build_options.output_dir) built_wheels.append(build_options.output_dir / repaired_wheel.name) From e6513a9b281fbdb12c0c2b82b263f47c135af66e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 16 Jun 2022 10:39:05 -0500 Subject: [PATCH 2/3] use Path.unlink() instead of os.unlink() --- cibuildwheel/macos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 3ae2d2040..18ccb04b0 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -536,7 +536,7 @@ def build(options: Options, tmp_path: Path) -> None: # we're all done here; move it to output (overwrite existing) if abi3_wheel is None: try: - os.remove(build_options.output_dir / repaired_wheel.name) + (build_options.output_dir / repaired_wheel.name).unlink() except OSError: pass From 9f4303ba2ccaf3f6ae7ed7593b5067b491f113af Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 16 Jun 2022 10:40:48 -0500 Subject: [PATCH 3/3] use FileNotFoundError instead of OSError --- cibuildwheel/macos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 18ccb04b0..91ba3f8e4 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -537,7 +537,7 @@ def build(options: Options, tmp_path: Path) -> None: if abi3_wheel is None: try: (build_options.output_dir / repaired_wheel.name).unlink() - except OSError: + except FileNotFoundError: pass shutil.move(str(repaired_wheel), build_options.output_dir)