Skip to content

Commit

Permalink
Merge pull request #122 from LLNL/feature/chapman39/find_clingo_thru_…
Browse files Browse the repository at this point in the history
…spack

Use `spack bootstrap now` to find clingo
  • Loading branch information
chapman39 authored Dec 20, 2024
2 parents 205672b + 6ce232a commit 44ab4ca
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .ci/test-project/packages/magictestlib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

import llnl.util.tty as tty

from spack import *
from spack.package import *


def cmake_cache_entry(name, value, vtype=None):
Expand Down
6 changes: 2 additions & 4 deletions .ci/test-project/packages/magictestlib_cached/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@
#
###############################################################################

import glob
from spack.package import *

import os
import shutil
import socket
from os import environ as env

import llnl.util.tty as tty

from spack import *


class MagictestlibCached(CachedCMakePackage):
"""MagictestlibCached"""
Expand Down
2 changes: 1 addition & 1 deletion .ci/test-project/packages/uberenv-magictestlib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#
###############################################################################

from spack import *
from spack.package import *

import socket
import os
Expand Down
5 changes: 3 additions & 2 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The Uberenv project release numbers follow [Semantic Versioning](http://semver.o
- Adds support for the spack `--reuse` option for more relaxed tpl/dependency matching.
- Adds support for `--upstream` with `--setup-only`.
- Allow to prevent Uberenv from installing clingo setting `spack_setup_clingo`
to `no` in `.uberenv_config.json`.
to `false` in `.uberenv_config.json`.
- Adds the `--spack-debug` option to run spack spec/install commands in debug mode.
- Adds the `--spack-allow-deprecated` option, to allow spack to build packages marked deprecated.

Expand All @@ -35,8 +35,9 @@ The Uberenv project release numbers follow [Semantic Versioning](http://semver.o
- Allow `.uberenv_config.json` to live at the same level as `uberenv.py`
- No longer removes symlinks when using the directory of `uberenv.py`
- Reduce Spack's git history to a bare minimum
- Better error message for out-of-date `pip`, better documentation for `spack_concretizer` setting
- Uberenv now requires python version 3.3 or above.
- Rather than using pip, Uberenv uses `spack bootstrap now` to install clingo.
- Removes Spack concretizer options, since clingo is the only option in newer Spack. (You can still disable clingo install.)

### Fixed

Expand Down
12 changes: 1 addition & 11 deletions docs/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ Project settings are as follows:
spack_build_mode ``--spack-build-mode`` Set mode used to build TPLs with Spack ``dev-build``
spack_configs_path **None** Directory with Spack configs to be autodetected ``spack_configs``
spack_packages_path **None** Directory|List with Package Repos to be added ``packages``
spack_concretizer **None** Spack concretizer to use ``original, clingo`` ``original``
spack_setup_clingo **None** Do not install clingo if set to ``false`` ``true``
spack_setup_clingo **None** Do not install clingo if set to string ``false`` **None**
spack_externals ``--spack-externals`` Space delimited string of packages for Spack to **None**
search for externals
spack_compiler_paths ``--spack-compiler-paths`` Space delimited string of paths for Spack to **None**
Expand Down Expand Up @@ -277,12 +276,3 @@ Uberenv also features options to optimize the installation

.. note::
These options are only currently available for spack.

Spack Concretization
--------------------

Uberenv provides a ``spack_concretizer`` setting to select the method by which the "concrete" dependency tree is determined.
The ``original`` option is the default behavior and is often subject to errors where a valid set of constraints fails to
concretize. The ``clingo`` option is more robust in this respect but requires the installation of the ``clingo`` Python module.
This happens automatically when the ``spack_concretizer`` option is set to ``clingo``, but requires ``pip`` >= 19.3 and Python >= 3.6.
If your ``pip`` version is out of date, Uberenv will prompt you to upgrade it.
70 changes: 19 additions & 51 deletions uberenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,6 @@ def __init__(self, args, extra_args):
self.spec_hash = ""
self.use_install = False

if "spack_concretizer" in self.project_args and self.project_args["spack_concretizer"] == "clingo":
self.use_clingo = True
if "spack_setup_clingo" in self.project_args and self.project_args["spack_setup_clingo"] == False:
print("[info: clingo will not be installed by uberenv]")
else:
self.setup_clingo()
else:
self.use_clingo = False

# Some additional setup for macos
if is_darwin():
if args["macos_sdk_env_setup"]:
Expand Down Expand Up @@ -719,7 +710,7 @@ def setup_paths_and_dirs(self):

UberEnv.setup_paths_and_dirs(self)

# Next to uberenv.py (backwards compatility)
# Next to uberenv.py (backwards compatibility)
spack_configs_path = pabs(pjoin(self.uberenv_path,"spack_config"))

# In project config file
Expand Down Expand Up @@ -885,19 +876,17 @@ def patch(self):
# this is an opportunity to show spack python info post obtaining spack
self.print_spack_python_info()

# Check which concretizer this version of Spack has
self.check_concretizer_args()

# force spack to use only "defaults" config scope
self.disable_spack_config_scopes()

# Update spack's config.yaml if clingo was requested
if self.use_clingo:
concretizer_cmd = "{0} config --scope defaults add config:concretizer:clingo".format(self.spack_exe(use_spack_env=False))
res = sexe(concretizer_cmd, echo=True)
if res != 0:
print("[ERROR: Failed to update Spack configuration to use new concretizer]")
sys.exit(-1)
# setup clingo (unless specified not to)
if "spack_setup_clingo" in self.project_args and self.project_args["spack_setup_clingo"].lower() == "false":
print("[info: clingo will not be installed by uberenv]")
else:
self.setup_clingo()

# Check which concretizer this version of Spack has
self.check_concretizer_args()

def create_spack_env(self):
# Create Spack Environment
Expand Down Expand Up @@ -1219,43 +1208,22 @@ def use_spack_upstream(self):

def setup_clingo(self):
"""
Attempts to install the clingo answer set programming library
Attempts to install the clingo answer set programming library via Spack
if it is not already available as a Python module
"""
if not have_internet():
print("[WARNING: No internet detected. Skipping setting up clingo.]")
return

try:
import clingo
except ImportError:
import pip
pip_ver = pip.__version__
# Requirement comes from https://github.com/pypa/manylinux
# JBE: I think the string comparison is somewhat correct here, if not we'll
# need to install setuptools for 'packaging.version'
if pip_ver < "19.3":
print("[!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print(" ERROR: pip version {0} is too old to install clingo".format(pip_ver))
print(" pip 19.3 is required for PEP 599 support")
print(" Try running the following command to upgrade pip:")
print(" python3 -m pip install --user --upgrade pip")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!]")
sys.exit(-1)
py_interp = sys.executable
clingo_pkg = "clingo"
uninstall_cmd = "{0} -m pip uninstall -y {1}".format(py_interp, clingo_pkg)
# Uninstall it first in case the available version failed due to differing arch
# pip will still return 0 in the case of a "trivial" uninstall
res = sexe(uninstall_cmd, echo=True)
if res != 0:
print("[ERROR: Clingo uninstall failed with returncode {0}]".format(res))
sys.exit(-1)
install_cmd = "{0} -m pip install --user {1}".format(py_interp, clingo_pkg)
res = sexe(install_cmd, echo=True)
if res != 0:
print("[ERROR: Clingo install failed with returncode {0}]".format(res))
sys.exit(-1)
res = sexe('{0} bootstrap now'.format(self.spack_exe(use_spack_env = False)), echo=True)
if res != 0:
print("[ERROR: 'spack bootstrap now' failed with returncode {0}]".format(res))
sys.exit(-1)

res = sexe('{0} bootstrap status'.format(self.spack_exe(use_spack_env = False)), echo=True)
if res != 0:
print("[ERROR: 'spack bootstrap status' failed with returncode {0}]".format(res))
sys.exit(-1)


def find_osx_sdks():
Expand Down

0 comments on commit 44ab4ca

Please sign in to comment.