def test_env_with_included_config_scope(): config_scope_path = os.path.join(ev.root('test'), 'config') test_config = """\ env: include: - %s specs: - mpileaks """ % config_scope_path _env_create('test', StringIO(test_config)) e = ev.read('test') fs.mkdirp(config_scope_path) with open(os.path.join(config_scope_path, 'packages.yaml'), 'w') as f: f.write("""\ packages: mpileaks: version: [2.2] """) with e: e.concretize() assert any(x.satisfies('[email protected]') for x in e._get_environment_specs())
def env_activate(args): env = args.activate_env if not args.shell: spack.cmd.common.shell_init_instructions( "spack env activate", " eval `spack env activate {sh_arg} %s`" % env, ) return 1 if ev.exists(env) and not args.dir: spack_env = ev.root(env) short_name = env env_prompt = '[%s]' % env elif ev.is_env_dir(env): spack_env = os.path.abspath(env) short_name = os.path.basename(os.path.abspath(env)) env_prompt = '[%s]' % short_name else: tty.die("No such environment: '%s'" % env) if spack_env == os.environ.get('SPACK_ENV'): tty.die("Environment %s is already active" % args.activate_env) active_env = ev.get_env(namedtuple('args', ['env'])(env), 'activate') cmds = ev.activate(active_env, add_view=args.with_view, shell=args.shell, prompt=env_prompt if args.prompt else None) sys.stdout.write(cmds)
def test_env_with_included_config_scope(): config_scope_path = os.path.join(ev.root('test'), 'config') test_config = """\ env: include: - %s specs: - mpileaks """ % config_scope_path spack.package_prefs.PackagePrefs.clear_caches() _env_create('test', StringIO(test_config)) e = ev.read('test') fs.mkdirp(config_scope_path) with open(os.path.join(config_scope_path, 'packages.yaml'), 'w') as f: f.write("""\ packages: mpileaks: version: [2.2] """) ev.prepare_config_scope(e) e.concretize() assert any(x.satisfies('[email protected]') for x in e._get_environment_specs())
def mock_test_env(): test_env_name = 'test' env_dir = ev.root(test_env_name) mkdirp(env_dir) yield test_env_name, env_dir # Remove the temporary test environment directory created above shutil.rmtree(env_dir)
def env_activate(args): if not args.activate_env and not args.dir and not args.temp: tty.die('spack env activate requires an environment name, directory, or --temp') if not args.shell: spack.cmd.common.shell_init_instructions( "spack env activate", " eval `spack env activate {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 activate with --env, --env-dir and --no-env ' 'is ambiguous') env_name_or_dir = args.activate_env or args.dir # Temporary environment if args.temp: env = create_temp_env_directory() spack_env = os.path.abspath(env) short_name = os.path.basename(spack_env) ev.Environment(env).write(regenerate=False) # Named environment elif ev.exists(env_name_or_dir) and not args.dir: spack_env = ev.root(env_name_or_dir) short_name = env_name_or_dir # Environment directory elif ev.is_env_dir(env_name_or_dir): spack_env = os.path.abspath(env_name_or_dir) short_name = os.path.basename(spack_env) else: tty.die("No such environment: '%s'" % env_name_or_dir) env_prompt = '[%s]' % short_name if spack_env == os.environ.get('SPACK_ENV'): tty.debug("Environment is already active") return # Activate new environment active_env = ev.Environment(spack_env) cmds = spack.environment.shell.activate_header( env=active_env, shell=args.shell, prompt=env_prompt if args.prompt else None ) env_mods = spack.environment.shell.activate( env=active_env, add_view=args.with_view ) cmds += env_mods.shell_modifications(args.shell) sys.stdout.write(cmds)
def env_activate(args): env = args.activate_env 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 activate --sh %s` # for bash/sh' % env, ' eval `spack env activate --csh %s` # for csh/tcsh' % env, ] tty.msg(*msg) return 1 if ev.exists(env) and not args.dir: spack_env = ev.root(env) short_name = env env_prompt = '[%s]' % env elif ev.is_env_dir(env): spack_env = os.path.abspath(env) short_name = os.path.basename(os.path.abspath(env)) env_prompt = '[%s]' % short_name else: tty.die("No such environment: '%s'" % env) if spack_env == os.environ.get('SPACK_ENV'): tty.die("Environment %s is already active" % args.activate_env) if args.shell == 'csh': # TODO: figure out how to make color work for csh sys.stdout.write('setenv SPACK_ENV %s;\n' % spack_env) sys.stdout.write('alias despacktivate "spack env deactivate";\n') if args.prompt: sys.stdout.write('if (! $?SPACK_OLD_PROMPT ) ' 'setenv SPACK_OLD_PROMPT "${prompt}";\n') sys.stdout.write('set prompt="%s ${prompt}";\n' % env_prompt) else: if 'color' in os.environ['TERM']: env_prompt = colorize('@G{%s} ' % env_prompt, color=True) sys.stdout.write('export SPACK_ENV=%s;\n' % spack_env) sys.stdout.write("alias despacktivate='spack env deactivate';\n") if args.prompt: sys.stdout.write('if [ -z "${SPACK_OLD_PS1}" ]; then\n') sys.stdout.write('export SPACK_OLD_PS1="${PS1}"; fi;\n') sys.stdout.write('export PS1="%s ${PS1}";\n' % env_prompt)
def env_activate(args): env = args.activate_env 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 activate --sh %s` # for bash/sh' % env, ' eval `spack env activate --csh %s` # for csh/tcsh' % env, ] tty.msg(*msg) return 1 if ev.exists(env) and not args.dir: spack_env = ev.root(env) short_name = env env_prompt = '[%s]' % env elif ev.is_env_dir(env): spack_env = os.path.abspath(env) short_name = os.path.basename(os.path.abspath(env)) env_prompt = '[%s]' % short_name else: tty.die("No such environment: '%s'" % env) if spack_env == os.environ.get('SPACK_ENV'): tty.die("Environment %s is already active" % args.activate_env) if args.shell == 'csh': # TODO: figure out how to make color work for csh sys.stdout.write('setenv SPACK_ENV %s;\n' % spack_env) sys.stdout.write('alias despacktivate "spack env deactivate";\n') if args.prompt: sys.stdout.write('if (! $?SPACK_OLD_PROMPT ) ' 'setenv SPACK_OLD_PROMPT "${prompt}";\n') sys.stdout.write('set prompt="%s ${prompt}";\n' % env_prompt) else: if 'color' in os.environ['TERM']: env_prompt = colorize('@G{%s} ' % env_prompt, color=True) sys.stdout.write('export SPACK_ENV=%s;\n' % spack_env) sys.stdout.write("alias despacktivate='spack env deactivate';\n") if args.prompt: sys.stdout.write('if [ -z "${SPACK_OLD_PS1}" ]; then\n') sys.stdout.write('export SPACK_OLD_PS1="${PS1}"; fi;\n') sys.stdout.write('export PS1="%s ${PS1}";\n' % env_prompt)
def env_activate(args): env = args.activate_env 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 activate --sh %s` # for bash/sh' % env, ' eval `spack env activate --csh %s` # for csh/tcsh' % env, ] tty.msg(*msg) return 1 if ev.exists(env) and not args.dir: spack_env = ev.root(env) short_name = env env_prompt = '[%s]' % env elif ev.is_env_dir(env): spack_env = os.path.abspath(env) short_name = os.path.basename(os.path.abspath(env)) env_prompt = '[%s]' % short_name else: tty.die("No such environment: '%s'" % env) if spack_env == os.environ.get('SPACK_ENV'): tty.die("Environment %s is already active" % args.activate_env) active_env = ev.get_env(namedtuple('args', ['env'])(env), 'activate') cmds = ev.activate( active_env, add_view=args.with_view, shell=args.shell, prompt=env_prompt if args.prompt else None ) sys.stdout.write(cmds)
def env_activate(args): env = args.activate_env if not args.shell: spack.cmd.common.shell_init_instructions( "spack env activate", " eval `spack env activate {sh_arg} %s`" % env, ) 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 activate with --env, --env-dir and --no-env ' 'is ambiguous') if ev.exists(env) and not args.dir: spack_env = ev.root(env) short_name = env env_prompt = '[%s]' % env elif ev.is_env_dir(env): spack_env = os.path.abspath(env) short_name = os.path.basename(os.path.abspath(env)) env_prompt = '[%s]' % short_name else: tty.die("No such environment: '%s'" % env) if spack_env == os.environ.get('SPACK_ENV'): tty.debug("Environment %s is already active" % args.activate_env) return cmds = ev.activate(ev.Environment(spack_env), add_view=args.with_view, shell=args.shell, prompt=env_prompt if args.prompt else None) sys.stdout.write(cmds)
def location(parser, args): if args.module_dir: print(spack.paths.module_path) return if args.spack_root: print(spack.paths.prefix) return if args.location_env: path = ev.root(args.location_env) if not os.path.isdir(path): tty.die("no such environment: '%s'" % args.location_env) print(path) return if args.packages: print(spack.repo.path.first_repo().root) return if args.stages: print(spack.stage.get_stage_root()) return specs = spack.cmd.parse_specs(args.spec) if not specs: tty.die("You must supply a spec.") if len(specs) != 1: tty.die("Too many specs. Supply only one.") # install_dir command matches against installed specs. if args.install_dir: env = ev.active_environment() spec = spack.cmd.disambiguate_spec(specs[0], env) print(spec.prefix) return spec = specs[0] # Package dir just needs the spec name if args.package_dir: print(spack.repo.path.dirname_for_package_name(spec.name)) return # Either concretize or filter from already concretized environment spec = spack.cmd.matching_spec_from_env(spec) pkg = spec.package if args.stage_dir: print(pkg.stage.path) return if args.build_dir: # Out of source builds have build_directory defined if hasattr(pkg, 'build_directory'): # build_directory can be either absolute or relative to the stage path # in either case os.path.join makes it absolute print( os.path.normpath( os.path.join(pkg.stage.path, pkg.build_directory))) return # Otherwise assume in-source builds print(pkg.stage.source_path) return # source dir remains, which requires the spec to be staged if not pkg.stage.expanded: tty.die( "Source directory does not exist yet. " "Run this to create it:", "spack stage " + " ".join(args.spec)) # Default to source dir. print(pkg.stage.source_path)