Skip to content

Commit

Permalink
fix: remove warning on 3.12a7+
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 14, 2023
1 parent 5a8811b commit 76b08ca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/news.rst
Expand Up @@ -5,6 +5,8 @@ Release Notes

- Added full support of the build tag syntax to ``wheel tags`` (you can now set a build
tag like ``123mytag``)
- Fix warning on Python 3.12 about ``onerror`` deprecation. (PR by Henry Schreiner)
- Support testing on Python 3.12 betas (PR by Ewout ter Hoeven)

**0.40.0 (2023-03-14)**

Expand Down
11 changes: 9 additions & 2 deletions src/wheel/bdist_wheel.py
Expand Up @@ -131,7 +131,11 @@ def safer_version(version):


def remove_readonly(func, path, excinfo):
print(str(excinfo[1]))
remove_readonly_exc(func, path, excinfo[1])


def remove_readonly_exc(func, path, exc):
print(str(exc))
os.chmod(path, stat.S_IWRITE)
func(path)

Expand Down Expand Up @@ -416,7 +420,10 @@ def run(self):
if not self.keep_temp:
log.info(f"removing {self.bdist_dir}")
if not self.dry_run:
rmtree(self.bdist_dir, onerror=remove_readonly)
if sys.version_info < (3, 12):
rmtree(self.bdist_dir, onerror=remove_readonly)

Check warning on line 424 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L423-L424

Added lines #L423 - L424 were not covered by tests
else:
rmtree(self.bdist_dir, onexc=remove_readonly_exc)

Check warning on line 426 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L426

Added line #L426 was not covered by tests

def write_wheelfile(
self, wheelfile_base, generator="bdist_wheel (" + wheel_version + ")"
Expand Down
33 changes: 32 additions & 1 deletion tests/test_bdist_wheel.py
Expand Up @@ -6,11 +6,17 @@
import subprocess
import sys
import sysconfig
from unittest.mock import Mock
from zipfile import ZipFile

import pytest

from wheel.bdist_wheel import bdist_wheel, get_abi_tag
from wheel.bdist_wheel import (
bdist_wheel,
get_abi_tag,
remove_readonly,
remove_readonly_exc,
)
from wheel.vendored.packaging import tags
from wheel.wheelfile import WheelFile

Expand Down Expand Up @@ -296,3 +302,28 @@ def test_platform_with_space(dummy_dist, monkeypatch):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--plat-name", "isilon onefs"]
)


def test_rmtree_readonly(monkeypatch, tmp_path):
"""Verify onerr works as expected"""

bdist_dir = tmp_path / "with_readonly"
bdist_dir.mkdir()
some_file = bdist_dir.joinpath("file.txt")
some_file.touch()
some_file.chmod(stat.S_IREAD)

if sys.version_info < (3, 12):
count_remove_readonly = Mock(side_effect=remove_readonly)
shutil.rmtree(bdist_dir, onerror=count_remove_readonly)
assert count_remove_readonly.call_count == (
1 if sys.platform.startswith("win") else 0
)
else:
count_remove_readonly_exc = Mock(side_effect=remove_readonly_exc)
shutil.rmtree(bdist_dir, onexc=count_remove_readonly_exc)
assert count_remove_readonly_exc.call_count == (
1 if sys.platform.startswith("win") else 0
)

assert not bdist_dir.is_dir()

0 comments on commit 76b08ca

Please sign in to comment.