Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/src/sage_setup/command/sage_build_ext_minimal.py
4081 views
1
import os
2
import multiprocessing
3
from setuptools.command.build_ext import build_ext
4
5
6
class sage_build_ext_minimal(build_ext):
7
"""
8
In contrast to :func:`~sage_setup.sage_build_ext.sage_build_ext`, this build extension is designed
9
to be used in combination with Cython's cythonize function.
10
Thus, we only take care of some options and letting Cython do the main work.
11
"""
12
13
def initialize_options(self):
14
build_ext.initialize_options(self)
15
self.parallel = self.get_default_number_build_jobs()
16
17
@staticmethod
18
def get_default_number_build_jobs() -> int:
19
"""
20
Get number of parallel build jobs used by default, i.e. unless explicitly
21
set by the --parallel command line argument of setup.py.
22
23
First, the environment variable ``SAGE_NUM_THREADS`` is checked.
24
If that is unset, return the number of processors on the system,
25
with a maximum of 10 (to prevent overloading the system if there a lot of CPUs).
26
27
OUTPUT:
28
number of parallel jobs that should be run
29
"""
30
try:
31
cpu_count = len(os.sched_getaffinity(0))
32
except AttributeError:
33
cpu_count = multiprocessing.cpu_count()
34
cpu_count = min(cpu_count, 10)
35
return int(os.environ.get("SAGE_NUM_THREADS", cpu_count))
36
37