Path: blob/develop/src/sage_setup/command/sage_build_ext_minimal.py
4081 views
import os1import multiprocessing2from setuptools.command.build_ext import build_ext345class sage_build_ext_minimal(build_ext):6"""7In contrast to :func:`~sage_setup.sage_build_ext.sage_build_ext`, this build extension is designed8to be used in combination with Cython's cythonize function.9Thus, we only take care of some options and letting Cython do the main work.10"""1112def initialize_options(self):13build_ext.initialize_options(self)14self.parallel = self.get_default_number_build_jobs()1516@staticmethod17def get_default_number_build_jobs() -> int:18"""19Get number of parallel build jobs used by default, i.e. unless explicitly20set by the --parallel command line argument of setup.py.2122First, the environment variable ``SAGE_NUM_THREADS`` is checked.23If that is unset, return the number of processors on the system,24with a maximum of 10 (to prevent overloading the system if there a lot of CPUs).2526OUTPUT:27number of parallel jobs that should be run28"""29try:30cpu_count = len(os.sched_getaffinity(0))31except AttributeError:32cpu_count = multiprocessing.cpu_count()33cpu_count = min(cpu_count, 10)34return int(os.environ.get("SAGE_NUM_THREADS", cpu_count))353637