ofek / hatch-vcs

Hatch plugin for versioning with your preferred VCS
MIT License
104 stars 15 forks source link

Don’t use deprecated shutil.rmtree(onerror=…) in Python 3.12+ #52

Closed musicinmybrain closed 1 year ago

musicinmybrain commented 1 year ago

The replacement is shutil.rmtree(onexc=…), which receives the exception instead of the sys.exc_info() tuple as the third argument.

Unfortunately, explicitly testing the Python version number seems to be required. See also https://github.com/pypa/pip/pull/12137.

Fixes a DeprecationWarning like

================================================== warnings summary ==================================================
tests/test_build.py: 5 warnings
tests/test_build_config.py: 6 warnings
tests/test_metadata_config.py: 4 warnings
tests/test_version_config.py: 7 warnings
  /home/ben/src/forks/hatch-vcs/tests/conftest.py:32: DeprecationWarning: onerror argument is deprecated, use onexc instead
    shutil.rmtree(directory, ignore_errors=False, onerror=handle_remove_readonly)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

when running the tests on Python 3.12.

musicinmybrain commented 1 year ago

it might be nice to simply define a small wrapper around rmtree

i wonder if there is a inexpensive backport

Is something like https://github.com/ofek/hatch-vcs/pull/53 what you were thinking of?

musicinmybrain commented 1 year ago

I didn’t address the line-by-line feedback in this PR (waiting to see if the approach in https://github.com/ofek/hatch-vcs/pull/53 is preferred or not), but I did cherry-pick @ofek’s suggested change to the version check from that PR.

ofek commented 1 year ago

Superseded by https://github.com/ofek/hatch-vcs/pull/53