From c9626f3267061f945b46443dd268895ef5831fca Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Sun, 29 Oct 2023 15:11:15 -0700 Subject: [PATCH] Remove distutils Distutils is gone in Python 3.12+. --- .../dependencies/clang-san-openmpi.sh | 3 ++- .github/workflows/dependencies/clang-tidy.sh | 3 ++- .github/workflows/dependencies/gcc-openmpi.sh | 3 ++- .github/workflows/dependencies/gcc.sh | 3 ++- .github/workflows/macos.yml | 3 ++- .github/workflows/windows.yml | 6 ++++-- docs/source/developers/testing.rst | 3 ++- docs/source/install/cmake.rst | 3 ++- pyproject.toml | 3 ++- setup.py | 18 +++++++----------- 10 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dependencies/clang-san-openmpi.sh b/.github/workflows/dependencies/clang-san-openmpi.sh index 9b7261223..df5b8293f 100755 --- a/.github/workflows/dependencies/clang-san-openmpi.sh +++ b/.github/workflows/dependencies/clang-san-openmpi.sh @@ -26,7 +26,8 @@ sudo apt-get install -y \ python3-pip \ wget -python3 -m pip install -U pip setuptools wheel +python3 -m pip install -U pip +python3 -m pip install -U build packaging setuptools wheel python3 -m pip install -U cmake pytest python3 -m pip install -U -r requirements_mpi.txt python3 -m pip install -U -r examples/requirements.txt diff --git a/.github/workflows/dependencies/clang-tidy.sh b/.github/workflows/dependencies/clang-tidy.sh index 4b8bb76a2..50cd73db0 100755 --- a/.github/workflows/dependencies/clang-tidy.sh +++ b/.github/workflows/dependencies/clang-tidy.sh @@ -25,7 +25,8 @@ sudo apt-get install -y \ python3-pip \ wget -python3 -m pip install -U pip setuptools wheel +python3 -m pip install -U pip +python3 -m pip install -U build packaging setuptools wheel python3 -m pip install -U cmake pytest python3 -m pip install -U -r requirements_mpi.txt python3 -m pip install -U -r examples/requirements.txt diff --git a/.github/workflows/dependencies/gcc-openmpi.sh b/.github/workflows/dependencies/gcc-openmpi.sh index 53c1bb4d0..bf921df33 100755 --- a/.github/workflows/dependencies/gcc-openmpi.sh +++ b/.github/workflows/dependencies/gcc-openmpi.sh @@ -22,7 +22,8 @@ sudo apt-get install -y \ python3-pip \ wget -python3 -m pip install -U pip setuptools wheel +python3 -m pip install -U pip +python3 -m pip install -U build packaging setuptools wheel python3 -m pip install -U cmake pytest python3 -m pip install -U -r requirements_mpi.txt python3 -m pip install -U -r examples/requirements.txt diff --git a/.github/workflows/dependencies/gcc.sh b/.github/workflows/dependencies/gcc.sh index 504bfc608..a4c94482e 100755 --- a/.github/workflows/dependencies/gcc.sh +++ b/.github/workflows/dependencies/gcc.sh @@ -21,7 +21,8 @@ sudo apt-get install -y \ python3-pip \ wget -python3 -m pip install -U pip setuptools wheel +python3 -m pip install -U pip +python3 -m pip install -U build packaging setuptools wheel python3 -m pip install -U cmake pytest python3 -m pip install -U -r examples/requirements.txt diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 886a0321b..42dd3c654 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -51,7 +51,8 @@ jobs: brew install ninja brew install open-mpi brew install pkg-config - python3 -m pip install --upgrade pip setuptools wheel pytest + python3 -m pip install --upgrade pip + python3 -m pip install --upgrade build packaging setuptools wheel pytest python3 -m pip install --upgrade pytest python3 -m pip install --upgrade -r requirements_mpi.txt python3 -m pip install --upgrade -r examples/requirements.txt diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7175cee1d..396dc6eea 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -52,7 +52,8 @@ jobs: $env:HDF5_DIR = "C:/Program Files/HDF_Group/HDF5/1.12.2/cmake/" $env:HDF5_USE_STATIC_LIBRARIES = "ON" - python3 -m pip install -U pip setuptools wheel pytest + python3 -m pip install -U pip + python3 -m pip install -U build packaging setuptools wheel pytest python3 -m pip install -U -r requirements.txt python3 -m pip install -U -r examples/requirements.txt python3 -m pip install -U openPMD-validator @@ -137,7 +138,8 @@ jobs: set "HDF5_DIR=C:/Program Files/HDF_Group/HDF5/1.12.2/cmake/" set "HDF5_USE_STATIC_LIBRARIES=ON" - python3 -m pip install -U pip setuptools wheel pytest + python3 -m pip install -U pip + python3 -m pip install -U build packaging setuptools wheel pytest python3 -m pip install -U -r requirements.txt python3 -m pip install -U -r examples/requirements.txt python3 -m pip install -U openPMD-validator diff --git a/docs/source/developers/testing.rst b/docs/source/developers/testing.rst index ad5a0359b..fc3450f15 100644 --- a/docs/source/developers/testing.rst +++ b/docs/source/developers/testing.rst @@ -12,7 +12,8 @@ In order to run our tests, you need to have a few :ref:`Python packages installe .. code-block:: sh - python3 -m pip install -U pip setuptools wheel pytest + python3 -m pip install -U pip + python3 -m pip install -U build packaging setuptools wheel pytest python3 -m pip install -r examples/requirements.txt Run diff --git a/docs/source/install/cmake.rst b/docs/source/install/cmake.rst index af2617bf5..65ad6238d 100644 --- a/docs/source/install/cmake.rst +++ b/docs/source/install/cmake.rst @@ -35,7 +35,8 @@ ImpactX depends on popular third party software. .. code-block:: bash - python3 -m pip install -U pip setuptools wheel pytest + python3 -m pip install -U pip + python3 -m pip install -U build packaging setuptools wheel pytest python3 -m pip install -U -r examples/requirements.txt diff --git a/pyproject.toml b/pyproject.toml index d7096f82d..f53522b56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,7 @@ requires = [ "setuptools>=42", "wheel", - "cmake>=3.20.0,<4.0.0" + "cmake>=3.20.0,<4.0.0", + "packaging>=23", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 1c8b1e365..0a87d1f44 100644 --- a/setup.py +++ b/setup.py @@ -5,9 +5,6 @@ # Authors: Axel Huebl # License: BSD-3-Clause-LBNL # -from distutils.command.build import build -from distutils.command.clean import clean -from distutils.version import LooseVersion import os import platform import re @@ -16,6 +13,7 @@ import sys from setuptools import Extension, setup +from setuptools.command.build import build from setuptools.command.build_ext import build_ext @@ -33,10 +31,8 @@ def run(self): # by default, this stays around. we want to make sure generated # files like libwarpx.(2d|3d|rz).(so|pyd) are always only the # ones we want to package and not ones from an earlier wheel's stage - c = clean(self.distribution) - c.all = True - c.finalize_options() - c.run() + if os.path.exists(self.build_base): + shutil.rmtree(self.build_base) # call superclass build.run(self) @@ -68,6 +64,8 @@ def __init__(self, name, sourcedir=""): class CMakeBuild(build_ext): def run(self): + from packaging.version import parse + try: out = subprocess.check_output(["cmake", "--version"]) except OSError: @@ -77,10 +75,8 @@ def run(self): + ", ".join(e.name for e in self.extensions) ) - cmake_version = LooseVersion( - re.search(r"version\s*([\d.]+)", out.decode()).group(1) - ) - if cmake_version < "3.20.0": + cmake_version = parse(re.search(r"version\s*([\d.]+)", out.decode()).group(1)) + if cmake_version < parse("3.20.0"): raise RuntimeError("CMake >= 3.20.0 is required") for ext in self.extensions: