Skip to contentSkip to conversation

build: convert from deprecated distutils to setuptools

PATCH Applied Thomas Bertschinger 2 participants 2 messages Feb 11, 2025 – Feb 12, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: convert from deprecated distutils to setuptools

According to PEP 632 [1], distutils is obsolete and removed after Python v3.12. Setuptools is the replacement.

There is a migration guide at [2] that suggests the following replacements:

{distutils.core => setuptools}.setup
{distutils => setuptools}.command
distutils.dep_util => setuptools.modified

Prior to setuptools v69.0.0 [3], newer_group was exposed through the now-deprecated setuptools.dep_util instead of setuptools.modified.

Rather than updating distutils.core.Extension, I remove it as it does not appear to be used.

---
I'm not deeply familiar with the Python ecosystem, so it'd be good to have this patch reviewed by someone who is.

I needed these changes to get pynfs to build on an Arch linux system with Python version 3.13.1.

I also tested on an AlmaLinux 8.10 system with Python version 3.6.8 and setuptools version 59.6.0, and it built succesfully for me there.

---
 nfs4.0/setup.py | 8 ++++++--
 nfs4.1/setup.py | 4 ++--
 rpc/setup.py    | 4 ++--
 setup.py        | 2 +-
 xdr/setup.py    | 2 +-
 5 files changed, 12 insertions(+), 8 deletions(-)
nfs4.0/setup.py +6 -2
index 58349d9..0f8380e 100755
@@ -3,8 +3,12 @@
 from __future__ import print_function
 from __future__ import absolute_import
 import sys
-from distutils.core import setup, Extension
-from distutils.dep_util import newer_group
+from setuptools import setup
+try:
+    from setuptools.modified import newer_group
+except ImportError:
+    # for older (before v69.0.0) versions of setuptools:
+    from setuptools.dep_util import newer_group
 import os
 import glob
 try:
nfs4.1/setup.py +2 -2
index e13170e..bfadea1 100644
@@ -1,5 +1,5 @@
 
-from distutils.core import setup
+from setuptools import setup
 
 DESCRIPTION = """
 nfs4
@@ -8,7 +8,7 @@ nfs4
 Add stuff here.
 """
 
-from distutils.command.build_py import build_py as _build_py
+from setuptools.command.build_py import build_py as _build_py
 import os
 from glob import glob
 try:
rpc/setup.py +2 -2
index 99dad5a..922838f 100644
@@ -1,5 +1,5 @@
 
-from distutils.core import setup
+from setuptools import setup
 
 DESCRIPTION = """
 rpc
@@ -8,7 +8,7 @@ rpc
 Add stuff here.
 """
 
-from distutils.command.build_py import build_py as _build_py
+from setuptools.command.build_py import build_py as _build_py
 import os
 from glob import glob
 try:
setup.py +1 -1
index 83dc6b5..203514d 100755
@@ -2,7 +2,7 @@
 
 from __future__ import print_function
 
-from distutils.core import setup
+from setuptools import setup
 
 import sys
 import os
xdr/setup.py +1 -1
index 3acb8a2..3778abb 100644
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-from distutils.core import setup
+from setuptools import setup
 
 DESCRIPTION = """
 xdrgen
Signature · 1 line
2.48.1
Reviewed-by Stephen Brennan on v1 1/1 Applied
#1 lore raw
Quoted 25 lines · Thomas Bertschinger

According to PEP 632 [1], distutils is obsolete and removed after Python v3.12. Setuptools is the replacement.

There is a migration guide at [2] that suggests the following replacements:

{distutils.core => setuptools}.setup
{distutils => setuptools}.command
distutils.dep_util => setuptools.modified

Prior to setuptools v69.0.0 [3], newer_group was exposed through the now-deprecated setuptools.dep_util instead of setuptools.modified.

Rather than updating distutils.core.Extension, I remove it as it does not appear to be used.

---
I'm not deeply familiar with the Python ecosystem, so it'd be good to have this patch reviewed by someone who is.

Quoted 5 lines

I needed these changes to get pynfs to build on an Arch linux system with Python version 3.13.1.

I also tested on an AlmaLinux 8.10 system with Python version 3.6.8 and setuptools version 59.6.0, and it built succesfully for me there.

Applied.

I asked a colleague with greater Python expertise than me to review it:

thanks very much for this, Thomas.

cheers,
c.

Quoted 92 lines
---
  nfs4.0/setup.py | 8 ++++++--
  nfs4.1/setup.py | 4 ++--
  rpc/setup.py    | 4 ++--
  setup.py        | 2 +-
  xdr/setup.py    | 2 +-
  5 files changed, 12 insertions(+), 8 deletions(-)
nfs4.0/setup.py +6 -2
index 58349d9..0f8380e 100755
@@ -3,8 +3,12 @@
  from __future__ import print_function
  from __future__ import absolute_import
  import sys
-from distutils.core import setup, Extension
-from distutils.dep_util import newer_group
+from setuptools import setup
+try:
+    from setuptools.modified import newer_group
+except ImportError:
+    # for older (before v69.0.0) versions of setuptools:
+    from setuptools.dep_util import newer_group
  import os
  import glob
  try:
nfs4.1/setup.py +2 -2
index e13170e..bfadea1 100644
@@ -1,5 +1,5 @@
 
-from distutils.core import setup
+from setuptools import setup
 
  DESCRIPTION = """
  nfs4
@@ -8,7 +8,7 @@ nfs4
  Add stuff here.
  """
 
-from distutils.command.build_py import build_py as _build_py
+from setuptools.command.build_py import build_py as _build_py
  import os
  from glob import glob
  try:
rpc/setup.py +2 -2
index 99dad5a..922838f 100644
@@ -1,5 +1,5 @@
 
-from distutils.core import setup
+from setuptools import setup
 
  DESCRIPTION = """
  rpc
@@ -8,7 +8,7 @@ rpc
  Add stuff here.
  """
 
-from distutils.command.build_py import build_py as _build_py
+from setuptools.command.build_py import build_py as _build_py
  import os
  from glob import glob
  try:
setup.py +1 -1
index 83dc6b5..203514d 100755
@@ -2,7 +2,7 @@
 
  from __future__ import print_function
 
-from distutils.core import setup
+from setuptools import setup
 
  import sys
  import os
xdr/setup.py +1 -1
index 3acb8a2..3778abb 100644
@@ -1,6 +1,6 @@
  #!/usr/bin/env python3
 
-from distutils.core import setup
+from setuptools import setup
 
  DESCRIPTION = """
  xdrgen