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

Commit d312143

Browse files
author
Release Manager
committed
Trac #30580: sage_setup: Remove import-time dependency (setup_requires) on pkgconfig, numpy
Just loading `src/setup.py` already pulls in Cython, `numpy`, and `pkgconfig` via `sage_setup`, so these distributions would have to be declared as `[build_system] requires` in `src/pyproject.toml` (ex `setup_requires`) By moving some computations from import-time to runtime, we get rid of this early dependency on `pkgconfig`, `numpy`. (They are, of course, still required for building the package.) This makes `setup.py sdist` work using a Python that does not have `numpy `or `pkgconfig` installed. To test (with a system python that has `Cython`): {{{ $ (cd build/pkgs/sagelib/src && python3 -u setup.py --no-user-cfg sdist) }}} (We also reduce the load-time dependency on Cython; however, we do not address the whole load-time dependency of `setup.py` on `Cython` (via `sage_setup.find`, which uses `open_source_file` and `is_package_dir`) in this ticket. This is best done after #28925.) URL: https://trac.sagemath.org/30580 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): Dima Pasechnik
2 parents 52b91c8 + 8f04684 commit d312143

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

build/pkgs/sagelib/src/setup.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,20 @@
5757
print("Discovering Python/Cython source code....")
5858
t = time.time()
5959

60-
distributions = ['']
61-
6260
from sage_setup.optional_extension import is_package_installed_and_updated
6361

64-
optional_packages_with_extensions = ['mcqd', 'bliss', 'tdlib', 'primecount',
65-
'coxeter3', 'fes', 'sirocco', 'meataxe']
66-
67-
distributions += ['sage-{}'.format(pkg)
68-
for pkg in optional_packages_with_extensions
69-
if is_package_installed_and_updated(pkg)]
70-
71-
log.warn('distributions = {0}'.format(distributions))
62+
if sdist:
63+
# No need to compute distributions. This avoids a dependency on Cython
64+
# just to make an sdist.
65+
distributions = None
66+
else:
67+
distributions = ['']
68+
optional_packages_with_extensions = ['mcqd', 'bliss', 'tdlib', 'primecount',
69+
'coxeter3', 'fes', 'sirocco', 'meataxe']
70+
distributions += ['sage-{}'.format(pkg)
71+
for pkg in optional_packages_with_extensions
72+
if is_package_installed_and_updated(pkg)]
73+
log.warn('distributions = {0}'.format(distributions))
7274

7375
from sage_setup.find import find_python_sources
7476
python_packages, python_modules, cython_modules = find_python_sources(

src/sage_setup/command/sage_build_cython.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
from distutils.errors import (DistutilsModuleError,
1414
DistutilsOptionError)
1515

16-
from Cython.Build.Dependencies import default_create_extension
1716
from sage_setup.util import stable_uniq
1817
from sage_setup.find import find_extra_files
19-
from sage_setup.library_order import library_order
2018
from sage_setup.cython_options import compiler_directives, compile_time_env_variables
2119

22-
from sage.env import (cython_aliases, sage_include_directories)
23-
2420
# Do not put all, but only the most common libraries and their headers
2521
# (that are likely to change on an upgrade) here:
2622
# [At least at the moment. Make sure the headers aren't copied with "-p",
@@ -58,13 +54,6 @@
5854
if subprocess.call("""$CC --version | grep -i 'gcc.* 4[.]8' >/dev/null """, shell=True) == 0:
5955
extra_compile_args.append('-fno-tree-copyrename')
6056

61-
# Search for dependencies in the source tree and add to the list of include directories
62-
include_dirs = sage_include_directories(use_sources=True)
63-
64-
# Look for libraries only in what is configured already through distutils
65-
# and environment variables
66-
library_dirs = []
67-
6857
class sage_build_cython(Command):
6958
name = 'build_cython'
7059
description = "compile Cython extensions into C/C++ extensions"
@@ -211,6 +200,13 @@ def run(self):
211200
Call ``cythonize()`` to replace the ``ext_modules`` with the
212201
extensions containing Cython-generated C code.
213202
"""
203+
from sage.env import (cython_aliases, sage_include_directories)
204+
# Set variables used in self.create_extension
205+
from ..library_order import library_order
206+
self.library_order = library_order
207+
# Search for dependencies in the source tree and add to the list of include directories
208+
self.sage_include_dirs = sage_include_directories(use_sources=True)
209+
214210
from Cython.Build import cythonize
215211
import Cython.Compiler.Options
216212

@@ -281,7 +277,7 @@ def create_extension(self, template, kwds):
281277
# Libraries: sort them
282278
libs = kwds.get('libraries', [])
283279
kwds['libraries'] = sorted(set(libs),
284-
key=lambda lib: library_order.get(lib, 0))
280+
key=lambda lib: self.library_order.get(lib, 0))
285281

286282
# Dependencies: add setup.py and lib_headers
287283
depends = kwds.get('depends', []) + [self.distribution.script_name]
@@ -322,11 +318,13 @@ def create_extension(self, template, kwds):
322318
kwds['extra_link_args'] = stable_uniq(ldflags)
323319

324320
# Process library_dirs
325-
lib_dirs = kwds.get('library_dirs', []) + library_dirs
321+
lib_dirs = kwds.get('library_dirs', [])
326322
kwds['library_dirs'] = stable_uniq(lib_dirs)
327323

328324
# Process include_dirs
329-
inc_dirs = kwds.get('include_dirs', []) + include_dirs + [self.build_dir]
325+
inc_dirs = kwds.get('include_dirs', []) + self.sage_include_dirs + [self.build_dir]
330326
kwds['include_dirs'] = stable_uniq(inc_dirs)
331327

328+
from Cython.Build.Dependencies import default_create_extension
329+
332330
return default_create_extension(template, kwds)

0 commit comments

Comments
 (0)