Skip to content

Commit

Permalink
Remove distutils (#180)
Browse files Browse the repository at this point in the history
* Remove distutils

Distutils is gone in Python 3.12+.

* Build & Clean: In Setuptools
  • Loading branch information
ax3l authored Oct 27, 2023
1 parent 2669550 commit 716f1f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Now, `cmake --version` should be at version 3.20.0 or newer.

Or go:
```bash
# optional: --user
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
```

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
18 changes: 7 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -33,10 +31,8 @@ def run(self):
# by default, this stays around. We want to make sure generated
# files like amrex_*d_pybind.*.(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)
Expand All @@ -54,6 +50,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:
Expand All @@ -63,10 +61,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:
Expand Down

0 comments on commit 716f1f8

Please sign in to comment.