Source code for ramble.test.mock_spack_runner

# Copyright 2022-2026 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import os


[docs] class MockPackageInfo: def __init__(self, data): self.data = data
[docs] def to_dict(self): return self.data
[docs] def to_version_text(self): return f"{self.data.get('name', 'unknown')} @{self.data.get('version', 'unknown')}"
def __getitem__(self, key): return self.data[key]
[docs] class MockSpackRunner: def __init__(self): self.env_path = None self.concretized = False self.dry_run = False
[docs] def set_env(self, env_path, require_exists=True): self.env_path = env_path
[docs] def set_dry_run(self, dry_run): self.dry_run = dry_run
[docs] def set_compiler_config_dir(self, path): pass
[docs] def activate(self): pass
[docs] def deactivate(self): pass
[docs] def concretize(self): if not self.env_path: return # write dummy spack.yaml and spack.lock spack_yaml = os.path.join(self.env_path, "spack.yaml") with open(spack_yaml, "w") as f: f.write("specs:\n - zlib\n") spack_lock = os.path.join(self.env_path, "spack.lock") with open(spack_lock, "w") as f: f.write('{"roots": [{"spec":"zlib"}]}') self.concretized = True
[docs] def package_provenance(self): return [ MockPackageInfo( { "name": "zlib", "version": "1.2.11", "compiler": "gcc", "compiler_version": "9.3.0", "target": "x86_64", "variants": "none", } ) ]
[docs] def get_version(self): return "0.0.0"
[docs] def generate_source_command(self): return ["echo 'source spack'"]
[docs] def generate_activate_command(self): return ["echo 'activate spack'"]
[docs] def generate_deactivate_command(self): return ["echo 'deactivate spack'"]
[docs] def configure_env(self, env_path): pass
[docs] def inventory_hash(self): return "dummy_hash"
[docs] def package_definitions(self): return []
[docs] def create_env(self, env_path): if not os.path.exists(env_path): os.makedirs(env_path)
[docs] def add_config(self, config): pass
[docs] def add_include_file(self, path): pass
[docs] def copy_from_external_env(self, env): pass
[docs] def add_spec(self, spec): pass
[docs] def generate_env_file(self): pass
[docs] def added_packages(self): return []
[docs] def install(self): pass
[docs] def get_package_path(self, spec): return "zlib", "/path/to/zlib"