Skip to content

Commit 870ce5d

Browse files
author
Matthias Koeppe
committed
pkgs/sage-conf_conda/setup.py: In editable mode, do not make a copy of SAGE_ROOT
1 parent 944bc97 commit 870ce5d

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

pkgs/sage-conf_conda/setup.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,59 @@
1010
from setuptools import setup
1111
from distutils.command.build_scripts import build_scripts as distutils_build_scripts
1212
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+
1615

1716
class build_py(setuptools_build_py):
1817

1918
def run(self):
20-
DOT_SAGE = os.environ.get('DOT_SAGE', os.path.join(os.environ.get('HOME'), '.sage'))
19+
2120
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'))
2258
with open(os.path.join(HERE, 'VERSION.txt')) as f:
2359
sage_version = f.read().strip()
2460
# After #30534, SAGE_LOCAL no longer contains any Python. So we key the SAGE_ROOT only to Sage version
2561
# and architecture.
2662
system = platform.system()
2763
machine = platform.machine()
2864
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
3066
SAGE_ROOT = os.path.join(DOT_SAGE, f'sage-{sage_version}-{arch_tag}-conda')
3167

3268
def ignore(path, names):
@@ -35,38 +71,20 @@ def ignore(path, names):
3571
return ['src']
3672
### ignore more stuff --- .tox etc.
3773
return [name for name in names
38-
if name in ('.tox',)]
74+
if name in ('.tox', '.git', '__pycache__')]
3975

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')):
4377
# config.status and other configure output has to be writable.
4478
# So (until the Sage distribution supports VPATH builds - #21469), we have to make a copy of sage_root.
4579
try:
4680
shutil.copytree('sage_root', SAGE_ROOT,
4781
ignore=ignore) # will fail if already exists
4882
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).")
6185

62-
# In this mode, we never run "make".
86+
return SAGE_ROOT
6387

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)
7088

7189
class build_scripts(distutils_build_scripts):
7290

@@ -76,6 +94,7 @@ def run(self):
7694
self.entry_points = self.distribution.entry_points = dict()
7795
distutils_build_scripts.run(self)
7896

97+
7998
setup(
8099
cmdclass=dict(build_py=build_py, build_scripts=build_scripts)
81100
)

0 commit comments

Comments
 (0)