Skip to content

Commit

Permalink
build/pkgs/conda: New optional package
Browse files Browse the repository at this point in the history
src/bin/sage-env: Add the conda env to PATH if present

build/make/Makefile.in: Try to install script packages without spkg-install using mamba

build/make/Makefile.in, src/bin/sage-env: Activate the conda env for installing, remove user conda env vars

Switch from mamba-forge to micromamba

build/pkgs/conda/SPKG.rst: Update

Simplify placement of conda env

Update build/pkgs/conda/spkg-install

Co-authored-by: Isuru Fernando <isuruf@gmail.com>

src/bin/sage-env: Do not override conda env vars here; do that only in build/make/Makefile.in
  • Loading branch information
Matthias Koeppe committed Dec 8, 2023
1 parent d7bca05 commit a2da019
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 31 deletions.
21 changes: 12 additions & 9 deletions build/bin/sage-print-system-package-command
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ do
--quiet)
QUIET=yes
;;
--isolated)
ISOLATED=yes
;;
-*)
echo >&2 "$0: unknown option $1"
exit 1
Expand All @@ -67,12 +70,7 @@ if [ "$system" = auto ]; then
fi
fi
if [ "$SPKG" = "yes" ]; then
case $system in
mamba)
base_system=conda;;
*)
base_system=$system;;
esac
base_system=${system%%-*}
system_packages=$(echo $(sage-get-system-packages $base_system $*))
else
system_packages="$*"
Expand Down Expand Up @@ -149,15 +147,20 @@ case $system:$command in
opensuse*:install)
[ -n "$system_packages" ] && print_shell_command "${SUDO}zypper install $system_packages"
;;
*conda*:install)
conda-micromamba*:install)
[ "$YES" = yes ] && options="$options --yes"
[ -n "$system_packages" ] && print_shell_command "conda install $options $system_packages"
[ "$ISOLATED" = yes ] && options="$options --no-rc"
[ -n "$system_packages" ] && print_shell_command "micromamba install $options $system_packages"
;;
mamba*:install)
conda-mamba*:install)
[ "$YES" = yes ] && options="$options --yes"
[ "$QUIET" = yes ] && options="$options --no-banner"
[ -n "$system_packages" ] && print_shell_command "mamba install $options $system_packages"
;;
*conda*:install)
[ "$YES" = yes ] && options="$options --yes"
[ -n "$system_packages" ] && print_shell_command "conda install $options $system_packages"
;;
homebrew*:install)
[ -n "$system_packages" ] && print_shell_command "brew install $system_packages"
;;
Expand Down
31 changes: 23 additions & 8 deletions build/make/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -704,19 +704,30 @@ $(1)-$(4)-no-deps:
echo "Error: The installation tree $(4) has been disabled" 2>&1; \
echo "$$($(4)_DISABLED_MESSAGE)" 2>&1; \
exit 1; \
elif [ -x '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' ]; then \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
else \
cd '$$(SAGE_ROOT)/build/pkgs/$(1)' && \
. '$$(SAGE_ROOT)/src/bin/sage-src-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env-config' && \
. '$$(SAGE_ROOT)/src/bin/sage-env' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env-config' && \
. '$$(SAGE_ROOT)/build/bin/sage-build-env' && \
SAGE_SPKG_WHEELS=$$($(4))/var/lib/sage/wheels \
SAGE_INST_LOCAL=$$($(4)) \
sage-logger -p 'SAGE_CHECK=$$(SAGE_CHECK_$(1)) $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' '$$(SAGE_LOGS)/$(1)-$(2).log' && \
rm -f "$$($(4))/$(SPKG_INST_RELDIR)/$(1)"-* && \
touch "$$($(4))/$(SPKG_INST_RELDIR)/$(1)-$(2)"; \
else ( \
if [ -x '$$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' ]; then \
SAGE_SPKG_WHEELS=$$($(4))/var/lib/sage/wheels \
SAGE_INST_LOCAL=$$($(4)) \
sage-logger -p 'SAGE_CHECK=$$(SAGE_CHECK_$(1)) $$(SAGE_ROOT)/build/pkgs/$(1)/spkg-install' '$$(SAGE_LOGS)/$(1)-$(2).log' || exit 1; \
else \
INSTALL_COMMAND=$$$$(sage-print-system-package-command conda-micromamba --yes --quiet --spkg install $(1)); \
if [ -n "$$$$INSTALL_COMMAND" ]; then \
if [ -d "$$$$SAGE_CONDA_PREFIX" ]; then \
export MAMBA_ROOT_PREFIX="$$$$SAGE_CONDA_PREFIX"; \
export CONDA_PREFIX="$$$$SAGE_CONDA_PREFIX"; \
export CONDARC="$(SAGE_ROOT)/condarc.yml"; \
eval $$$$INSTALL_COMMAND; \
else ( \
echo "Error: $(1) is a conda package, but the environment created by SPKG conda is not present" \
) | sage-logger -p 'cat; exit 1' '$$(SAGE_LOGS)/$(1)-$(2).log'; \
fi; \
else ( \
echo; \
echo "Note: $(1) is a dummy package that the Sage distribution uses"; \
echo "to provide information about equivalent system packages."; \
Expand All @@ -729,6 +740,10 @@ $(1)-$(4)-no-deps:
echo; \
echo "Error: $(1) is a dummy package and "; \
echo "cannot be installed using the Sage distribution." ) | sage-logger -p 'cat; exit 1' '$$(SAGE_LOGS)/$(1)-$(2).log'; \
fi; \
fi; \
rm -f "$$($(4))/$(SPKG_INST_RELDIR)/$(1)"-* && \
touch "$$($(4))/$(SPKG_INST_RELDIR)/$(1)-$(2)"; \
fi

