Skip to content

Commit

Permalink
[Python] Use CPython libraries over distuils
Browse files Browse the repository at this point in the history
As distutils and Easy Install are deprecated

c.f.:
* https://setuptools.pypa.io/en/stable/deprecated/distutils-legacy.html
* https://setuptools.pypa.io/en/stable/deprecated/easy_install.html

it is perferable to convert use of distutils to either use existing CPython
libraries or use setuptool's versions of them. This patch applies

* distutils.spawn.find_executable -> shutil.which

Henry Schreiner pointed out that shutil.which (added in Python 3.3) is perferable
to setuptools._distutils.spawn.find_executable.

This patch was meant to also change:

* distutils.setup -> setuptools.setup
* distutils.sysconfig -> CPython's sysconfig

but it seems that these are still required given the current state of the build
and will need to be revised in a later PR.

The change

distutils.core.Extension -> setuptools.Extension

could be applied in:

* bindings/python/setup_pypi.py
* bindings/python/setup_standalone.py

but isn't as these files are obsolete and should be removed.

Co-authored-by: Henry Schreiner <henry.fredrick.schreiner@cern.ch>
  • Loading branch information
matthewfeickert and henryiii committed Jan 18, 2022
1 parent 25d52dc commit 3267e92
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packaging/wheel/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from setuptools.command.sdist import sdist
from wheel.bdist_wheel import bdist_wheel

# shutil.which was added in Python 3.3
# c.f. https://docs.python.org/3/library/shutil.html#shutil.which
try:
from shutil import which
except ImportError:
from distutils.spawn import find_executable as which

import subprocess
import sys
import getpass
Expand All @@ -27,11 +34,9 @@ def get_version_from_file():

def binary_exists(name):
"""Check whether `name` is on PATH."""
from distutils.spawn import find_executable
return find_executable(name) is not None
return which(name) is not None

def check_cmake3(path):
from distutils.spawn import find_executable
args = (path, "--version")
popen = subprocess.Popen(args, stdout=subprocess.PIPE)
popen.wait()
Expand All @@ -42,12 +47,11 @@ def check_cmake3(path):

def cmake_exists():
"""Check whether CMAKE is on PATH."""
from distutils.spawn import find_executable
path = find_executable('cmake')
path = which('cmake')
if path is not None:
if check_cmake3(path): return True, path
path = find_executable('cmake3')
return path is not None, path
path = which('cmake3')
return path is not None, path

def is_rhel7():
"""check if we are running on rhel7 platform"""
Expand Down Expand Up @@ -78,9 +82,8 @@ def has_cxx14():

# def python_dependency_name( py_version_short, py_version_nodot ):
# """ find the name of python dependency """
# from distutils.spawn import find_executable
# # this is the path to default python
# path = find_executable( 'python' )
# path = which( 'python' )
# from os.path import realpath
# # this is the real default python after resolving symlinks
# real = realpath(path)
Expand Down

0 comments on commit 3267e92

Please sign in to comment.