Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit c462eeb

Browse files
author
Release Manager
committed
Trac #30984: sage_setup: Replace imports from distutils by setuptools
... in anticipation of the `distutils` deprecation (https://www.python.org/dev/peps/pep-0632/) From https://setuptools.readthedocs.io/en/latest/deprecated/distutils- legacy.html - `distutils.core.setup` → `setuptools.setup` - `distutils.cmd.Command` → `setuptools.Command` - `distutils.log` → `(no replacement yet)` - `distutils.version.*` → `packaging.version.*` "If a project relies on uses of distutils that do not have a suitable replacement above, please search the Setuptools issue tracker and file a request, describing the use-case so that Setuptools’ maintainers can investigate." Part of #31295 (Meta-ticket: Replace imports from deprecated distutils) URL: https://trac.sagemath.org/30984 Reported by: mkoeppe Ticket author(s): Frédéric Chapoton, Matthias Koeppe Reviewer(s): Matthias Koeppe, John Palmieri
2 parents f0ab074 + 25b877c commit c462eeb

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

src/sage_setup/command/sage_build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Import setuptools before importing distutils, so that setuptools
2+
# can replace distutils by its own vendored copy.
3+
import setuptools
4+
15
from distutils import log
26
from distutils.command.build import build
37

src/sage_setup/command/sage_build_cython.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import sys
99
import time
1010
import json
11+
12+
# Import setuptools before importing distutils, so that setuptools
13+
# can replace distutils by its own vendored copy.
14+
import setuptools
15+
1116
from distutils import log
12-
from distutils.cmd import Command
13-
from distutils.errors import (DistutilsModuleError,
14-
DistutilsOptionError)
17+
from setuptools import Command
1518

1619
from sage_setup.util import stable_uniq
1720
from sage_setup.find import find_extra_files
@@ -130,12 +133,12 @@ def finalize_options(self):
130133
try:
131134
self.parallel = int(self.parallel)
132135
except ValueError:
133-
raise DistutilsOptionError("parallel should be an integer")
136+
raise ValueError("parallel should be an integer")
134137

135138
try:
136139
import Cython
137140
except ImportError:
138-
raise DistutilsModuleError(
141+
raise ImportError(
139142
"Cython must be installed and importable in order to run "
140143
"the cythonize command")
141144

src/sage_setup/command/sage_build_ext.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import os
22
import errno
3+
4+
# Import setuptools before importing distutils, so that setuptools
5+
# can replace distutils by its own vendored copy.
6+
import setuptools
7+
38
from distutils import log
4-
from distutils.command.build_ext import build_ext
9+
from setuptools.command.build_ext import build_ext
510
from distutils.dep_util import newer_group
611
from distutils.errors import DistutilsSetupError
712
from sage_setup.run_parallel import execute_list_of_commands

src/sage_setup/command/sage_install.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import os
66
import time
7+
8+
# Import setuptools before importing distutils, so that setuptools
9+
# can replace distutils by its own vendored copy.
10+
import setuptools
11+
712
from distutils import log
813
from distutils.command.install import install
914

src/sage_setup/find.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
"""
22
Recursive Directory Contents
33
"""
4-
#*****************************************************************************
4+
# ****************************************************************************
55
# Copyright (C) 2014 Volker Braun <[email protected]>
66
#
77
# This program is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
99
# the Free Software Foundation, either version 2 of the License, or
1010
# (at your option) any later version.
1111
# http://www.gnu.org/licenses/
12-
#*****************************************************************************
13-
12+
# ****************************************************************************
1413

1514
import importlib.machinery
1615
import importlib.util
@@ -19,6 +18,7 @@
1918

2019
from collections import defaultdict
2120

21+
2222
def read_distribution(src_file):
2323
"""
2424
Parse ``src_file`` for a ``# sage_setup: distribution = PKG`` directive.
@@ -58,6 +58,7 @@ def read_distribution(src_file):
5858
return value
5959
return ''
6060

61+
6162
def find_python_sources(src_dir, modules=['sage'], distributions=None):
6263
"""
6364
Find all Python packages and Python/Cython modules in the sources.
@@ -115,7 +116,7 @@ def find_python_sources(src_dir, modules=['sage'], distributions=None):
115116
Filtering by distribution (distutils package)::
116117
117118
sage: find_python_sources(SAGE_SRC, distributions=['sage-tdlib'])
118-
([], [], [<distutils.extension.Extension('sage.graphs.graph_decompositions.tdlib')...>])
119+
([], [], [<setuptools.extension.Extension('sage.graphs.graph_decompositions.tdlib')...>])
119120
120121
Benchmarking::
121122
@@ -130,7 +131,7 @@ def find_python_sources(src_dir, modules=['sage'], distributions=None):
130131
sage: find_python_sources(SAGE_SRC, modules=['sage_setup'])
131132
(['sage_setup', ...], [...'sage_setup.find'...], [])
132133
"""
133-
from distutils.extension import Extension
134+
from setuptools import Extension
134135

135136
PYMOD_EXT = get_extensions('source')[0]
136137
INIT_FILE = '__init__' + PYMOD_EXT
@@ -172,6 +173,7 @@ def is_in_distributions(filename):
172173
os.chdir(cwd)
173174
return python_packages, python_modules, cython_modules
174175

176+
175177
def find_extra_files(src_dir, modules, cythonized_dir, special_filenames=[]):
176178
"""
177179
Find all extra files which should be installed.

src/sage_setup/optional_extension.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
package which must be installed.
88
"""
99

10-
#*****************************************************************************
10+
# ****************************************************************************
1111
# Copyright (C) 2015 Jeroen Demeyer <[email protected]>
1212
#
1313
# This program is free software: you can redistribute it and/or modify
1414
# it under the terms of the GNU General Public License as published by
1515
# the Free Software Foundation, either version 2 of the License, or
1616
# (at your option) any later version.
17-
# http://www.gnu.org/licenses/
18-
#*****************************************************************************
17+
# https://www.gnu.org/licenses/
18+
# ****************************************************************************
1919

20-
21-
from distutils.extension import Extension
20+
from setuptools.extension import Extension
2221
from sage.misc.package import list_packages
2322

2423
all_packages = list_packages(local=True)
@@ -40,6 +39,7 @@ class CythonizeExtension(Extension):
4039
"""
4140
skip_build = True
4241

42+
4343
def is_package_installed_and_updated(pkg):
4444
from sage.misc.package import is_package_installed
4545
try:
@@ -51,6 +51,7 @@ def is_package_installed_and_updated(pkg):
5151
condition = (pkginfo["installed_version"] == pkginfo["remote_version"])
5252
return condition
5353

54+
5455
def OptionalExtension(*args, **kwds):
5556
"""
5657
If some condition (see INPUT) is satisfied, return an ``Extension``.

0 commit comments

Comments
 (0)