$(1)-no-deps: $(1)-$(4)-no-deps
Expand Down
34 changes: 34 additions & 0 deletions build/pkgs/conda/SPKG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
conda: Installs conda-forge packages in an isolated environment
===============================================================

Description
-----------

conda-forge is a community-led collection of recipes, build infrastructure
and distributions for the conda package manager.

mamba is a fast cross-platform package manager, a compatible
reimplementation of the conda package manager in C++.

micromamba is a tiny version of the mamba package manager. It is a statically linked
C++ executable with a separate command line interface. It does not need a base
environment and does not come with a default version of Python.

Installing this script package installs ``micromamba`` in ``$SAGE_LOCAL/bin``
and creates an isolated conda environment within ``$SAGE_LOCAL/var/lib/sage/conda``.


License
-------

BSD-3-Clause


Upstream Contact
----------------

https://conda-forge.org/

https://github.com/mamba-org/mamba

https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html
32 changes: 32 additions & 0 deletions build/pkgs/conda/spkg-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /bin/sh
set -e

ARCH=$(uname -m)
OS=$(uname)

# Adapted from micro.mamba.pm/install.sh, removed bashisms
if [ "$OS" = "Linux" ]; then
PLATFORM="linux"
if [ "$ARCH" = "aarch64" ]; then
ARCH="aarch64";
elif [ "$ARCH" = "ppc64le" ]; then
ARCH="ppc64le";
else
ARCH="64";
fi
fi

if [ "$OS" = "Darwin" ]; then
PLATFORM="osx";
if [ "$ARCH" = "arm64" ]; then
ARCH="arm64";
else
ARCH="64"
fi
fi

set -x
sage-download-file "https://micro.mamba.pm/api/micromamba/$PLATFORM-$ARCH/latest" | tar -xvj -C "$SAGE_LOCAL" bin/micromamba
export MAMBA_ROOT_PREFIX="$SAGE_LOCAL/var/lib/sage/conda"
export CONDARC="$SAGE_ROOT/condarc.yml"
micromamba create --yes --prefix "$MAMBA_ROOT_PREFIX" -c conda-forge
1 change: 1 addition & 0 deletions build/pkgs/conda/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
optional
2 changes: 1 addition & 1 deletion build/pkgs/ffmpeg/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/git/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/github_cli/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/imagemagick/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/info/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
4 changes: 0 additions & 4 deletions build/pkgs/latte_int/dependencies

This file was deleted.

2 changes: 1 addition & 1 deletion build/pkgs/pandoc/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/pdf2svg/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/rubiks/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/texlive/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
2 changes: 1 addition & 1 deletion build/pkgs/valgrind/dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mamba_forge
conda
6 changes: 6 additions & 0 deletions src/bin/sage-env
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ if [ -z "${SAGE_ORIG_PATH_SET}" ]; then
SAGE_ORIG_PATH_SET=True && export SAGE_ORIG_PATH_SET
fi
if [ -n "$SAGE_LOCAL" ]; then
# https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html
SAGE_CONDA_PREFIX="$SAGE_LOCAL/var/lib/sage/conda"
if [ -d "$SAGE_CONDA_PREFIX/conda-meta" ]; then
# We do not use the activation script; we only want bin in PATH, nothing else.
export PATH="$SAGE_CONDA_PREFIX/bin:$PATH"
fi
export PATH="$SAGE_LOCAL/bin:$PATH"
fi
if [ -n "$SAGE_VENV" ]; then
Expand Down

0 comments on commit a2da019

Please sign in to comment.