Skip to content

Commit

Permalink
Trac #33295: Refactor sage_conf
Browse files Browse the repository at this point in the history
(split out from #31396)

We refactor `sage_conf` to make it easier to maintain variants of it,
both the 2 in-tree variants (and another one to be added in #31396) and
downstream variants:'''
- The `configure`-generated configuration file is now `pkgs/sage-
conf/_sage_conf/_conf.py`
- The file `pkgs/sage-conf/sage_conf.py` is now static

URL: https://trac.sagemath.org/33295
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): François Bissey
  • Loading branch information
Release Manager committed Jul 8, 2022
2 parents 662aaf2 + eeddb03 commit 80d2ee6
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sageruntime: base-toolchain

# CONFIG_FILES lists all files that appear in AC_CONFIG_FILES in configure.ac;
# except for build/make/Makefile-auto, which is unused by the build system
CONFIG_FILES = build/make/Makefile src/bin/sage-env-config build/bin/sage-build-env-config pkgs/sage-conf/sage_conf.py pkgs/sage-conf/setup.cfg
CONFIG_FILES = build/make/Makefile src/bin/sage-env-config build/bin/sage-build-env-config pkgs/sage-conf/_sage_conf/_conf.py

# SPKG_COLLECT_FILES contains all files that influence the SAGE_SPKG_COLLECT macro
SPKG_COLLECT_FILES = build/pkgs/*/type build/pkgs/*/package-version.txt build/pkgs/*/dependencies build/pkgs/*/requirements.txt build/pkgs/*/checksums.ini build/pkgs/*/spkg-install
Expand Down
2 changes: 1 addition & 1 deletion build/pkgs/sage_conf/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$(PYTHON) $(SAGE_ROOT)/pkgs/sage-conf/sage_conf.py $(SAGE_ROOT)/pkgs/sage-conf/setup.cfg $(SAGE_ROOT)/pkgs/sage-conf/bin/sage-env-config | $(PYTHON_TOOLCHAIN)
$(PYTHON) $(SAGE_ROOT)/pkgs/sage-conf/_sage_conf/_conf.py $(SAGE_ROOT)/pkgs/sage-conf/setup.cfg $(SAGE_ROOT)/pkgs/sage-conf/bin/sage-env-config | $(PYTHON_TOOLCHAIN)
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ dnl AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([build/make/Makefile-auto build/make/Makefile])
AC_CONFIG_FILES([src/bin/sage-env-config src/bin/sage-src-env-config build/bin/sage-build-env-config])

AC_CONFIG_FILES([pkgs/sage-conf/sage_conf.py pkgs/sage-conf/setup.cfg])
AC_CONFIG_FILES([pkgs/sage-conf/_sage_conf/_conf.py])

dnl Create basic directories needed for Sage
AC_CONFIG_COMMANDS(mkdirs,
Expand Down
4 changes: 3 additions & 1 deletion pkgs/sage-conf/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/sage_conf.py
/_sage_conf/_conf.py
/setup.cfg
/build
/dist
/*.egg-info
/.tox
22 changes: 22 additions & 0 deletions pkgs/sage-conf/_sage_conf/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Entry point 'sage-config'. It does not depend on any packages.

from sage_conf import *

def _main():
from argparse import ArgumentParser
from sys import exit, stdout
parser = ArgumentParser()
parser.add_argument('--version', help="show version", action="version",
version='%(prog)s ' + VERSION)
parser.add_argument("VARIABLE", nargs='?', help="output the value of VARIABLE")
args = parser.parse_args()
d = globals()
if args.VARIABLE:
stdout.write('{}\n'.format(d[args.VARIABLE]))
else:
for k, v in d.items():
if not k.startswith('_'):
stdout.write('{}={}\n'.format(k, v))

if __name__ == "__main__":
_main()
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,9 @@ THREEJS_DIR = SAGE_LOCAL + "/share/threejs-sage"
OPENMP_CFLAGS = "@OPENMP_CFLAGS@"
OPENMP_CXXFLAGS = "@OPENMP_CXXFLAGS@"

# Singular executable
SINGULAR_BIN = "@SINGULAR_BIN@"

# The full absolute path to the main Singular library.
LIBSINGULAR_PATH = "@LIBSINGULAR_PATH@".replace('$SAGE_LOCAL', SAGE_LOCAL)

# Installation location of wheels. This is determined at configuration time
# and does not depend on the installation location of sage-conf.
SAGE_SPKG_WHEELS = "@SAGE_VENV@".replace('${SAGE_LOCAL}', SAGE_LOCAL) + "/var/lib/sage/wheels"


# Entry point 'sage-config'. It does not depend on any packages.

def _main():
from argparse import ArgumentParser
from sys import exit, stdout
parser = ArgumentParser()
parser.add_argument('--version', help="show version", action="version",
version='%(prog)s ' + VERSION)
parser.add_argument("VARIABLE", nargs='?', help="output the value of VARIABLE")
args = parser.parse_args()
d = globals()
if args.VARIABLE:
stdout.write('{}\n'.format(d[args.VARIABLE]))
else:
for k, v in d.items():
if not k.startswith('_'):
stdout.write('{}={}\n'.format(k, v))

if __name__ == "__main__":
_main()
2 changes: 2 additions & 0 deletions pkgs/sage-conf/sage_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from _sage_conf._conf import *
from _sage_conf.__main__ import _main
7 changes: 4 additions & 3 deletions pkgs/sage-conf/setup.cfg.in → pkgs/sage-conf/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# @configure_input@

[metadata]
name = sage-conf
version = @PACKAGE_VERSION@
version = file: VERSION.txt
description = Sage: Open Source Mathematics Software: Configuration module for the SageMath library
long_description = file: README.rst
license = GNU General Public License (GPL) v3 or later
Expand All @@ -11,6 +9,9 @@ author_email = sage-support@googlegroups.com
url = https://www.sagemath.org

[options]
packages =
_sage_conf

py_modules =
sage_conf

Expand Down
3 changes: 2 additions & 1 deletion pkgs/sage-conf_pypi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/sage_conf.py
/_sage_conf/_conf.py
/build
/dist
/*.egg-info
/.tox
/bin/sage-env-config
5 changes: 3 additions & 2 deletions pkgs/sage-conf_pypi/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ graft sage_root/pkgs/sage-docbuild
prune sage_root/pkgs/sage-docbuild/build
prune sage_root/pkgs/sage-docbuild/*.egg-info
# Exclude files generated by config.status (AC_CONFIG_FILES)
exclude sage_root/pkgs/sage-conf/sage_conf.py
exclude sage_root/pkgs/sage-conf/setup.cfg
exclude _sage_conf/_conf.py
exclude sage_root/pkgs/sage-conf/_sage_conf/_conf.py
exclude bin/sage-env-config
exclude sage_root/pkgs/sage-conf/bin/sage-env-config
exclude sage_root/build/bin/sage-build-env-config
exclude sage_root/build/make/Makefile-auto
Expand Down
1 change: 1 addition & 0 deletions pkgs/sage-conf_pypi/_sage_conf
1 change: 1 addition & 0 deletions pkgs/sage-conf_pypi/sage_conf.py
1 change: 0 additions & 1 deletion pkgs/sage-conf_pypi/sage_conf.py.in

This file was deleted.

16 changes: 0 additions & 16 deletions pkgs/sage-conf_pypi/setup.cfg

This file was deleted.

1 change: 1 addition & 0 deletions pkgs/sage-conf_pypi/setup.cfg
10 changes: 2 additions & 8 deletions pkgs/sage-conf_pypi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ def run(self):
raise DistutilsSetupError(f"make {TARGETS} failed")

# Install configuration
shutil.copyfile(os.path.join(SAGE_ROOT, 'pkgs', 'sage-conf', '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, 'pkgs', 'sage-conf', '_sage_conf', '_conf.py'),
os.path.join(HERE, '_sage_conf', '_conf.py'))
shutil.copyfile(os.path.join(SAGE_ROOT, 'src', 'bin', 'sage-env-config'),
os.path.join(HERE, 'bin', 'sage-env-config'))
setuptools_build_py.run(self)
Expand All @@ -77,9 +74,6 @@ def run(self):
self.distribution.scripts.append(os.path.join('bin', 'sage-env-config'))
if not self.distribution.entry_points:
self.entry_points = self.distribution.entry_points = dict()
if 'console_scripts' not in self.distribution.entry_points:
self.distribution.entry_points['console_scripts'] = []
self.distribution.entry_points['console_scripts'].append('sage-config=sage_conf:_main')
distutils_build_scripts.run(self)

setup(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sage-env-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# or build/bin/sage-build-env instead.
# - Configuration variables that are only needed by the Sage runtime,
# but not as environment variables, should instead be set in
# pkgs/sage-conf/sage_conf.py
# pkgs/sage-conf/_sage_conf/_conf.py
#
##########################################################################

Expand Down
2 changes: 1 addition & 1 deletion src/bin/sage-src-env-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# instead.
# - Configuration variables that are only needed by the Sage runtime,
# but not as environment variables, should instead be set in
# build/pkgs/sage_conf/src/sage_conf.py
# pkgs/sage-conf/_sage_conf/_conf.py
#
##########################################################################

Expand Down

0 comments on commit 80d2ee6

Please sign in to comment.