10
10
from setuptools import setup
11
11
from distutils .command .build_scripts import build_scripts as distutils_build_scripts
12
12
from setuptools .command .build_py import build_py as setuptools_build_py
13
- from setuptools .command .egg_info import egg_info as setuptools_egg_info
14
- from distutils .errors import (DistutilsSetupError , DistutilsModuleError ,
15
- DistutilsOptionError )
13
+ from setuptools .errors import SetupError
14
+
16
15
17
16
class build_py (setuptools_build_py ):
18
17
19
18
def run (self ):
20
- DOT_SAGE = os . environ . get ( 'DOT_SAGE' , os . path . join ( os . environ . get ( 'HOME' ), '.sage' ))
19
+
21
20
HERE = os .path .dirname (__file__ )
21
+ if self .editable_mode :
22
+ SAGE_ROOT = os .path .join (HERE , 'sage_root' )
23
+ else :
24
+ SAGE_ROOT = self ._create_writable_sage_root ()
25
+
26
+ if os .path .exists (os .path .join (SAGE_ROOT , 'config.status' )):
27
+ print (f'Reusing configured SAGE_ROOT={ SAGE_ROOT } ' )
28
+ else :
29
+ cmd = f"cd { SAGE_ROOT } && ./configure --enable-build-as-root --with-system-python3=force --disable-notebook --disable-sagelib --disable-sage_conf --disable-doc"
30
+ cmd += ' --with-python=$CONDA_PREFIX/bin/python --prefix="$CONDA_PREFIX" --enable-system-site-packages'
31
+ cmd += ' $(for pkg in $(PATH="build/bin:$PATH" build/bin/sage-package list :standard: --exclude rpy2 --has-file spkg-configure.m4 --has-file distros/conda.txt); do echo --with-system-$pkg=force; done)'
32
+ print (f"Running { cmd } " )
33
+ sys .stdout .flush ()
34
+ if os .system (cmd ) != 0 :
35
+ if os .path .exists (os .path .join (SAGE_ROOT , 'config.status' )):
36
+ print ("Warning: A configuration has been written, but the configure script has exited with an error. "
37
+ "Carefully check any error messages before continuing." )
38
+ else :
39
+ print (f"Error: The configure script has failed; this may be caused by missing build prerequisites." )
40
+ sys .stdout .flush ()
41
+ PREREQ_SPKG = "_prereq bzip2 xz libffi" # includes python3 SPKG_DEPCHECK packages
42
+ os .system (f'cd { SAGE_ROOT } && export SYSTEM=$(build/bin/sage-guess-package-system 2>/dev/null) && export PACKAGES="$(build/bin/sage-get-system-packages $SYSTEM { PREREQ_SPKG } )" && [ -n "$PACKAGES" ] && echo "You can install the required build prerequisites using the following shell command" && echo "" && build/bin/sage-print-system-package-command $SYSTEM --verbose --sudo install $PACKAGES && echo ""' )
43
+ raise SetupError ("configure failed" )
44
+
45
+ # In this mode, we never run "make".
46
+
47
+ if not self .editable_mode :
48
+ # Install configuration
49
+ shutil .copyfile (os .path .join (SAGE_ROOT , 'pkgs' , 'sage-conf' , '_sage_conf' , '_conf.py' ),
50
+ os .path .join (HERE , '_sage_conf' , '_conf.py' ))
51
+ shutil .copyfile (os .path .join (SAGE_ROOT , 'src' , 'bin' , 'sage-env-config' ),
52
+ os .path .join (HERE , 'bin' , 'sage-env-config' ))
53
+
54
+ setuptools_build_py .run (self )
55
+
56
+ def _create_writable_sage_root (self ):
57
+ DOT_SAGE = os .environ .get ('DOT_SAGE' , os .path .join (os .environ .get ('HOME' ), '.sage' ))
22
58
with open (os .path .join (HERE , 'VERSION.txt' )) as f :
23
59
sage_version = f .read ().strip ()
24
60
# After #30534, SAGE_LOCAL no longer contains any Python. So we key the SAGE_ROOT only to Sage version
25
61
# and architecture.
26
62
system = platform .system ()
27
63
machine = platform .machine ()
28
64
arch_tag = f'{ system } -{ machine } '
29
- # TODO: These two should be user-configurable with options passed to "setup.py install"
65
+ # TODO: Should be user-configurable with config settings
30
66
SAGE_ROOT = os .path .join (DOT_SAGE , f'sage-{ sage_version } -{ arch_tag } -conda' )
31
67
32
68
def ignore (path , names ):
@@ -35,38 +71,20 @@ def ignore(path, names):
35
71
return ['src' ]
36
72
### ignore more stuff --- .tox etc.
37
73
return [name for name in names
38
- if name in ('.tox' ,)]
74
+ if name in ('.tox' , '.git' , '__pycache__' )]
39
75
40
- if os .path .exists (os .path .join (SAGE_ROOT , 'config.status' )):
41
- print (f'Reusing SAGE_ROOT={ SAGE_ROOT } ' )
42
- else :
76
+ if not os .path .exists (os .path .join (SAGE_ROOT , 'config.status' )):
43
77
# config.status and other configure output has to be writable.
44
78
# So (until the Sage distribution supports VPATH builds - #21469), we have to make a copy of sage_root.
45
79
try :
46
80
shutil .copytree ('sage_root' , SAGE_ROOT ,
47
81
ignore = ignore ) # will fail if already exists
48
82
except Exception as e :
49
- raise DistutilsSetupError (f"the directory SAGE_ROOT={ SAGE_ROOT } already exists but it is not configured. Please remove it and try again. (Exception: { e } )" )
50
- cmd = f"cd { SAGE_ROOT } && ./configure --enable-build-as-root --with-system-python3=force --disable-notebook --disable-sagelib --disable-sage_conf --disable-doc"
51
- cmd += ' --with-python=$CONDA_PREFIX/bin/python --prefix="$CONDA_PREFIX" --enable-system-site-packages'
52
- cmd += ' $(for pkg in $(build/bin/sage-package list :standard: --exclude rpy2 --has-file spkg-configure.m4 --has-file distros/conda.txt); do echo --with-system-$pkg=force; done)'
53
- print (f"Running { cmd } " )
54
- sys .stdout .flush ()
55
- if os .system (cmd ) != 0 :
56
- print (f"configure failed; this may be caused by missing build prerequisites." )
57
- sys .stdout .flush ()
58
- PREREQ_SPKG = "_prereq bzip2 xz libffi" # includes python3 SPKG_DEPCHECK packages
59
- os .system (f'cd { SAGE_ROOT } && export SYSTEM=$(build/bin/sage-guess-package-system 2>/dev/null) && export PACKAGES="$(build/bin/sage-get-system-packages $SYSTEM { PREREQ_SPKG } )" && [ -n "$PACKAGES" ] && echo "You can install the required build prerequisites using the following shell command" && echo "" && build/bin/sage-print-system-package-command $SYSTEM --verbose --sudo install $PACKAGES && echo ""' )
60
- raise DistutilsSetupError ("configure failed" )
83
+ raise SetupError (f"the directory SAGE_ROOT={ SAGE_ROOT } already exists but it is not configured ({ e } ). "
84
+ "Please either remove it and try again, or install in editable mode (pip install -e)." )
61
85
62
- # In this mode, we never run "make".
86
+ return SAGE_ROOT
63
87
64
- # Install configuration
65
- shutil .copyfile (os .path .join (SAGE_ROOT , 'pkgs' , 'sage-conf' , '_sage_conf' , '_conf.py' ),
66
- os .path .join (HERE , '_sage_conf' , '_conf.py' ))
67
- shutil .copyfile (os .path .join (SAGE_ROOT , 'src' , 'bin' , 'sage-env-config' ),
68
- os .path .join (HERE , 'bin' , 'sage-env-config' ))
69
- setuptools_build_py .run (self )
70
88
71
89
class build_scripts (distutils_build_scripts ):
72
90
@@ -76,6 +94,7 @@ def run(self):
76
94
self .entry_points = self .distribution .entry_points = dict ()
77
95
distutils_build_scripts .run (self )
78
96
97
+
79
98
setup (
80
99
cmdclass = dict (build_py = build_py , build_scripts = build_scripts )
81
100
)
0 commit comments