def deactivate(): """ Deactivate an environment and collect corresponding environment modifications. Note: unloads the environment in its current state, not in the state it was loaded in, meaning that specs that were removed from the spack environment after activation are not unloaded. Returns: spack.util.environment.EnvironmentModifications: Environment variables modifications to activate environment. """ env_mods = EnvironmentModifications() active = ev.active_environment() if active is None: return env_mods if ev.default_view_name in active.views: try: with spack.store.db.read_transaction(): active.rm_default_view_from_env(env_mods) except (spack.repo.UnknownPackageError, spack.repo.UnknownNamespaceError) as e: tty.warn(e) tty.warn('Could not fully deactivate view due to missing package ' 'or repo, shell environment may be corrupt.') ev.deactivate() return env_mods
def create_dev_env(parser, args): env_path = create_env.create_env(parser, args) env = ev.Environment(env_path) ev.activate(env) specs = spack.cmd.parse_specs(args.spec) for s in specs: # check that all specs were concrete if not s.versions.concrete: print('\nWarning: {spec} is not concrete and will not ' 'be setup as a develop spec.' '\nAll specs must be concrete for ' '\'spack manager create-dev-env\' to clone for you i.e. at ' 'least [package]@[version].\nTo learn what versions are' ' available type \'spack info [package]\'' '\nSome common exawind versions are: exawind@master, ' 'amr-wind@main and nalu-wind@master\n'.format(spec=s)) continue dev_args = [] # kind of hacky, but spack will try to re-clone # if we don't give the --path argument even though # it is already in the spack.yaml if env.is_develop(s) and 'path' in env.yaml['spack']['develop'][str( s.name)]: dev_args.extend( ['--path', env.yaml['spack']['develop'][str(s.name)]['path']]) if 'trilinos' in str(s.name): dev_args.extend([ '-rb', '[email protected]:trilinos/trilinos.git', str(s.version) ]) dev_args.append(str(s)) develop(dev_args) ev.deactivate()
def use_develop_specs(env, specs): # we have to concretize to solve the dependency tree to extract # the top level dependencies and make them develop specs. # anything that is not a develop spec is not gauranteed to get installed # since spack can reuse them for matching hashes print('\nSetting up develop specs') dev_specs = list( dict.fromkeys([s.format('{name}{@version}') for s in specs])) ev.activate(env) for spec_string in dev_specs: # special treatment for trilinos since its clone fails # with standard spack develop if 'trilinos' in spec_string: branch = spec_string.split('@')[-1] command(manager, 'develop', '--shallow', '-rb', 'https://github.com/trilinos/trilinos', branch, spec_string) elif 'openfast' in spec_string: # skip openfast. we never want to dev build it # because it takes so long to compile continue elif 'cmake' in spec_string: continue else: command(manager, 'develop', '--shallow', spec_string) ev.deactivate()
def deactivate(): """ Deactivate an environment and collect corresponding environment modifications Returns: spack.util.environment.EnvironmentModifications: Environment variables modifications to activate environment. """ env_mods = EnvironmentModifications() active = ev.active_environment() if active is None: return env_mods if ev.default_view_name in active.views: try: with spack.store.db.read_transaction(): active.rm_default_view_from_env(env_mods) except (spack.repo.UnknownPackageError, spack.repo.UnknownNamespaceError) as e: tty.warn(e) tty.warn('Could not fully deactivate view due to missing package ' 'or repo, shell environment may be corrupt.') ev.deactivate() return env_mods
def clean_user_environment(): env_var = ev.spack_env_var in os.environ active = ev._active_environment if env_var: spack_env_value = os.environ.pop(ev.spack_env_var) if active: ev.deactivate() yield if env_var: os.environ[ev.spack_env_var] = spack_env_value if active: ev.activate(active)
def clean_user_environment(): env_var = ev.spack_env_var in os.environ active = ev._active_environment if env_var: spack_env_value = os.environ.pop(ev.spack_env_var) if active: ev.deactivate() yield if env_var: os.environ[ev.spack_env_var] = spack_env_value if active: ev.activate(active)
def get_top_level_specs(env, blacklist=blacklist): ev.activate(env) print('\nInitial concretize') command(concretize) top_specs = [] for root in env.roots(): if root.name in blacklist: continue top_specs.append(root) for dep in root.dependencies(): if dep.name not in blacklist: top_specs.append(dep) # remove any duplicates top_specs = list(dict.fromkeys(top_specs)) print('\nTop Level Specs:', [s.name for s in top_specs]) ev.deactivate() return top_specs
def add_spec(env, extension, data, create_modules): ev.activate(env) add(data.spec) ev.deactivate() excludes = view_excludes(data) with open(env.manifest_path, 'r') as f: yaml = syaml.load(f) if create_modules: module_excludes = excludes.copy() module_path = os.path.join(os.environ['SPACK_MANAGER'], 'modules') module_dict = { data.id: { 'enable': ['tcl'], 'use_view': data.id, 'prefix_inspections': { 'bin': ['PATH'] }, 'roots': { 'tcl': module_path }, 'arch_folder': False, 'tcl': { 'projections': { 'all': '%s/{name}-%s' % (extension, data.id) }, 'hash_length': 0, 'blacklist_implicits': True, 'blacklist': module_excludes } } } try: yaml['spack']['modules'].update(module_dict) except KeyError: yaml['spack']['modules'] = module_dict with open(env.manifest_path, 'w') as f: syaml.dump(yaml, stream=f, default_flow_style=False)
def env_deactivate(args): if not args.shell: spack.cmd.common.shell_init_instructions( "spack env deactivate", " eval `spack env deactivate {sh_arg}`", ) return 1 if 'SPACK_ENV' not in os.environ: tty.die('No environment is currently active.') cmds = ev.deactivate(shell=args.shell) sys.stdout.write(cmds)
def env_deactivate(args): if not args.shell: msg = [ "This command works best with Spack's shell support", "" ] + spack.cmd.common.shell_init_instructions + [ 'Or, if you want to use `spack env activate` without initializing', 'shell support, you can run one of these:', '', ' eval `spack env deactivate --sh` # for bash/sh', ' eval `spack env deactivate --csh` # for csh/tcsh', ] tty.msg(*msg) return 1 if 'SPACK_ENV' not in os.environ: tty.die('No environment is currently active.') cmds = ev.deactivate(shell=args.shell) sys.stdout.write(cmds)
def env_deactivate(args): if not args.shell: spack.cmd.common.shell_init_instructions( "spack env deactivate", " eval `spack env deactivate {sh_arg}`", ) return 1 # Error out when -e, -E, -D flags are given, cause they are ambiguous. if args.env or args.no_env or args.env_dir: tty.die( 'Calling spack env deactivate with --env, --env-dir and --no-env ' 'is ambiguous') if 'SPACK_ENV' not in os.environ: tty.die('No environment is currently active.') cmds = ev.deactivate(shell=args.shell) sys.stdout.write(cmds)
def clean_test_environment(): yield ev.deactivate()
parser.add_argument('--dev_name', required=False, help='directory name for the developer env') parser.add_argument('--num_threads', required=False, help='DAG paralleization') parser.set_defaults(view_name='default', snap_name='test', dev_name='test_external', num_threads=1) args = parser.parse_args() # set up the snapshot print('Create Snapshot') args = snapshot_creator.parse([ '--use_develop', '--modules', '--name', args.snap_name, '--num_threads', args.num_threads ]) snapshot_path = snapshot_creator.create_snapshots(args) print('Snapshot created at', snapshot_path) # set up the user environment ev.deactivate() env_path = os.path.join(os.environ['SPACK_MANAGER'], 'environments', args.dev_name) command(manager, 'create-env', '--directory', env_path, '--spec', 'nalu-wind') ev.activate(ev.Environment(env_path)) command(manager, 'external', snapshot_path, '-v', args.view_name, '--blacklist', 'nalu-wind') command(manager, 'develop', 'nalu-wind@master') command(concretize) command(install)