Skip to content

Commit

Permalink
Trac #33873: Refactor system package scripts
Browse files Browse the repository at this point in the history
We extend the scripts `sage-get-system-packages` and `sage-print-system-
package-command`:

- When `system=auto`, they now invoke `sage-guess-package-system`.

- `sage-print-system-package-command` gets a new option `--spkg`; then
it invokes `sage-get-system-packages`.

This simplifies some uses.

URL: https://trac.sagemath.org/33873
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Jul 8, 2022
2 parents 6455b21 + d75da7e commit 0d76aee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 8 additions & 1 deletion build/bin/sage-get-system-packages
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
SYSTEM=$1
if [ -z "$SYSTEM" ]; then
echo >&2 "usage: $0 {debian|arch|conda|pip|...} SPKGS..."
echo >&2 "usage: $0 {auto|debian|arch|conda|pip|...} SPKGS..."
exit 1
fi
shift
Expand Down Expand Up @@ -31,6 +31,13 @@ case "$SYSTEM" in
COLLECT=echo
;;
*)
if [ "$SYSTEM" = auto ]; then
SYSTEM=$(sage-guess-package-system 2>/dev/null)
if [ "$SYSTEM" = unknown ]; then
echo >&2 "unknown package system"
exit 1
fi
fi
SYSTEM_PACKAGES_FILE_NAMES="distros/$SYSTEM.txt"
STRIP_COMMENTS="sed s/#.*//;"
COLLECT=echo
Expand Down
20 changes: 18 additions & 2 deletions build/bin/sage-print-system-package-command
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ shift
IF_VERBOSE=:
SUDO=
PROMPT=
SPKG=no
if [ -n "$OUTPUT_RST" ]; then
COMMENT=""
else
Expand All @@ -13,6 +14,10 @@ fi
while :
do
case "$1" in
--spkg)
# Whether given package names are SPKG names instead of system package names
SPKG=yes
;;
--verbose=*)
IF_VERBOSE=
COMMENT="${1#--verbose=}"
Expand Down Expand Up @@ -48,10 +53,21 @@ done
command=$1
shift
if [ -z "$system" -o -z "$command" ]; then
echo >&2 "usage: $0 {debian|arch|conda|...} [--verbose] [--sudo] [--prompt] {update|install|setup-build-env|remove|...} PACKAGES..."
echo >&2 "usage: $0 {auto|debian|arch|conda|...} [--verbose] [--sudo] [--prompt] {update|install|setup-build-env|remove|...} PACKAGES..."
exit 1
fi
system_packages="$*"
if [ "$system" = auto ]; then
system=$(sage-guess-package-system 2>/dev/null)
if [ "$system" = unknown ]; then
echo >&2 "unknown package system"
exit 1
fi
fi
if [ "$SPKG" = "yes" ]; then
system_packages=$(echo $(sage-get-system-packages $system $*))
else
system_packages="$*"
fi
options=
env=
shopt -s extglob
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ setenv =
# local envs need HOME set, also Docker 19.03 needs HOME
{local,docker}: HOME={envdir}
# for local envs we can guess the package system if it is not provided as a factor
local: SYSTEM=$(build/bin/sage-guess-package-system)
local: SYSTEM=auto
#
# default tag is "latest"
#
Expand Down Expand Up @@ -586,7 +586,7 @@ commands =
#
# https://docs.brew.sh/Installation
homebrew: bash -c 'if [ ! -x {env:HOMEBREW}/bin/brew ]; then mkdir -p {env:HOMEBREW} && cd {env:HOMEBREW} && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 ; fi'
homebrew: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) PACKAGES=$(build/bin/sage-get-system-packages homebrew $(PATH=build/bin:$PATH build/bin/sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}); {env:HOMEBREW}/bin/brew install $PACKAGES; {env:HOMEBREW}/bin/brew upgrade $PACKAGES;; esac'
homebrew: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) export PATH="build/bin:$PATH" && PACKAGES=$(sage-get-system-packages homebrew $(sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}); {env:HOMEBREW}/bin/brew install $PACKAGES; {env:HOMEBREW}/bin/brew upgrade $PACKAGES;; esac'
#
# local-conda
#
Expand All @@ -599,17 +599,17 @@ commands =
local-conda: bash -c 'cat {env:USE_CONDARC} >> {env:CONDA_PREFIX}/.condarc'
local-conda: bash -c 'if [ ! -x {env:CONDA_PREFIX}/bin/conda ]; then mkdir {env:CONDA_PREFIX}/conda-meta && curl -L {env:CONDA_INSTALLER_URL_BASE}{env:CONDA_INSTALLER_FILE} -C - -o {env:SHARED_CACHE_DIR}/{env:CONDA_INSTALLER_FILE} && bash {env:SHARED_CACHE_DIR}/{env:CONDA_INSTALLER_FILE} -b -f -p {env:CONDA_PREFIX}; fi'
local-conda: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) {env:SETENV} && {env:CONDA_PREFIX}/bin/conda update -n base --yes conda;; esac'
local-conda: bash -c 'PACKAGES=$(build/bin/sage-get-system-packages conda $(PATH=build/bin:$PATH build/bin/sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}); {env:SETENV} && {env:CONDA_PREFIX}/bin/conda install --yes --quiet $PACKAGES'
local-conda: bash -c 'export PATH="build/bin:$PATH" && PACKAGES=$(sage-get-system-packages conda $(sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}); {env:SETENV} && {env:CONDA_PREFIX}/bin/conda install --yes --quiet $PACKAGES'
#
# local-cygwin-choco: Use choco to install cygwin packages
#
local-cygwin-choco: bash -c 'PACKAGES=$(build/bin/sage-get-system-packages {env:SYSTEM} $(PATH=build/bin:$PATH build/bin/sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) _bootstrap); /cygdrive/c/ProgramData/Chocolatey/bin/choco install $PACKAGES --source cygwin'
local-cygwin-choco: bash -c 'export PATH="build/bin:$PATH" && PACKAGES=$(sage-get-system-packages {env:SYSTEM} $(sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) _bootstrap); /cygdrive/c/ProgramData/Chocolatey/bin/choco install $PACKAGES --source cygwin'
#
# local-root: Assume we are root, run the system package commands
# local-sudo: Use sudo to run the system package commands as root
#
local-{root,sudo}: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) eval $(build/bin/sage-print-system-package-command {env:SYSTEM} {env:__SUDO:} update) ;; esac'
local-{root,sudo}: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) PACKAGES=$(build/bin/sage-get-system-packages {env:SYSTEM} $(PATH=build/bin:$PATH build/bin/sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}); eval $(build/bin/sage-print-system-package-command {env:SYSTEM} {env:__SUDO:} --yes --no-install-recommends install $PACKAGES) || [ "$IGNORE_MISSING_SYSTEM_PACKAGES" = yes ] && echo "(ignoring errors)" ;; esac'
local-{root,sudo}: bash -c 'case "{env:SKIP_SYSTEM_PKG_INSTALL:}" in 1|y*|Y*);; *) export PATH="build/bin:$PATH" && eval $(sage-print-system-package-command {env:SYSTEM} {env:__SUDO:} --yes --no-install-recommends --spkg install $(sage-package list {env:SAGE_PACKAGE_LIST_ARGS}) {env:ALL_EXTRA_SAGE_PACKAGES}) || [ "$IGNORE_MISSING_SYSTEM_PACKAGES" = yes ] && echo "(ignoring errors)" ;; esac'
#
# All "local" environments
#
Expand Down

0 comments on commit 0d76aee

Please sign in to comment.