Skip to content

Commit

Permalink
Replacement for the deprecation of distutils in Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
samcmill committed Nov 8, 2023
1 parent 5603329 commit 7e938aa
Show file tree
Hide file tree
Showing 39 changed files with 229 additions and 221 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
include:
- os: macos-latest
python-version: '3.5'
Expand All @@ -34,7 +34,7 @@ jobs:
else
python -m pip install --upgrade pip
fi
pip install six archspec
pip install six archspec packaging
shell: bash

- name: Run unit tests
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ specified using this option are inserted into a Python dictionary
named `USERARG` that can be accessed inside a recipe.

```python
from distutils.version import StrictVersion
from packaging.version import Version

cuda_version = USERARG.get('cuda', '9.1')
if StrictVersion(cuda_version) < StrictVersion('9.0'):
if Version(cuda_version) < Version('9.0'):
raise RuntimeError('invalid CUDA version: {}'.format(cuda_version))
Stage0 += baseimage(image='nvidia/cuda:{}-devel-ubuntu16.04'.format(cuda_version))

ompi_version = USERARG.get('ompi', '3.1.2')
if not StrictVersion(ompi_version):
if not Version(ompi_version):
raise RuntimeError('invalid OpenMPI version: {}'.format(ompi_version))
Stage0 += openmpi(infiniband=False, version=ompi_version)
```
Expand Down Expand Up @@ -353,7 +353,7 @@ provide equivalent functionality.
#!/usr/bin/env python
from __future__ import print_function
from distutils.version import StrictVersion
from packaging.version import Version
import argparse
import hpccm
Expand All @@ -372,11 +372,11 @@ args = parser.parse_args()
Stage0 = hpccm.Stage()
if StrictVersion(args.cuda) < StrictVersion('9.0'):
if Version(args.cuda) < Version('9.0'):
raise RuntimeError('invalid CUDA version: {}'.format(args.cuda))
Stage0 += baseimage(image='nvidia/cuda:{}-devel-ubuntu16.04'.format(args.cuda))
if not StrictVersion(args.ompi):
if not Version(args.ompi):
raise RuntimeError('invalid OpenMPI version: {}'.format(args.ompi))
Stage0 += openmpi(infiniband=False, version=args.ompi)
Expand Down
18 changes: 9 additions & 9 deletions hpccm/building_blocks/arm_allinea_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import StrictVersion
from packaging.version import Version
import logging
import posixpath
import re
Expand Down Expand Up @@ -168,11 +168,11 @@ def __distro(self):
specified value overrides any defaults."""

if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
if StrictVersion(self.__version) <= StrictVersion('20.3'):
if Version(self.__version) <= Version('20.3'):
self.__directory_string = 'Ubuntu-16.04'
self.__package_string = 'Ubuntu-16.04'
self.__url_string = 'Ubuntu16.04'
elif hpccm.config.g_linux_version <= StrictVersion('18.04'):
elif hpccm.config.g_linux_version <= Version('18.04'):
self.__directory_string = 'Ubuntu-18.04'
self.__package_string = 'Ubuntu-18.04'
self.__url_string = "ACfL"
Expand All @@ -182,7 +182,7 @@ def __distro(self):
self.__url_string = "ACfL"

self.__installer_template = 'arm-compiler-for-linux_{{}}_{0}.sh'.format(self.__directory_string)
if hpccm.config.g_linux_version >= StrictVersion('22.04'):
if hpccm.config.g_linux_version >= Version('22.04'):
python2_package = "python2"
else:
python2_package = "python"
Expand All @@ -191,17 +191,17 @@ def __distro(self):
'tcl', 'wget']

elif hpccm.config.g_linux_distro == linux_distro.CENTOS:
if hpccm.config.g_linux_version >= StrictVersion('8.0'):
if hpccm.config.g_linux_version >= Version('8.0'):
self.__directory_string = 'RHEL-8'
self.__package_string = 'RHEL-8'
if StrictVersion(self.__version) <= StrictVersion('20.3'):
if Version(self.__version) <= Version('20.3'):
self.__url_string = 'RHEL8'
else:
self.__url_string = 'ACfL'
else:
self.__directory_string = 'RHEL-7'
self.__package_string = 'RHEL-7'
if StrictVersion(self.__version) <= StrictVersion('20.3'):
if Version(self.__version) <= Version('20.3'):
self.__url_string = 'RHEL7'
else:
self.__url_string = 'ACfL'
Expand Down Expand Up @@ -252,10 +252,10 @@ def __setup(self):
install_args = ['--install-to {}'.format(self.__prefix)]
if self.__eula:
install_args.append('--accept')
if self.__microarchitectures and StrictVersion(self.__version) <= StrictVersion('20.3'):
if self.__microarchitectures and Version(self.__version) <= Version('20.3'):
install_args.append('--only-install-microarchitectures={}'.format(
','.join(self.__microarchitectures)))
if StrictVersion(self.__version) >= StrictVersion("21.1"):
if Version(self.__version) >= Version("21.1"):
arch_string = ""
else:
arch_string = "_aarch64"
Expand Down
4 changes: 2 additions & 2 deletions hpccm/building_blocks/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import LooseVersion
from packaging.version import Version
import posixpath

import hpccm.config
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, **kwargs):
self.__version = kwargs.get('version', '6.10.2')

# Version 6.9.0 dropped the 'v' from directory name
if LooseVersion(self.__version) >= LooseVersion('6.9.0'):
if Version(self.__version) >= Version('6.9.0'):
self.__installdir = posixpath.join(
self.__prefix, 'charm-{}'.format(self.__version))
else:
Expand Down
8 changes: 4 additions & 4 deletions hpccm/building_blocks/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from hpccm.building_blocks.base import bb_base
from hpccm.building_blocks.packages import packages
from hpccm.common import cpu_arch, linux_distro
from distutils.version import LooseVersion
from packaging.version import Version
from hpccm.primitives.comment import comment
from hpccm.primitives.shell import shell
from hpccm.primitives.environment import environment
Expand Down Expand Up @@ -122,7 +122,7 @@ def __setup(self):
if not self.__source and hpccm.config.g_cpu_arch == cpu_arch.X86_64:
# Use the pre-compiled x86_64 binary
self.__binary()
elif not self.__source and hpccm.config.g_cpu_arch == cpu_arch.AARCH64 and LooseVersion(self.__version) >= LooseVersion('3.20'):
elif not self.__source and hpccm.config.g_cpu_arch == cpu_arch.AARCH64 and Version(self.__version) >= Version('3.20'):
# Use the pre-compiled aarch64 binary
self.__binary()
else:
Expand All @@ -135,11 +135,11 @@ def __binary(self):
runfile = 'cmake-{}-linux-x86_64.sh'
if hpccm.config.g_cpu_arch == cpu_arch.AARCH64:
runfile = 'cmake-{}-linux-aarch64.sh'
elif hpccm.config.g_cpu_arch == cpu_arch.X86_64 and LooseVersion(self.__version) < LooseVersion('3.20'):
elif hpccm.config.g_cpu_arch == cpu_arch.X86_64 and Version(self.__version) < Version('3.20'):
runfile = 'cmake-{}-Linux-x86_64.sh'

runfile = runfile.format(self.__version)
if LooseVersion(self.__version) < LooseVersion('3.1'):
if Version(self.__version) < Version('3.1'):
runfile = 'cmake-{}-Linux-i386.sh'.format(self.__version)
# CMake releases of versions < 3.1 are only include 32-bit
# binaries:
Expand Down
4 changes: 2 additions & 2 deletions hpccm/building_blocks/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import LooseVersion
from packaging.version import Version
import logging
import posixpath

Expand Down Expand Up @@ -152,7 +152,7 @@ def __setup(self):
"""Construct the series of shell commands, i.e., fill in
self.__commands"""

if LooseVersion(self.__version) >= LooseVersion('4.8'):
if Version(self.__version) >= Version('4.8'):
miniconda = 'Miniconda{0}-{1}_{2}-Linux-{3}.sh'.format(
self.__python_version, self.__python_subversion,
self.__version, self.__arch_pkg)
Expand Down
4 changes: 2 additions & 2 deletions hpccm/building_blocks/gdrcopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import posixpath
from six.moves import shlex_quote
from distutils.version import LooseVersion
from packaging.version import Version

import hpccm.templates.envvars
import hpccm.templates.ldconfig
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, **kwargs):
make_opts['COMMONCFLAGS'] = make_opts.pop('CFLAGS')

# Version 2.2 changed the flag to lowercase prefix and the lib directory
if LooseVersion(self.__version) >= LooseVersion('2.2'):
if Version(self.__version) >= Version('2.2'):
make_opts['prefix'] = self.__prefix
libdir = 'lib'
else:
Expand Down
12 changes: 6 additions & 6 deletions hpccm/building_blocks/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import StrictVersion
from packaging.version import Version
import posixpath

import hpccm.config
Expand Down Expand Up @@ -345,11 +345,11 @@ def __distro(self):
# Set libfortran version depending on the Ubuntu version
if self.__fortran:
if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
if hpccm.config.g_linux_version >= StrictVersion('20.0'):
if hpccm.config.g_linux_version >= Version('20.0'):
self.__runtime_debs.append('libgfortran5')
elif hpccm.config.g_linux_version >= StrictVersion('18.0'):
elif hpccm.config.g_linux_version >= Version('18.0'):
self.__runtime_debs.append('libgfortran4')
elif hpccm.config.g_linux_version >= StrictVersion('16.0'):
elif hpccm.config.g_linux_version >= Version('16.0'):
self.__runtime_debs.append('libgfortran3')
else: # pragma: no cover
raise RuntimeError('Unrecognized Ubuntu version')
Expand All @@ -374,7 +374,7 @@ def __distro(self):
# Default for CentOS 7
toolset_path = '/opt/rh/devtoolset-{}/root/usr/bin'.format(
self.__version)
if hpccm.config.g_linux_version >= StrictVersion('8.0'):
if hpccm.config.g_linux_version >= Version('8.0'):
# CentOS 8
toolset_path = '/opt/rh/gcc-toolset-{}/root/usr/bin'.format(self.__version)

Expand Down Expand Up @@ -447,7 +447,7 @@ def __repository(self):
'{0}-{1}'.format(x, self.__version)
for x in self.__compiler_debs]

if hpccm.config.g_linux_version >= StrictVersion('8.0'):
if hpccm.config.g_linux_version >= Version('8.0'):
# CentOS 8
self.__compiler_rpms = [
'gcc-toolset-{1}-{0}'.format(x, self.__version)
Expand Down
36 changes: 18 additions & 18 deletions hpccm/building_blocks/hpcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import StrictVersion
from packaging.version import Version
import posixpath
import re

Expand Down Expand Up @@ -152,25 +152,25 @@ def __init__(self, **kwargs):
self.__wd = kwargs.get('wd', hpccm.config.g_wd) # working directory

if not self.__buildlabel:
if StrictVersion(self.__version) >= StrictVersion('2.16'):
if Version(self.__version) >= Version('2.16'):
self.__buildlabel = 'cuda12-gdrcopy2-nccl2.18'
elif StrictVersion(self.__version) >= StrictVersion('2.15'):
elif Version(self.__version) >= Version('2.15'):
self.__buildlabel = 'cuda12-gdrcopy2-nccl2.17'
elif StrictVersion(self.__version) >= StrictVersion('2.14'):
elif Version(self.__version) >= Version('2.14'):
self.__buildlabel = 'cuda11-gdrcopy2-nccl2.16'
elif StrictVersion(self.__version) >= StrictVersion('2.12'):
elif Version(self.__version) >= Version('2.12'):
self.__buildlabel = 'cuda11-gdrcopy2-nccl2.12'
elif StrictVersion(self.__version) >= StrictVersion('2.10'):
elif Version(self.__version) >= Version('2.10'):
self.__buildlabel = 'cuda11-gdrcopy2-nccl2.11'

if not self.__mlnx_ofed:
if StrictVersion(self.__version) >= StrictVersion('2.10'):
if Version(self.__version) >= Version('2.10'):
self.__mlnx_ofed = '5'
else:
self.__mlnx_ofed = '5.2-2.2.0.0'

if not self.__ofedlabel:
if StrictVersion(self.__version) >= StrictVersion('2.16'):
if Version(self.__version) >= Version('2.16'):
self.__ofedlabel = 'gcc-mlnx_ofed'
else:
self.__ofedlabel = 'gcc-MLNX_OFED_LINUX-{}'.format(self.__mlnx_ofed)
Expand Down Expand Up @@ -202,11 +202,11 @@ def __distro(self):

if hpccm.config.g_linux_distro == linux_distro.UBUNTU:
if not self.__oslabel:
if hpccm.config.g_linux_version >= StrictVersion('22.0'):
if hpccm.config.g_linux_version >= Version('22.0'):
self.__oslabel = 'ubuntu22.04'
elif hpccm.config.g_linux_version >= StrictVersion('20.0'):
elif hpccm.config.g_linux_version >= Version('20.0'):
self.__oslabel = 'ubuntu20.04'
elif hpccm.config.g_linux_version >= StrictVersion('18.0'):
elif hpccm.config.g_linux_version >= Version('18.0'):
self.__oslabel = 'ubuntu18.04'
else:
self.__oslabel = 'ubuntu16.04'
Expand All @@ -218,13 +218,13 @@ def __distro(self):

elif hpccm.config.g_linux_distro == linux_distro.CENTOS:
if not self.__oslabel:
if hpccm.config.g_linux_version >= StrictVersion('8.0'):
if StrictVersion(self.__version) >= StrictVersion('2.10'):
if hpccm.config.g_linux_version >= Version('8.0'):
if Version(self.__version) >= Version('2.10'):
self.__oslabel = 'redhat8'
else:
self.__oslabel = 'redhat8.0'
else:
if StrictVersion(self.__version) >= StrictVersion('2.10'):
if Version(self.__version) >= Version('2.10'):
self.__oslabel = 'redhat7'
else:
self.__oslabel = 'redhat7.6'
Expand All @@ -246,15 +246,15 @@ def __setup(self):
# MAJOR.MINOR.REVISION, so pull apart the full version to get
# the individual components.
version_string = self.__version
if StrictVersion(self.__version) <= StrictVersion('2.8'):
if Version(self.__version) <= Version('2.8'):
match = re.match(r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)',
self.__version)
version_string = '{0}.{1}'.format(match.groupdict()['major'],
match.groupdict()['minor'])

if self.__inbox:
# Use inbox OFED
if StrictVersion(self.__version) >= StrictVersion('2.10'):
if Version(self.__version) >= Version('2.10'):
# Version 2.11 and later include an extra label
self.__label = 'hpcx-v{0}-gcc-inbox-{1}-{2}-{3}'.format(
self.__version, self.__oslabel, self.__buildlabel,
Expand All @@ -264,7 +264,7 @@ def __setup(self):
self.__version, self.__oslabel, self.__arch)
else:
# Use MLNX OFED
if StrictVersion(self.__version) >= StrictVersion('2.10'):
if Version(self.__version) >= Version('2.10'):
# Version 2.10 and later include an extra label
self.__label = 'hpcx-v{0}-{1}-{2}-{3}-{4}'.format(
self.__version, self.__ofedlabel, self.__oslabel, self.__buildlabel, self.__arch)
Expand Down Expand Up @@ -311,7 +311,7 @@ def __setup(self):
hpcx_mpi_dir = posixpath.join(hpcx_dir, 'ompi')
hpcx_oshmem_dir = hpcx_mpi_dir
hpcx_mpi_tests_dir = posixpath.join(hpcx_mpi_dir, 'tests')
if StrictVersion(self.__version) >= StrictVersion('2.7'):
if Version(self.__version) >= Version('2.7'):
hpcx_osu_dir = posixpath.join(hpcx_mpi_tests_dir,
'osu-micro-benchmarks-5.6.2')
hpcx_osu_cuda_dir = posixpath.join(
Expand Down
4 changes: 2 additions & 2 deletions hpccm/building_blocks/intel_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from __future__ import unicode_literals
from __future__ import print_function

from distutils.version import LooseVersion
from packaging.version import Version
import logging

import hpccm.config
Expand Down Expand Up @@ -143,7 +143,7 @@ def __instructions(self):
# subsequent build steps and when starting the container,
# but this may miss some things relative to the mpivars
# environment script.
if LooseVersion(self.__version) >= LooseVersion('2019.0'):
if Version(self.__version) >= Version('2019.0'):
self.environment_variables={
'FI_PROVIDER_PATH': '/opt/intel/compilers_and_libraries/linux/mpi/intel64/libfabric/lib/prov',
'I_MPI_ROOT': '/opt/intel/compilers_and_libraries/linux/mpi',
Expand Down
Loading

0 comments on commit 7e938aa

Please sign in to comment.