From ff401dde50343c9bbc1c49a0294272f2da7d01e2 Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Tue, 30 Apr 2024 23:54:06 -0700 Subject: [PATCH] [SPARK-48069][INFRA] Handle `PEP-632` by checking `ModuleNotFoundError` on `setuptools` in Python 3.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What changes were proposed in this pull request? This PR aims to handle `PEP-632` by checking `ModuleNotFoundError` on `setuptools`. - [PEP 632 – Deprecate distutils module](https://peps.python.org/pep-0632/) ### Why are the changes needed? Use `Python 3.12`. ``` $ python3 --version Python 3.12.2 ``` **BEFORE** ``` $ dev/lint-python --mypy | grep ModuleNotFoundError Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'setuptools' ``` **AFTER** ``` $ dev/lint-python --mypy | grep ModuleNotFoundError ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs and manual test. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #46315 from dongjoon-hyun/SPARK-48069. Authored-by: Dongjoon Hyun Signed-off-by: Dongjoon Hyun --- dev/lint-python | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/lint-python b/dev/lint-python index 8d587bd52aca7..6bd843103bd74 100755 --- a/dev/lint-python +++ b/dev/lint-python @@ -84,7 +84,10 @@ function satisfies_min_version { local expected_version="$2" echo "$( "$PYTHON_EXECUTABLE" << EOM -from setuptools.extern.packaging import version +try: + from setuptools.extern.packaging import version +except ModuleNotFoundError: + from packaging import version print(version.parse('$provided_version') >= version.parse('$expected_version')) EOM )"