Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Determine SAGE_ROOT from sage version and python version
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Feb 14, 2021
1 parent ff7f110 commit 072b522
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/pkgs/sage_conf-pypi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,53 @@ class build_py(distutils_build_py):

def run(self):
DOT_SAGE = os.environ.get('DOT_SAGE', os.path.join(os.environ.get('HOME'), '.sage'))
# config.status and other configure output has to be writable.
SAGE_ROOT = os.path.join(DOT_SAGE, 'sage-{}-{}'.format(self.distribution.version,
sysconfig.get_config_var('SOABI')))
HERE = os.path.dirname(__file__)
with open(os.path.join(HERE, 'VERSION.txt')) as f:
sage_version = f.read().strip()
# Until pynac is repackaged as a pip-installable package (#30534), SAGE_LOCAL still has to be specific to
# the Python version. Note that as of pynac-0.7.26.sage-2020-04-03, on Cygwin, pynac is linked through
# to libpython; whereas on all other platforms, it is not linked through, so we only key it to the SOABI.
soabi = sysconfig.get_config_var('SOABI')
if sys.platform == 'cygwin':
libdir_tag = sysconfig.get_config_var('LIBDIR').replace(' ', '-').replace('\\', '-').replace('/', '-')
ldversion = sysconfig.get_config_var('LDVERSION')
python_tag = f'{libdir_tag}-{ldversion}'
else:
python_tag = soabi
# TODO: These two should be user-configurable with options passed to "setup.py install"
SAGE_ROOT = os.path.join(DOT_SAGE, f'sage-{sage_version}-{python_tag}')
SAGE_LOCAL = os.path.join(SAGE_ROOT, 'local')
if os.path.exists(os.path.join(SAGE_ROOT, 'config.status')):
print('Reusing {}'.format(SAGE_ROOT))
print('Reusing SAGE_ROOT={SAGE_ROOT}')
else:
# config.status and other configure output has to be writable.
# So (until the Sage distribution supports VPATH builds - #21469), we have to make a copy of sage_root.
try:
shutil.copytree('sage_root', SAGE_ROOT) # will fail if already exists
except Exception:
raise DistutilsSetupError("the directory SAGE_ROOT={} already exists but it is not configured. Please remove it and try again.".format(SAGE_ROOT))
cmd = "cd {} && ./configure --prefix={} --with-python={} --with-system-python3=force".format(SAGE_ROOT, SAGE_LOCAL, sys.executable)
print("Running {}".format(cmd))
raise DistutilsSetupError(f"the directory SAGE_ROOT={SAGE_ROOT} already exists but it is not configured. Please remove it and try again.")
cmd = f"cd {SAGE_ROOT} && ./configure --prefix={SAGE_LOCAL} --with-python={sys.executable} --with-system-python3=force"
print(f"Running {cmd}")
if os.system(cmd) != 0:
raise DistutilsSetupError("configure failed")

cmd = "cd {} && make V=0 build-local".format(SAGE_ROOT)
# build-local only builds the non-Python packages of the Sage distribution.
# It still makes an (empty) venv in SAGE_LOCAL, which is unused by default;
# but a user could use "make build-venv" to build compatible wheels for all Python packages.
# TODO: A target to only build wheels of tricky packages
# (that use native libraries shared with other packages).
cmd = f"cd {SAGE_ROOT} && make V=0 build-local"
if os.system(cmd) != 0:
raise DistutilsSetupError("make build-local failed")

# Install configuration
shutil.copyfile(os.path.join(SAGE_ROOT, 'build', 'pkgs', 'sage_conf', 'src', 'sage_conf.py'),
'sage_conf.py')
os.path.join(HERE, 'sage_conf.py'))
if not self.distribution.py_modules:
self.py_modules = self.distribution.py_modules = []
self.distribution.py_modules.append('sage_conf')
shutil.copyfile(os.path.join(SAGE_ROOT, 'src', 'bin', 'sage-env-config'),
os.path.join('bin', 'sage-env-config'))
os.path.join(HERE, 'bin', 'sage-env-config'))
distutils_build_py.run(self)

class build_scripts(distutils_build_scripts):
Expand Down

0 comments on commit 072b522

Please sign in to comment.