init: factor paths out of spack/__init__.py and into spack.paths module

This commit is contained in:
Todd Gamblin 2018-04-08 21:10:05 -05:00 committed by scheibelp
parent 74aee60f7d
commit a4d276fbe4
65 changed files with 367 additions and 296 deletions

View File

@ -27,51 +27,7 @@
import sys import sys
import multiprocessing import multiprocessing
from llnl.util.filesystem import ancestor from spack.paths import var_path, user_config_path
#-----------------------------------------------------------------------------
# Variables describing how Spack is laid out in its prefix.
#-----------------------------------------------------------------------------
# This file lives in $prefix/lib/spack/spack/__file__
spack_root = ancestor(__file__, 4)
# The spack script itself
spack_file = os.path.join(spack_root, "bin", "spack")
# spack directory hierarchy
lib_path = os.path.join(spack_root, "lib", "spack")
external_path = os.path.join(lib_path, "external")
build_env_path = os.path.join(lib_path, "env")
module_path = os.path.join(lib_path, "spack")
platform_path = os.path.join(module_path, 'platforms')
compilers_path = os.path.join(module_path, "compilers")
build_systems_path = os.path.join(module_path, 'build_systems')
operating_system_path = os.path.join(module_path, 'operating_systems')
test_path = os.path.join(module_path, "test")
hooks_path = os.path.join(module_path, "hooks")
var_path = os.path.join(spack_root, "var", "spack")
stage_path = os.path.join(var_path, "stage")
repos_path = os.path.join(var_path, "repos")
share_path = os.path.join(spack_root, "share", "spack")
# Paths to built-in Spack repositories.
packages_path = os.path.join(repos_path, "builtin")
mock_packages_path = os.path.join(repos_path, "builtin.mock")
# User configuration location
user_config_path = os.path.expanduser('~/.spack')
prefix = spack_root
opt_path = os.path.join(prefix, "opt")
etc_path = os.path.join(prefix, "etc")
system_etc_path = '/etc'
# GPG paths.
gpg_keys_path = os.path.join(var_path, "gpg")
mock_gpg_data_path = os.path.join(var_path, "gpg.mock", "data")
mock_gpg_keys_path = os.path.join(var_path, "gpg.mock", "keys")
gpg_path = os.path.join(opt_path, "spack", "gpg")
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Below code imports spack packages. # Below code imports spack packages.
@ -280,4 +236,3 @@ def editor_not_found(*args, **kwargs):
# Add default values for attributes that would otherwise be modified from # Add default values for attributes that would otherwise be modified from
# Spack main script # Spack main script
debug = False debug = False
spack_working_dir = None

View File

@ -83,12 +83,12 @@
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.paths
import spack.error as serr
from spack.util.naming import mod_to_class from spack.util.naming import mod_to_class
from spack.util.environment import get_path from spack.util.environment import get_path
from spack.util.multiproc import parmap from spack.util.multiproc import parmap
from spack.util.spack_yaml import syaml_dict from spack.util.spack_yaml import syaml_dict
import spack.error as serr
class NoPlatformError(serr.SpackError): class NoPlatformError(serr.SpackError):
@ -463,7 +463,7 @@ def arch_for_spec(arch_spec):
@memoized @memoized
def all_platforms(): def all_platforms():
classes = [] classes = []
mod_path = spack.platform_path mod_path = spack.paths.platform_path
parent_module = "spack.platforms" parent_module = "spack.platforms"
for name in list_modules(mod_path): for name in list_modules(mod_path):

View File

@ -63,9 +63,10 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.tty.color import colorize from llnl.util.tty.color import colorize
from llnl.util.filesystem import join_path, mkdirp, install, install_tree from llnl.util.filesystem import mkdirp, install, install_tree
import spack import spack.main
import spack.paths
import spack.store import spack.store
from spack.environment import EnvironmentModifications, validate from spack.environment import EnvironmentModifications, validate
from spack.util.environment import env_flag, filter_system_paths, get_path from spack.util.environment import env_flag, filter_system_paths, get_path
@ -138,21 +139,21 @@ def set_compiler_environment_variables(pkg, env):
# and return it # and return it
# TODO : add additional kwargs for better diagnostics, like requestor, # TODO : add additional kwargs for better diagnostics, like requestor,
# ttyout, ttyerr, etc. # ttyout, ttyerr, etc.
link_dir = spack.build_env_path link_dir = spack.paths.build_env_path
# Set SPACK compiler variables so that our wrapper knows what to call # Set SPACK compiler variables so that our wrapper knows what to call
if compiler.cc: if compiler.cc:
env.set('SPACK_CC', compiler.cc) env.set('SPACK_CC', compiler.cc)
env.set('CC', join_path(link_dir, compiler.link_paths['cc'])) env.set('CC', os.path.join(link_dir, compiler.link_paths['cc']))
if compiler.cxx: if compiler.cxx:
env.set('SPACK_CXX', compiler.cxx) env.set('SPACK_CXX', compiler.cxx)
env.set('CXX', join_path(link_dir, compiler.link_paths['cxx'])) env.set('CXX', os.path.join(link_dir, compiler.link_paths['cxx']))
if compiler.f77: if compiler.f77:
env.set('SPACK_F77', compiler.f77) env.set('SPACK_F77', compiler.f77)
env.set('F77', join_path(link_dir, compiler.link_paths['f77'])) env.set('F77', os.path.join(link_dir, compiler.link_paths['f77']))
if compiler.fc: if compiler.fc:
env.set('SPACK_FC', compiler.fc) env.set('SPACK_FC', compiler.fc)
env.set('FC', join_path(link_dir, compiler.link_paths['fc'])) env.set('FC', os.path.join(link_dir, compiler.link_paths['fc']))
# Set SPACK compiler rpath flags so that our wrapper knows what to use # Set SPACK compiler rpath flags so that our wrapper knows what to use
env.set('SPACK_CC_RPATH_ARG', compiler.cc_rpath_arg) env.set('SPACK_CC_RPATH_ARG', compiler.cc_rpath_arg)
@ -302,20 +303,21 @@ def set_build_environment_variables(pkg, env, dirty):
env.prepend_path('PATH', bin_dir) env.prepend_path('PATH', bin_dir)
# Add spack build environment path with compiler wrappers first in # Add spack build environment path with compiler wrappers first in
# the path. We add both spack.env_path, which includes default # the path. We add the compiler wrapper path, which includes default
# wrappers (cc, c++, f77, f90), AND a subdirectory containing # wrappers (cc, c++, f77, f90), AND a subdirectory containing
# compiler-specific symlinks. The latter ensures that builds that # compiler-specific symlinks. The latter ensures that builds that
# are sensitive to the *name* of the compiler see the right name # are sensitive to the *name* of the compiler see the right name when
# when we're building with the wrappers. # we're building with the wrappers.
# #
# Conflicts on case-insensitive systems (like "CC" and "cc") are # Conflicts on case-insensitive systems (like "CC" and "cc") are
# handled by putting one in the <build_env_path>/case-insensitive # handled by putting one in the <build_env_path>/case-insensitive
# directory. Add that to the path too. # directory. Add that to the path too.
env_paths = [] env_paths = []
compiler_specific = join_path(spack.build_env_path, pkg.compiler.name) compiler_specific = os.path.join(
for item in [spack.build_env_path, compiler_specific]: spack.paths.build_env_path, pkg.compiler.name)
for item in [spack.paths.build_env_path, compiler_specific]:
env_paths.append(item) env_paths.append(item)
ci = join_path(item, 'case-insensitive') ci = os.path.join(item, 'case-insensitive')
if os.path.isdir(ci): if os.path.isdir(ci):
env_paths.append(ci) env_paths.append(ci)
@ -328,12 +330,12 @@ def set_build_environment_variables(pkg, env, dirty):
env.set(SPACK_DEBUG, 'TRUE') env.set(SPACK_DEBUG, 'TRUE')
env.set(SPACK_SHORT_SPEC, pkg.spec.short_spec) env.set(SPACK_SHORT_SPEC, pkg.spec.short_spec)
env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format('${PACKAGE}-${HASH:7}')) env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format('${PACKAGE}-${HASH:7}'))
env.set(SPACK_DEBUG_LOG_DIR, spack.spack_working_dir) env.set(SPACK_DEBUG_LOG_DIR, spack.main.spack_working_dir)
# Add any pkgconfig directories to PKG_CONFIG_PATH # Add any pkgconfig directories to PKG_CONFIG_PATH
for prefix in build_link_prefixes: for prefix in build_link_prefixes:
for directory in ('lib', 'lib64', 'share'): for directory in ('lib', 'lib64', 'share'):
pcdir = join_path(prefix, directory, 'pkgconfig') pcdir = os.path.join(prefix, directory, 'pkgconfig')
if os.path.isdir(pcdir): if os.path.isdir(pcdir):
env.prepend_path('PKG_CONFIG_PATH', pcdir) env.prepend_path('PKG_CONFIG_PATH', pcdir)
@ -374,11 +376,11 @@ def set_module_variables_for_package(pkg, module):
m.std_cmake_args = spack.CMakePackage._std_args(pkg) m.std_cmake_args = spack.CMakePackage._std_args(pkg)
# Put spack compiler paths in module scope. # Put spack compiler paths in module scope.
link_dir = spack.build_env_path link_dir = spack.paths.build_env_path
m.spack_cc = join_path(link_dir, pkg.compiler.link_paths['cc']) m.spack_cc = os.path.join(link_dir, pkg.compiler.link_paths['cc'])
m.spack_cxx = join_path(link_dir, pkg.compiler.link_paths['cxx']) m.spack_cxx = os.path.join(link_dir, pkg.compiler.link_paths['cxx'])
m.spack_f77 = join_path(link_dir, pkg.compiler.link_paths['f77']) m.spack_f77 = os.path.join(link_dir, pkg.compiler.link_paths['f77'])
m.spack_fc = join_path(link_dir, pkg.compiler.link_paths['fc']) m.spack_fc = os.path.join(link_dir, pkg.compiler.link_paths['fc'])
# Emulate some shell commands for convenience # Emulate some shell commands for convenience
m.pwd = os.getcwd m.pwd = os.getcwd

View File

@ -33,8 +33,8 @@
from llnl.util.tty.color import colorize from llnl.util.tty.color import colorize
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack
import spack.config import spack.config
import spack.paths
import spack.spec import spack.spec
import spack.store import spack.store
from spack.error import SpackError from spack.error import SpackError
@ -58,8 +58,6 @@
SETUP_PARSER = "setup_parser" SETUP_PARSER = "setup_parser"
DESCRIPTION = "description" DESCRIPTION = "description"
command_path = os.path.join(spack.lib_path, "spack", "cmd")
#: Names of all commands #: Names of all commands
all_commands = [] all_commands = []
@ -74,7 +72,7 @@ def cmd_name(python_name):
return python_name.replace('_', '-') return python_name.replace('_', '-')
for file in os.listdir(command_path): for file in os.listdir(spack.paths.command_path):
if file.endswith(".py") and not re.search(ignore_files, file): if file.endswith(".py") and not re.search(ignore_files, file):
cmd = re.sub(r'.py$', '', file) cmd = re.sub(r'.py$', '', file)
all_commands.append(cmd_name(cmd)) all_commands.append(cmd_name(cmd))
@ -320,5 +318,5 @@ def fmt(s):
def spack_is_git_repo(): def spack_is_git_repo():
"""Ensure that this instance of Spack is a git clone.""" """Ensure that this instance of Spack is a git clone."""
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
return os.path.isdir('.git') return os.path.isdir('.git')

View File

@ -30,7 +30,7 @@
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
from llnl.util.tty.colify import colify_table from llnl.util.tty.colify import colify_table
import spack import spack.paths
from spack.util.executable import which from spack.util.executable import which
from spack.cmd import spack_is_git_repo from spack.cmd import spack_is_git_repo
@ -67,7 +67,7 @@ def blame(parser, args):
blame_file = None blame_file = None
if os.path.isfile(args.package_name): if os.path.isfile(args.package_name):
path = os.path.realpath(args.package_name) path = os.path.realpath(args.package_name)
if path.startswith(spack.prefix): if path.startswith(spack.paths.prefix):
blame_file = path blame_file = path
if not blame_file: if not blame_file:
@ -75,7 +75,7 @@ def blame(parser, args):
blame_file = pkg.module.__file__.rstrip('c') # .pyc -> .py blame_file = pkg.module.__file__.rstrip('c') # .pyc -> .py
# get git blame for the package # get git blame for the package
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
if args.view == 'git': if args.view == 'git':
git('blame', blame_file) git('blame', blame_file)
return return

View File

@ -27,7 +27,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp, working_dir from llnl.util.filesystem import mkdirp, working_dir
import spack import spack.paths
from spack.util.executable import ProcessError, which from spack.util.executable import ProcessError, which
_SPACK_UPSTREAM = 'https://github.com/spack/spack' _SPACK_UPSTREAM = 'https://github.com/spack/spack'
@ -47,7 +47,7 @@ def setup_parser(subparser):
def get_origin_info(remote): def get_origin_info(remote):
git_dir = os.path.join(spack.prefix, '.git') git_dir = os.path.join(spack.paths.prefix, '.git')
git = which('git', required=True) git = which('git', required=True)
try: try:
branch = git('symbolic-ref', '--short', 'HEAD', output=str) branch = git('symbolic-ref', '--short', 'HEAD', output=str)

View File

@ -23,7 +23,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import spack import spack.paths
from llnl.util import tty from llnl.util import tty
@ -35,9 +35,10 @@ def print_module_placeholder_help():
"To initialize spack's shell commands, you must run one of", "To initialize spack's shell commands, you must run one of",
"the commands below. Choose the right command for your shell.", "the commands below. Choose the right command for your shell.",
"", "For bash and zsh:", "", "For bash and zsh:",
" . %s/setup-env.sh" % spack.share_path, "", " . %s/setup-env.sh" % spack.paths.share_path, "",
"For csh and tcsh:", " setenv SPACK_ROOT %s" % spack.prefix, "For csh and tcsh:",
" source %s/setup-env.csh" % spack.share_path, "", " setenv SPACK_ROOT %s" % spack.paths.prefix,
" source %s/setup-env.csh" % spack.paths.share_path, "",
"This exposes a 'spack' shell function, which you can use like", "This exposes a 'spack' shell function, which you can use like",
" $ spack load package-foo", "", " $ spack load package-foo", "",
"Running the Spack executable directly (for example, invoking", "Running the Spack executable directly (for example, invoking",

View File

@ -30,7 +30,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack import spack.paths
from spack.util.executable import which from spack.util.executable import which
description = "debugging commands for troubleshooting Spack" description = "debugging commands for troubleshooting Spack"
@ -52,7 +52,7 @@ def _debug_tarball_suffix():
if not git: if not git:
return 'nobranch-nogit-%s' % suffix return 'nobranch-nogit-%s' % suffix
with working_dir(spack.spack_root): with working_dir(spack.paths.prefix):
if not os.path.isdir('.git'): if not os.path.isdir('.git'):
return 'nobranch.nogit.%s' % suffix return 'nobranch.nogit.%s' % suffix

View File

@ -27,8 +27,8 @@
import llnl.util.tty as tty import llnl.util.tty as tty
import spack
import spack.cmd import spack.cmd
import spack.paths
from spack.spec import Spec from spack.spec import Spec
from spack.repository import Repo from spack.repository import Repo
@ -74,23 +74,23 @@ def setup_parser(subparser):
# Edits package files by default # Edits package files by default
excl_args.add_argument( excl_args.add_argument(
'-b', '--build-system', dest='path', action='store_const', '-b', '--build-system', dest='path', action='store_const',
const=spack.build_systems_path, const=spack.paths.build_systems_path,
help="Edit the build system with the supplied name.") help="Edit the build system with the supplied name.")
excl_args.add_argument( excl_args.add_argument(
'-c', '--command', dest='path', action='store_const', '-c', '--command', dest='path', action='store_const',
const=spack.cmd.command_path, const=spack.paths.command_path,
help="edit the command with the supplied name") help="edit the command with the supplied name")
excl_args.add_argument( excl_args.add_argument(
'-d', '--docs', dest='path', action='store_const', '-d', '--docs', dest='path', action='store_const',
const=os.path.join(spack.lib_path, 'docs'), const=os.path.join(spack.paths.lib_path, 'docs'),
help="edit the docs with the supplied name") help="edit the docs with the supplied name")
excl_args.add_argument( excl_args.add_argument(
'-t', '--test', dest='path', action='store_const', '-t', '--test', dest='path', action='store_const',
const=spack.test_path, const=spack.paths.test_path,
help="edit the test with the supplied name") help="edit the test with the supplied name")
excl_args.add_argument( excl_args.add_argument(
'-m', '--module', dest='path', action='store_const', '-m', '--module', dest='path', action='store_const',
const=spack.module_path, const=spack.paths.module_path,
help="edit the main spack module with the supplied name") help="edit the main spack module with the supplied name")
# Options for editing packages # Options for editing packages
@ -110,14 +110,14 @@ def edit(parser, args):
name = args.name name = args.name
# By default, edit package files # By default, edit package files
path = spack.packages_path path = spack.paths.packages_path
# If `--command`, `--test`, or `--module` is chosen, edit those instead # If `--command`, `--test`, or `--module` is chosen, edit those instead
if args.path: if args.path:
path = args.path path = args.path
if name: if name:
# convert command names to python module name # convert command names to python module name
if path == spack.cmd.command_path: if path == spack.paths.command_path:
name = spack.cmd.python_name(name) name = spack.cmd.python_name(name)
path = os.path.join(path, name) path = os.path.join(path, name)

View File

@ -33,7 +33,7 @@
from llnl.util.filesystem import working_dir, mkdirp from llnl.util.filesystem import working_dir, mkdirp
import spack import spack.paths
from spack.util.executable import which from spack.util.executable import which
@ -53,7 +53,7 @@ def is_package(f):
#: List of directories to exclude from checks. #: List of directories to exclude from checks.
exclude_directories = [spack.external_path] exclude_directories = [spack.paths.external_path]
#: This is a dict that maps: #: This is a dict that maps:
@ -243,11 +243,12 @@ def flake8(parser, args):
if file_list: if file_list:
def prefix_relative(path): def prefix_relative(path):
return os.path.relpath( return os.path.relpath(
os.path.abspath(os.path.realpath(path)), spack.prefix) os.path.abspath(os.path.realpath(path)),
spack.paths.prefix)
file_list = [prefix_relative(p) for p in file_list] file_list = [prefix_relative(p) for p in file_list]
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
if not file_list: if not file_list:
file_list = changed_files(args) file_list = changed_files(args)
@ -261,7 +262,7 @@ def prefix_relative(path):
# filter files into a temporary directory with exemptions added. # filter files into a temporary directory with exemptions added.
for filename in file_list: for filename in file_list:
src_path = os.path.join(spack.prefix, filename) src_path = os.path.join(spack.paths.prefix, filename)
dest_path = os.path.join(temp, filename) dest_path = os.path.join(temp, filename)
filter_file(src_path, dest_path, args.output) filter_file(src_path, dest_path, args.output)
@ -275,13 +276,14 @@ def prefix_relative(path):
if file_list: if file_list:
output += flake8( output += flake8(
'--format', 'pylint', '--format', 'pylint',
'--config=%s' % os.path.join(spack.prefix, '.flake8'), '--config=%s' % os.path.join(spack.paths.prefix,
'.flake8'),
*file_list, fail_on_error=False, output=str) *file_list, fail_on_error=False, output=str)
returncode |= flake8.returncode returncode |= flake8.returncode
if package_file_list: if package_file_list:
output += flake8( output += flake8(
'--format', 'pylint', '--format', 'pylint',
'--config=%s' % os.path.join(spack.prefix, '--config=%s' % os.path.join(spack.paths.prefix,
'.flake8_packages'), '.flake8_packages'),
*package_file_list, fail_on_error=False, output=str) *package_file_list, fail_on_error=False, output=str)
returncode |= flake8.returncode returncode |= flake8.returncode
@ -293,7 +295,8 @@ def prefix_relative(path):
# print results relative to current working directory # print results relative to current working directory
def cwd_relative(path): def cwd_relative(path):
return '{0}: ['.format(os.path.relpath( return '{0}: ['.format(os.path.relpath(
os.path.join(spack.prefix, path.group(1)), os.getcwd())) os.path.join(
spack.paths.prefix, path.group(1)), os.getcwd()))
for line in output.split('\n'): for line in output.split('\n'):
print(re.sub(r'^(.*): \[', cwd_relative, line)) print(re.sub(r'^(.*): \[', cwd_relative, line))

View File

@ -22,10 +22,11 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
from spack.util.gpg import Gpg
import argparse
import spack
import os import os
import argparse
import spack.paths
from spack.util.gpg import Gpg
description = "handle GPG actions for spack" description = "handle GPG actions for spack"
section = "packaging" section = "packaging"
@ -148,7 +149,7 @@ def gpg_trust(args):
def gpg_init(args): def gpg_init(args):
import_dir = args.import_dir import_dir = args.import_dir
if import_dir is None: if import_dir is None:
import_dir = spack.gpg_keys_path import_dir = spack.paths.gpg_keys_path
for root, _, filenames in os.walk(import_dir): for root, _, filenames in os.walk(import_dir):
for filename in filenames: for filename in filenames:

View File

@ -30,7 +30,7 @@
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.paths
import spack.build_environment import spack.build_environment
import spack.cmd import spack.cmd
import spack.cmd.common.arguments as arguments import spack.cmd.common.arguments as arguments
@ -137,7 +137,7 @@ def default_log_file(spec):
""" """
fmt = 'test-{x.name}-{x.version}-{hash}.xml' fmt = 'test-{x.name}-{x.version}-{hash}.xml'
basename = fmt.format(x=spec, hash=spec.dag_hash()) basename = fmt.format(x=spec, hash=spec.dag_hash())
dirname = fs.join_path(spack.var_path, 'junit-report') dirname = fs.join_path(spack.paths.var_path, 'junit-report')
fs.mkdirp(dirname) fs.mkdirp(dirname)
return fs.join_path(dirname, basename) return fs.join_path(dirname, basename)

View File

@ -27,7 +27,7 @@
import argparse import argparse
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.paths
import spack.cmd import spack.cmd
description = "print out locations of various directories used by Spack" description = "print out locations of various directories used by Spack"
@ -73,16 +73,16 @@ def setup_parser(subparser):
def location(parser, args): def location(parser, args):
if args.module_dir: if args.module_dir:
print(spack.module_path) print(spack.paths.module_path)
elif args.spack_root: elif args.spack_root:
print(spack.prefix) print(spack.paths.prefix)
elif args.packages: elif args.packages:
print(spack.repo.first_repo().root) print(spack.repo.first_repo().root)
elif args.stages: elif args.stages:
print(spack.stage_path) print(spack.paths.stage_path)
else: else:
specs = spack.cmd.parse_specs(args.spec) specs = spack.cmd.parse_specs(args.spec)

View File

@ -31,7 +31,7 @@
from llnl.util.tty.colify import colify from llnl.util.tty.colify import colify
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack import spack.paths
from spack.util.executable import which from spack.util.executable import which
from spack.cmd import spack_is_git_repo from spack.cmd import spack_is_git_repo
@ -78,11 +78,11 @@ def setup_parser(subparser):
def list_packages(rev): def list_packages(rev):
pkgpath = os.path.join(spack.packages_path, 'packages') pkgpath = os.path.join(spack.paths.packages_path, 'packages')
relpath = pkgpath[len(spack.prefix + os.path.sep):] + os.path.sep relpath = pkgpath[len(spack.paths.prefix + os.path.sep):] + os.path.sep
git = which('git', required=True) git = which('git', required=True)
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
output = git('ls-tree', '--full-tree', '--name-only', rev, relpath, output = git('ls-tree', '--full-tree', '--name-only', rev, relpath,
output=str) output=str)
return sorted(line[len(relpath):] for line in output.split('\n') if line) return sorted(line[len(relpath):] for line in output.split('\n') if line)
@ -96,8 +96,8 @@ def pkg_add(args):
pkg_name, filename) pkg_name, filename)
git = which('git', required=True) git = which('git', required=True)
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
git('-C', spack.packages_path, 'add', filename) git('-C', spack.paths.packages_path, 'add', filename)
def pkg_list(args): def pkg_list(args):

View File

@ -34,7 +34,7 @@
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
from llnl.util.tty.colify import colify from llnl.util.tty.colify import colify
import spack import spack.paths
description = "run spack's unit tests" description = "run spack's unit tests"
section = "developer" section = "developer"
@ -97,7 +97,7 @@ def test(parser, args, unknown_args):
return return
# pytest.ini lives in the root of the spack repository. # pytest.ini lives in the root of the spack repository.
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
# --list and --long-list print the test output better. # --list and --long-list print the test output better.
if args.list or args.long_list: if args.list or args.long_list:
do_list(args, unknown_args) do_list(args, unknown_args)

View File

@ -25,12 +25,12 @@
"""This module contains functions related to finding compilers on the """This module contains functions related to finding compilers on the
system and configuring Spack to use multiple compilers. system and configuring Spack to use multiple compilers.
""" """
import os
import imp import imp
from llnl.util.lang import list_modules from llnl.util.lang import list_modules
from llnl.util.filesystem import join_path
import spack import spack.paths
import spack.error import spack.error
import spack.spec import spack.spec
import spack.config import spack.config
@ -204,7 +204,8 @@ def supported_compilers():
See available_compilers() to get a list of all the available See available_compilers() to get a list of all the available
versions of supported compilers. versions of supported compilers.
""" """
return sorted(name for name in list_modules(spack.compilers_path)) return sorted(
name for name in list_modules(spack.paths.compilers_path))
@_auto_compiler_spec @_auto_compiler_spec
@ -357,7 +358,7 @@ def class_for_compiler_name(compiler_name):
"""Given a compiler module name, get the corresponding Compiler class.""" """Given a compiler module name, get the corresponding Compiler class."""
assert(supported(compiler_name)) assert(supported(compiler_name))
file_path = join_path(spack.compilers_path, compiler_name + ".py") file_path = os.path.join(spack.paths.compilers_path, compiler_name + ".py")
compiler_mod = imp.load_source(_imported_compilers_module, file_path) compiler_mod = imp.load_source(_imported_compilers_module, file_path)
cls = getattr(compiler_mod, mod_to_class(compiler_name)) cls = getattr(compiler_mod, mod_to_class(compiler_name))

View File

@ -29,7 +29,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.paths
from spack.compiler import Compiler, _version_cache from spack.compiler import Compiler, _version_cache
from spack.util.executable import Executable from spack.util.executable import Executable
from spack.version import ver from spack.version import ver
@ -48,7 +48,7 @@ class Clang(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['flang', 'gfortran'] fc_names = ['flang', 'gfortran']
# Named wrapper links within spack.build_env_path # Named wrapper links within lib/spack/env
link_paths = {'cc': 'clang/clang', link_paths = {'cc': 'clang/clang',
'cxx': 'clang/clang++'} 'cxx': 'clang/clang++'}
@ -228,7 +228,7 @@ def setup_custom_environment(self, pkg, env):
raise OSError(msg) raise OSError(msg)
real_root = os.path.dirname(os.path.dirname(real_root)) real_root = os.path.dirname(os.path.dirname(real_root))
developer_root = os.path.join(spack.stage_path, developer_root = os.path.join(spack.paths.stage_path,
'xcode-select', 'xcode-select',
self.name, self.name,
str(self.version)) str(self.version))
@ -267,8 +267,9 @@ def setup_custom_environment(self, pkg, env):
for fname in os.listdir(dev_dir): for fname in os.listdir(dev_dir):
if fname in bins: if fname in bins:
os.unlink(os.path.join(dev_dir, fname)) os.unlink(os.path.join(dev_dir, fname))
os.symlink(os.path.join(spack.build_env_path, 'cc'), os.symlink(
os.path.join(dev_dir, fname)) os.path.join(spack.paths.build_env_path, 'cc'),
os.path.join(dev_dir, fname))
os.symlink(developer_root, xcode_link) os.symlink(developer_root, xcode_link)

View File

@ -24,7 +24,7 @@
############################################################################## ##############################################################################
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.compilers.clang
from spack.compiler import Compiler, get_compiler_version from spack.compiler import Compiler, get_compiler_version
from spack.version import ver from spack.version import ver
@ -47,7 +47,7 @@ class Gcc(Compiler):
# Old compatibility versions may contain XY suffixes. # Old compatibility versions may contain XY suffixes.
suffixes = [r'-mp-\d\.\d', r'-\d\.\d', r'-\d', r'\d\d'] suffixes = [r'-mp-\d\.\d', r'-\d\.\d', r'-\d', r'\d\d']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
link_paths = {'cc': 'gcc/gcc', link_paths = {'cc': 'gcc/gcc',
'cxx': 'gcc/g++', 'cxx': 'gcc/g++',
'f77': 'gcc/gfortran', 'f77': 'gcc/gfortran',

View File

@ -41,7 +41,7 @@ class Intel(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['ifort'] fc_names = ['ifort']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
link_paths = {'cc': 'intel/icc', link_paths = {'cc': 'intel/icc',
'cxx': 'intel/icpc', 'cxx': 'intel/icpc',
'f77': 'intel/ifort', 'f77': 'intel/ifort',

View File

@ -38,7 +38,7 @@ class Nag(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['nagfor'] fc_names = ['nagfor']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
# Use default wrappers for C and C++, in case provided in compilers.yaml # Use default wrappers for C and C++, in case provided in compilers.yaml
link_paths = { link_paths = {
'cc': 'cc', 'cc': 'cc',

View File

@ -38,7 +38,7 @@ class Pgi(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['pgfortran', 'pgf95', 'pgf90'] fc_names = ['pgfortran', 'pgf95', 'pgf90']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
link_paths = {'cc': 'pgi/pgcc', link_paths = {'cc': 'pgi/pgcc',
'cxx': 'pgi/pgc++', 'cxx': 'pgi/pgc++',
'f77': 'pgi/pgfortran', 'f77': 'pgi/pgfortran',

View File

@ -41,7 +41,7 @@ class Xl(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['xlf90', 'xlf95', 'xlf2003', 'xlf2008'] fc_names = ['xlf90', 'xlf95', 'xlf2003', 'xlf2008']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
link_paths = {'cc': 'xl/xlc', link_paths = {'cc': 'xl/xlc',
'cxx': 'xl/xlc++', 'cxx': 'xl/xlc++',
'f77': 'xl/xlf', 'f77': 'xl/xlf',

View File

@ -42,7 +42,7 @@ class XlR(Compiler):
# Subclasses use possible names of Fortran 90 compiler # Subclasses use possible names of Fortran 90 compiler
fc_names = ['xlf90_r', 'xlf95_r', 'xlf2003_r', 'xlf2008_r'] fc_names = ['xlf90_r', 'xlf95_r', 'xlf2003_r', 'xlf2008_r']
# Named wrapper links within spack.build_env_path # Named wrapper links within build_env_path
link_paths = {'cc': 'xl_r/xlc_r', link_paths = {'cc': 'xl_r/xlc_r',
'cxx': 'xl_r/xlc++_r', 'cxx': 'xl_r/xlc++_r',
'f77': 'xl_r/xlf_r', 'f77': 'xl_r/xlf_r',

View File

@ -64,7 +64,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp from llnl.util.filesystem import mkdirp
import spack import spack.paths
import spack.architecture import spack.architecture
import spack.schema import spack.schema
from spack.error import SpackError from spack.error import SpackError
@ -218,24 +218,24 @@ def __repr__(self):
#: Default configuration scope is the lowest-level scope. These are #: Default configuration scope is the lowest-level scope. These are
#: versioned with Spack and can be overridden by systems, sites or users. #: versioned with Spack and can be overridden by systems, sites or users.
_defaults_path = os.path.join(spack.etc_path, 'spack', 'defaults') _defaults_path = os.path.join(spack.paths.etc_path, 'spack', 'defaults')
ConfigScope('defaults', _defaults_path) ConfigScope('defaults', _defaults_path)
ConfigScope('defaults/%s' % _platform, os.path.join(_defaults_path, _platform)) ConfigScope('defaults/%s' % _platform, os.path.join(_defaults_path, _platform))
#: System configuration is per machine. #: System configuration is per machine.
#: No system-level configs should be checked into spack by default #: No system-level configs should be checked into spack by default
_system_path = os.path.join(spack.system_etc_path, 'spack') _system_path = os.path.join(spack.paths.system_etc_path, 'spack')
ConfigScope('system', _system_path) ConfigScope('system', _system_path)
ConfigScope('system/%s' % _platform, os.path.join(_system_path, _platform)) ConfigScope('system/%s' % _platform, os.path.join(_system_path, _platform))
#: Site configuration is per spack instance, for sites or projects. #: Site configuration is per spack instance, for sites or projects.
#: No site-level configs should be checked into spack by default. #: No site-level configs should be checked into spack by default.
_site_path = os.path.join(spack.etc_path, 'spack') _site_path = os.path.join(spack.paths.etc_path, 'spack')
ConfigScope('site', _site_path) ConfigScope('site', _site_path)
ConfigScope('site/%s' % _platform, os.path.join(_site_path, _platform)) ConfigScope('site/%s' % _platform, os.path.join(_site_path, _platform))
#: User configuration can override both spack defaults and site config. #: User configuration can override both spack defaults and site config.
_user_path = spack.user_config_path _user_path = spack.paths.user_config_path
ConfigScope('user', _user_path) ConfigScope('user', _user_path)
ConfigScope('user/%s' % _platform, os.path.join(_user_path, _platform)) ConfigScope('user/%s' % _platform, os.path.join(_user_path, _platform))

View File

@ -43,7 +43,7 @@
""" """
import imp import imp
import spack import spack.paths
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path
from llnl.util.lang import memoized, list_modules from llnl.util.lang import memoized, list_modules
@ -51,9 +51,9 @@
@memoized @memoized
def all_hook_modules(): def all_hook_modules():
modules = [] modules = []
for name in list_modules(spack.hooks_path): for name in list_modules(spack.paths.hooks_path):
mod_name = __name__ + '.' + name mod_name = __name__ + '.' + name
path = join_path(spack.hooks_path, name) + ".py" path = join_path(spack.paths.hooks_path, name) + ".py"
mod = imp.load_source(mod_name, path) mod = imp.load_source(mod_name, path)
modules.append(mod) modules.append(mod)

View File

@ -28,7 +28,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack.paths
import spack.modules import spack.modules
# Character limit for shebang line. Using Linux's 127 characters # Character limit for shebang line. Using Linux's 127 characters
@ -56,7 +56,7 @@ def filter_shebang(path):
original = original_file.read() original = original_file.read()
# This line will be prepended to file # This line will be prepended to file
new_sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.spack_root new_sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.paths.prefix
# Skip files that are already using sbang. # Skip files that are already using sbang.
if original.startswith(new_sbang_line): if original.startswith(new_sbang_line):

View File

@ -41,28 +41,29 @@
from llnl.util.tty.log import log_output from llnl.util.tty.log import log_output
import spack import spack
import spack.paths
from spack.error import SpackError from spack.error import SpackError
# names of profile statistics #: names of profile statistics
stat_names = pstats.Stats.sort_arg_dict_default stat_names = pstats.Stats.sort_arg_dict_default
# help levels in order of detail (i.e., number of commands shown) #: help levels in order of detail (i.e., number of commands shown)
levels = ['short', 'long'] levels = ['short', 'long']
# intro text for help at different levels #: intro text for help at different levels
intro_by_level = { intro_by_level = {
'short': 'These are common spack commands:', 'short': 'These are common spack commands:',
'long': 'Complete list of spack commands:', 'long': 'Complete list of spack commands:',
} }
# control top-level spack options shown in basic vs. advanced help #: control top-level spack options shown in basic vs. advanced help
options_by_level = { options_by_level = {
'short': ['h', 'k', 'V', 'color'], 'short': ['h', 'k', 'V', 'color'],
'long': 'all' 'long': 'all'
} }
# Longer text for each section, to show in help #: Longer text for each section, to show in help
section_descriptions = { section_descriptions = {
'admin': 'administration', 'admin': 'administration',
'basic': 'query packages', 'basic': 'query packages',
@ -76,8 +77,8 @@
'system': 'system', 'system': 'system',
} }
# preferential command order for some sections (e.g., build pipeline is #: preferential command order for some sections (e.g., build pipeline is
# in execution order, not alphabetical) #: in execution order, not alphabetical)
section_order = { section_order = {
'basic': ['list', 'info', 'find'], 'basic': ['list', 'info', 'find'],
'build': ['fetch', 'stage', 'patch', 'configure', 'build', 'restage', 'build': ['fetch', 'stage', 'patch', 'configure', 'build', 'restage',
@ -85,17 +86,21 @@
'packaging': ['create', 'edit'] 'packaging': ['create', 'edit']
} }
# Properties that commands are required to set. #: Properties that commands are required to set.
required_command_properties = ['level', 'section', 'description'] required_command_properties = ['level', 'section', 'description']
#: Recorded directory where spack command was originally invoked
spack_working_dir = None
def set_working_dir(): def set_working_dir():
"""Change the working directory to getcwd, or spack prefix if no cwd.""" """Change the working directory to getcwd, or spack prefix if no cwd."""
global spack_working_dir
try: try:
spack.spack_working_dir = os.getcwd() spack_working_dir = os.getcwd()
except OSError: except OSError:
os.chdir(spack.spack_prefix) os.chdir(spack.paths.prefix)
spack.spack_working_dir = spack.spack_prefix spack_working_dir = spack.paths.prefix
def add_all_commands(parser): def add_all_commands(parser):
@ -347,7 +352,7 @@ def setup_main_options(args):
if args.mock: if args.mock:
from spack.repository import RepoPath from spack.repository import RepoPath
spack.repo.swap(RepoPath(spack.mock_packages_path)) spack.repo.swap(RepoPath(spack.paths.mock_packages_path))
# If the user asked for it, don't check ssl certs. # If the user asked for it, don't check ssl certs.
if args.insecure: if args.insecure:

View File

@ -56,7 +56,8 @@
import six import six
import llnl.util.filesystem import llnl.util.filesystem
import llnl.util.tty as tty import llnl.util.tty as tty
import spack
import spack.paths
import spack.build_environment as build_environment import spack.build_environment as build_environment
import spack.environment import spack.environment
import spack.tengine as tengine import spack.tengine as tengine
@ -229,7 +230,7 @@ def root_path(name):
Returns: Returns:
root folder for module file installation root folder for module file installation
""" """
path = roots.get(name, os.path.join(spack.share_path, name)) path = roots.get(name, os.path.join(spack.paths.share_path, name))
return spack.util.path.canonicalize_path(path) return spack.util.path.canonicalize_path(path)

View File

@ -52,7 +52,9 @@
from six import with_metaclass from six import with_metaclass
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack
import spack.paths
import spack.store import spack.store
import spack.compilers import spack.compilers
import spack.directives import spack.directives
@ -67,7 +69,7 @@
import spack.multimethod import spack.multimethod
import spack.binary_distribution as binary_distribution import spack.binary_distribution as binary_distribution
from llnl.util.filesystem import mkdirp, join_path, touch, ancestor from llnl.util.filesystem import mkdirp, join_path, touch
from llnl.util.filesystem import working_dir, install_tree, install from llnl.util.filesystem import working_dir, install_tree, install
from llnl.util.lang import memoized from llnl.util.lang import memoized
from llnl.util.link_tree import LinkTree from llnl.util.link_tree import LinkTree
@ -688,8 +690,7 @@ def package_dir(self):
def global_license_dir(self): def global_license_dir(self):
"""Returns the directory where global license files for all """Returns the directory where global license files for all
packages are stored.""" packages are stored."""
spack_root = ancestor(__file__, 4) return os.path.join(spack.paths.prefix, 'etc', 'spack', 'licenses')
return join_path(spack_root, 'etc', 'spack', 'licenses')
@property @property
def global_license_file(self): def global_license_file(self):
@ -697,8 +698,8 @@ def global_license_file(self):
particular package should be stored.""" particular package should be stored."""
if not self.license_files: if not self.license_files:
return return
return join_path(self.global_license_dir, self.name, return os.path.join(self.global_license_dir, self.name,
os.path.basename(self.license_files[0])) os.path.basename(self.license_files[0]))
@property @property
def version(self): def version(self):
@ -1107,9 +1108,9 @@ def do_patch(self):
# Construct paths to special files in the archive dir used to # Construct paths to special files in the archive dir used to
# keep track of whether patches were successfully applied. # keep track of whether patches were successfully applied.
archive_dir = self.stage.source_path archive_dir = self.stage.source_path
good_file = join_path(archive_dir, '.spack_patched') good_file = os.path.join(archive_dir, '.spack_patched')
no_patches_file = join_path(archive_dir, '.spack_no_patches') no_patches_file = os.path.join(archive_dir, '.spack_no_patches')
bad_file = join_path(archive_dir, '.spack_patch_failed') bad_file = os.path.join(archive_dir, '.spack_patch_failed')
# If we encounter an archive that failed to patch, restage it # If we encounter an archive that failed to patch, restage it
# so that we can apply all the patches again. # so that we can apply all the patches again.
@ -1619,7 +1620,7 @@ def check_for_unfinished_installation(
partial = True partial = True
stage_is_managed_in_spack = self.stage.path.startswith( stage_is_managed_in_spack = self.stage.path.startswith(
spack.stage_path) spack.paths.stage_path)
if restage and stage_is_managed_in_spack: if restage and stage_is_managed_in_spack:
self.stage.destroy() self.stage.destroy()
self.stage.create() self.stage.create()

80
lib/spack/spack/paths.py Normal file
View File

@ -0,0 +1,80 @@
##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
"""Defines paths that are part of Spack's directory structure.
Do not import other ``spack`` modules here. This module is used
throughout Spack and should bring in a minimal number of external
dependencies.
"""
import os
from llnl.util.filesystem import ancestor
#: This file lives in $prefix/lib/spack/spack/__file__
prefix = ancestor(__file__, 4)
#: synonym for prefix
spack_root = prefix
#: bin directory in the spack prefix
bin_path = os.path.join(prefix, "bin")
#: The spack script itself
spack_script = os.path.join(bin_path, "spack")
# spack directory hierarchy
lib_path = os.path.join(prefix, "lib", "spack")
external_path = os.path.join(lib_path, "external")
build_env_path = os.path.join(lib_path, "env")
module_path = os.path.join(lib_path, "spack")
command_path = os.path.join(module_path, "cmd")
platform_path = os.path.join(module_path, 'platforms')
compilers_path = os.path.join(module_path, "compilers")
build_systems_path = os.path.join(module_path, 'build_systems')
operating_system_path = os.path.join(module_path, 'operating_systems')
test_path = os.path.join(module_path, "test")
hooks_path = os.path.join(module_path, "hooks")
var_path = os.path.join(prefix, "var", "spack")
stage_path = os.path.join(var_path, "stage")
repos_path = os.path.join(var_path, "repos")
share_path = os.path.join(prefix, "share", "spack")
# Paths to built-in Spack repositories.
packages_path = os.path.join(repos_path, "builtin")
mock_packages_path = os.path.join(repos_path, "builtin.mock")
#: User configuration location
user_config_path = os.path.expanduser('~/.spack')
opt_path = os.path.join(prefix, "opt")
etc_path = os.path.join(prefix, "etc")
system_etc_path = '/etc'
# GPG paths.
gpg_keys_path = os.path.join(var_path, "gpg")
mock_gpg_data_path = os.path.join(var_path, "gpg.mock", "data")
mock_gpg_keys_path = os.path.join(var_path, "gpg.mock", "keys")
gpg_path = os.path.join(opt_path, "spack", "gpg")

View File

@ -25,7 +25,7 @@
import os import os
import re import re
import llnl.util.tty as tty import llnl.util.tty as tty
from spack import build_env_path from spack.paths import build_env_path
from spack.util.executable import which from spack.util.executable import which
from spack.architecture import Platform, Target, NoPlatformError from spack.architecture import Platform, Target, NoPlatformError
from spack.operating_systems.cray_frontend import CrayFrontend from spack.operating_systems.cray_frontend import CrayFrontend

View File

@ -115,6 +115,7 @@
from llnl.util.tty.color import cwrite, colorize, cescape, get_color_when from llnl.util.tty.color import cwrite, colorize, cescape, get_color_when
import spack import spack
import spack.architecture import spack.architecture
import spack.compilers as compilers import spack.compilers as compilers
import spack.error import spack.error
@ -3090,7 +3091,7 @@ def write(s, c):
if self.dependencies: if self.dependencies:
out.write(fmt % token_transform(str(self.dag_hash(7)))) out.write(fmt % token_transform(str(self.dag_hash(7))))
elif named_str == 'SPACK_ROOT': elif named_str == 'SPACK_ROOT':
out.write(fmt % token_transform(spack.prefix)) out.write(fmt % token_transform(spack.paths.prefix))
elif named_str == 'SPACK_INSTALL': elif named_str == 'SPACK_INSTALL':
out.write(fmt % token_transform(spack.store.root)) out.write(fmt % token_transform(spack.store.root))
elif named_str == 'PREFIX': elif named_str == 'PREFIX':

View File

@ -38,7 +38,7 @@
from llnl.util.filesystem import mkdirp, join_path, can_access from llnl.util.filesystem import mkdirp, join_path, can_access
from llnl.util.filesystem import remove_if_dead_link, remove_linked_tree from llnl.util.filesystem import remove_if_dead_link, remove_linked_tree
import spack import spack.paths
import spack.config import spack.config
import spack.error import spack.error
import spack.fetch_strategy as fs import spack.fetch_strategy as fs
@ -93,7 +93,7 @@ def get_tmp_root():
raise StageError("No accessible stage paths in %s", candidates) raise StageError("No accessible stage paths in %s", candidates)
# Return None to indicate we're using a local staging area. # Return None to indicate we're using a local staging area.
if path == canonicalize_path(spack.stage_path): if path == canonicalize_path(spack.paths.stage_path):
_use_tmp_stage = False _use_tmp_stage = False
return None return None
@ -147,7 +147,7 @@ class Stage(object):
If spack.use_tmp_stage is True, spack will attempt to create If spack.use_tmp_stage is True, spack will attempt to create
stages in a tmp directory. Otherwise, stages are created directly stages in a tmp directory. Otherwise, stages are created directly
in spack.stage_path. in spack.paths.stage_path.
There are two kinds of stages: named and unnamed. Named stages There are two kinds of stages: named and unnamed. Named stages
can persist between runs of spack, e.g. if you fetched a tarball can persist between runs of spack, e.g. if you fetched a tarball
@ -216,7 +216,7 @@ def __init__(
if path is not None: if path is not None:
self.path = path self.path = path
else: else:
self.path = join_path(spack.stage_path, self.name) self.path = join_path(spack.paths.stage_path, self.name)
# Flag to decide whether to delete the stage folder on exit or not # Flag to decide whether to delete the stage folder on exit or not
self.keep = keep self.keep = keep
@ -229,7 +229,7 @@ def __init__(
if self.name not in Stage.stage_locks: if self.name not in Stage.stage_locks:
sha1 = hashlib.sha1(self.name.encode('utf-8')).digest() sha1 = hashlib.sha1(self.name.encode('utf-8')).digest()
lock_id = prefix_bits(sha1, bit_length(sys.maxsize)) lock_id = prefix_bits(sha1, bit_length(sys.maxsize))
stage_lock_path = join_path(spack.stage_path, '.lock') stage_lock_path = join_path(spack.paths.stage_path, '.lock')
Stage.stage_locks[self.name] = llnl.util.lock.Lock( Stage.stage_locks[self.name] = llnl.util.lock.Lock(
stage_lock_path, lock_id, 1) stage_lock_path, lock_id, 1)
@ -478,17 +478,17 @@ def create(self):
"""Creates the stage directory. """Creates the stage directory.
If get_tmp_root() is None, the stage directory is created If get_tmp_root() is None, the stage directory is created
directly under spack.stage_path, otherwise this will attempt to directly under spack.paths.stage_path, otherwise this will attempt to
create a stage in a temporary directory and link it into create a stage in a temporary directory and link it into
spack.stage_path. spack.paths.stage_path.
Spack will use the first writable location in spack.tmp_dirs Spack will use the first writable location in spack.tmp_dirs
to create a stage. If there is no valid location in tmp_dirs, to create a stage. If there is no valid location in tmp_dirs,
fall back to making the stage inside spack.stage_path. fall back to making the stage inside spack.paths.stage_path.
""" """
# Create the top-level stage directory # Create the top-level stage directory
mkdirp(spack.stage_path) mkdirp(spack.paths.stage_path)
remove_if_dead_link(self.path) remove_if_dead_link(self.path)
# If a tmp_root exists then create a directory there and then link it # If a tmp_root exists then create a directory there and then link it
@ -655,7 +655,7 @@ def _get_mirrors():
return [val for name, val in iteritems(config)] return [val for name, val in iteritems(config)]
def ensure_access(file=spack.stage_path): def ensure_access(file=spack.paths.stage_path):
"""Ensure we can access a directory and die with an error if we can't.""" """Ensure we can access a directory and die with an error if we can't."""
if not can_access(file): if not can_access(file):
tty.die("Insufficient permissions for %s" % file) tty.die("Insufficient permissions for %s" % file)
@ -663,9 +663,9 @@ def ensure_access(file=spack.stage_path):
def purge(): def purge():
"""Remove all build directories in the top-level stage path.""" """Remove all build directories in the top-level stage path."""
if os.path.isdir(spack.stage_path): if os.path.isdir(spack.paths.stage_path):
for stage_dir in os.listdir(spack.stage_path): for stage_dir in os.listdir(spack.paths.stage_path):
stage_path = join_path(spack.stage_path, stage_dir) stage_path = join_path(spack.paths.stage_path, stage_dir)
remove_linked_tree(stage_path) remove_linked_tree(stage_path)

View File

@ -43,7 +43,7 @@
""" """
import os import os
import spack import spack.paths
import spack.config import spack.config
from spack.util.path import canonicalize_path from spack.util.path import canonicalize_path
from spack.database import Database from spack.database import Database
@ -62,7 +62,7 @@
# Set up the install path # Set up the install path
# #
root = canonicalize_path( root = canonicalize_path(
config.get('install_tree', os.path.join(spack.opt_path, 'spack'))) config.get('install_tree', os.path.join(spack.paths.opt_path, 'spack')))
# #
# Set up the installed packages database # Set up the installed packages database

View File

@ -25,7 +25,7 @@
import os import os
import pytest import pytest
import spack from spack.paths import build_env_path
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path
from spack.build_environment import dso_suffix, _static_to_shared_library from spack.build_environment import dso_suffix, _static_to_shared_library
from spack.util.executable import Executable from spack.util.executable import Executable
@ -33,9 +33,9 @@
@pytest.fixture @pytest.fixture
def build_environment(): def build_environment():
cc = Executable(join_path(spack.build_env_path, "cc")) cc = Executable(join_path(build_env_path, "cc"))
cxx = Executable(join_path(spack.build_env_path, "c++")) cxx = Executable(join_path(build_env_path, "c++"))
fc = Executable(join_path(spack.build_env_path, "fc")) fc = Executable(join_path(build_env_path, "fc"))
realcc = "/bin/mycc" realcc = "/bin/mycc"
prefix = "/spack-test-prefix" prefix = "/spack-test-prefix"

View File

@ -31,7 +31,7 @@
import tempfile import tempfile
import shutil import shutil
import spack from spack.paths import build_env_path
from llnl.util.filesystem import mkdirp, join_path from llnl.util.filesystem import mkdirp, join_path
from spack.util.executable import Executable from spack.util.executable import Executable
@ -54,11 +54,11 @@
class CompilerWrapperTest(unittest.TestCase): class CompilerWrapperTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.cc = Executable(join_path(spack.build_env_path, "cc")) self.cc = Executable(join_path(build_env_path, "cc"))
self.ld = Executable(join_path(spack.build_env_path, "ld")) self.ld = Executable(join_path(build_env_path, "ld"))
self.cpp = Executable(join_path(spack.build_env_path, "cpp")) self.cpp = Executable(join_path(build_env_path, "cpp"))
self.cxx = Executable(join_path(spack.build_env_path, "c++")) self.cxx = Executable(join_path(build_env_path, "c++"))
self.fc = Executable(join_path(spack.build_env_path, "fc")) self.fc = Executable(join_path(build_env_path, "fc"))
self.realcc = "/bin/mycc" self.realcc = "/bin/mycc"
self.prefix = "/spack-test-prefix" self.prefix = "/spack-test-prefix"

View File

@ -26,7 +26,7 @@
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack import spack.paths
import spack.cmd import spack.cmd
from spack.main import SpackCommand from spack.main import SpackCommand
from spack.util.executable import which from spack.util.executable import which
@ -56,7 +56,7 @@ def test_blame_by_percent(builtin_mock):
def test_blame_file(builtin_mock): def test_blame_file(builtin_mock):
"""Sanity check the blame command to make sure it works.""" """Sanity check the blame command to make sure it works."""
with working_dir(spack.prefix): with working_dir(spack.paths.prefix):
out = blame('bin/spack') out = blame('bin/spack')
assert 'LAST_COMMIT' in out assert 'LAST_COMMIT' in out
assert 'AUTHOR' in out assert 'AUTHOR' in out

View File

@ -29,7 +29,7 @@
from llnl.util.filesystem import FileFilter from llnl.util.filesystem import FileFilter
import spack import spack.paths
from spack.cmd.flake8 import flake8, setup_parser, changed_files from spack.cmd.flake8 import flake8, setup_parser, changed_files
from spack.repository import Repo from spack.repository import Repo
from spack.util.executable import which from spack.util.executable import which
@ -50,7 +50,7 @@ def flake8_package():
mock package, yields the filename, then undoes the mock package, yields the filename, then undoes the
change on cleanup. change on cleanup.
""" """
repo = Repo(spack.mock_packages_path) repo = Repo(spack.paths.mock_packages_path)
filename = repo.filename_for_package_name('flake8') filename = repo.filename_for_package_name('flake8')
package = FileFilter(filename) package = FileFilter(filename)
@ -69,7 +69,7 @@ def test_changed_files(parser, flake8_package):
# changed_files returns file paths relative to the root # changed_files returns file paths relative to the root
# directory of Spack. Convert to absolute file paths. # directory of Spack. Convert to absolute file paths.
files = changed_files(args) files = changed_files(args)
files = [os.path.join(spack.spack_root, path) for path in files] files = [os.path.join(spack.paths.prefix, path) for path in files]
# There will likely be other files that have changed # There will likely be other files that have changed
# when these tests are run # when these tests are run

View File

@ -25,7 +25,8 @@
import os import os
import pytest import pytest
import spack
from spack.paths import mock_gpg_data_path, mock_gpg_keys_path
import spack.util.gpg as gpg_util import spack.util.gpg as gpg_util
from spack.main import SpackCommand from spack.main import SpackCommand
from spack.util.executable import ProcessError from spack.util.executable import ProcessError
@ -58,10 +59,10 @@ def has_gnupg2():
def test_gpg(gpg, tmpdir, testing_gpg_directory): def test_gpg(gpg, tmpdir, testing_gpg_directory):
# Verify a file with an empty keyring. # Verify a file with an empty keyring.
with pytest.raises(ProcessError): with pytest.raises(ProcessError):
gpg('verify', os.path.join(spack.mock_gpg_data_path, 'content.txt')) gpg('verify', os.path.join(mock_gpg_data_path, 'content.txt'))
# Import the default key. # Import the default key.
gpg('init', '--from', spack.mock_gpg_keys_path) gpg('init', '--from', mock_gpg_keys_path)
# List the keys. # List the keys.
# TODO: Test the output here. # TODO: Test the output here.
@ -69,14 +70,14 @@ def test_gpg(gpg, tmpdir, testing_gpg_directory):
gpg('list', '--signing') gpg('list', '--signing')
# Verify the file now that the key has been trusted. # Verify the file now that the key has been trusted.
gpg('verify', os.path.join(spack.mock_gpg_data_path, 'content.txt')) gpg('verify', os.path.join(mock_gpg_data_path, 'content.txt'))
# Untrust the default key. # Untrust the default key.
gpg('untrust', 'Spack testing') gpg('untrust', 'Spack testing')
# Now that the key is untrusted, verification should fail. # Now that the key is untrusted, verification should fail.
with pytest.raises(ProcessError): with pytest.raises(ProcessError):
gpg('verify', os.path.join(spack.mock_gpg_data_path, 'content.txt')) gpg('verify', os.path.join(mock_gpg_data_path, 'content.txt'))
# Create a file to test signing. # Create a file to test signing.
test_path = tmpdir.join('to-sign.txt') test_path = tmpdir.join('to-sign.txt')

View File

@ -44,8 +44,9 @@ def test_name_parsed_correctly():
assert name_parsed_correctly(MyPackage('r-devtools', []), 'devtools') assert name_parsed_correctly(MyPackage('r-devtools', []), 'devtools')
assert name_parsed_correctly(MyPackage('py-numpy', []), 'numpy') assert name_parsed_correctly(MyPackage('py-numpy', []), 'numpy')
assert name_parsed_correctly(MyPackage('octave-splines', []), 'splines') assert name_parsed_correctly(MyPackage('octave-splines', []), 'splines')
assert name_parsed_correctly(MyPackage('imagemagick', []), 'ImageMagick') # noqa
assert name_parsed_correctly(MyPackage('th-data', []), 'TH.data') assert name_parsed_correctly(MyPackage('th-data', []), 'TH.data')
assert name_parsed_correctly(
MyPackage('imagemagick', []), 'ImageMagick')
# Expected False # Expected False
assert not name_parsed_correctly(MyPackage('', []), 'hdf5') assert not name_parsed_correctly(MyPackage('', []), 'hdf5')
@ -53,7 +54,8 @@ def test_name_parsed_correctly():
assert not name_parsed_correctly(MyPackage('yaml-cpp', []), 'yamlcpp') assert not name_parsed_correctly(MyPackage('yaml-cpp', []), 'yamlcpp')
assert not name_parsed_correctly(MyPackage('yamlcpp', []), 'yaml-cpp') assert not name_parsed_correctly(MyPackage('yamlcpp', []), 'yaml-cpp')
assert not name_parsed_correctly(MyPackage('r-py-parser', []), 'parser') assert not name_parsed_correctly(MyPackage('r-py-parser', []), 'parser')
assert not name_parsed_correctly(MyPackage('oce', []), 'oce-0.18.0') # noqa assert not name_parsed_correctly(
MyPackage('oce', []), 'oce-0.18.0')
def test_version_parsed_correctly(): def test_version_parsed_correctly():
@ -70,7 +72,8 @@ def test_version_parsed_correctly():
assert not version_parsed_correctly(MyPackage('', ['1.2.3']), '1.2.4') assert not version_parsed_correctly(MyPackage('', ['1.2.3']), '1.2.4')
assert not version_parsed_correctly(MyPackage('', ['3.4a']), '3.4') assert not version_parsed_correctly(MyPackage('', ['3.4a']), '3.4')
assert not version_parsed_correctly(MyPackage('', ['3.4']), '3.4b') assert not version_parsed_correctly(MyPackage('', ['3.4']), '3.4b')
assert not version_parsed_correctly(MyPackage('', ['0.18.0']), 'oce-0.18.0') # noqa assert not version_parsed_correctly(
MyPackage('', ['0.18.0']), 'oce-0.18.0')
def test_url_parse(): def test_url_parse():
@ -120,8 +123,10 @@ def test_url_summary():
(total_urls, correct_names, correct_versions, (total_urls, correct_names, correct_versions,
name_count_dict, version_count_dict) = url_summary(None) name_count_dict, version_count_dict) = url_summary(None)
assert 0 < correct_names <= sum(name_count_dict.values()) <= total_urls # noqa assert (0 < correct_names <=
assert 0 < correct_versions <= sum(version_count_dict.values()) <= total_urls # noqa sum(name_count_dict.values()) <= total_urls)
assert (0 < correct_versions <=
sum(version_count_dict.values()) <= total_urls)
# make sure it agrees with the actual command. # make sure it agrees with the actual command.
out = url('summary') out = url('summary')

View File

@ -22,17 +22,18 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os
import collections import collections
import getpass import getpass
import os
import tempfile import tempfile
import spack.util.ordereddict
import pytest import pytest
import spack
import spack.config
import yaml import yaml
import spack.paths
import spack.config
from spack.util.path import canonicalize_path from spack.util.path import canonicalize_path
from spack.util.ordereddict import OrderedDict
# Some sample compiler config data # Some sample compiler config data
a_comps = { a_comps = {
@ -242,7 +243,7 @@ def config(tmpdir):
"""Mocks the configuration scope.""" """Mocks the configuration scope."""
spack.config.clear_config_caches() spack.config.clear_config_caches()
real_scope = spack.config.config_scopes real_scope = spack.config.config_scopes
spack.config.config_scopes = spack.util.ordereddict.OrderedDict() spack.config.config_scopes = OrderedDict()
for priority in ['low', 'high']: for priority in ['low', 'high']:
spack.config.ConfigScope(priority, str(tmpdir.join(priority))) spack.config.ConfigScope(priority, str(tmpdir.join(priority)))
Config = collections.namedtuple('Config', ['real', 'mock']) Config = collections.namedtuple('Config', ['real', 'mock'])
@ -336,14 +337,14 @@ def check_canonical(self, var, expected):
expected + path) expected + path)
def test_substitute_config_variables(self): def test_substitute_config_variables(self):
prefix = spack.prefix.lstrip('/') prefix = spack.paths.prefix.lstrip('/')
assert os.path.join( assert os.path.join(
'/foo/bar/baz', prefix '/foo/bar/baz', prefix
) == canonicalize_path('/foo/bar/baz/$spack') ) == canonicalize_path('/foo/bar/baz/$spack')
assert os.path.join( assert os.path.join(
spack.prefix, 'foo/bar/baz' spack.paths.prefix, 'foo/bar/baz'
) == canonicalize_path('$spack/foo/bar/baz/') ) == canonicalize_path('$spack/foo/bar/baz/')
assert os.path.join( assert os.path.join(
@ -355,7 +356,7 @@ def test_substitute_config_variables(self):
) == canonicalize_path('/foo/bar/baz/${spack}') ) == canonicalize_path('/foo/bar/baz/${spack}')
assert os.path.join( assert os.path.join(
spack.prefix, 'foo/bar/baz' spack.paths.prefix, 'foo/bar/baz'
) == canonicalize_path('${spack}/foo/bar/baz/') ) == canonicalize_path('${spack}/foo/bar/baz/')
assert os.path.join( assert os.path.join(
@ -432,7 +433,7 @@ def test_keys_are_ordered():
config_scope = spack.config.ConfigScope( config_scope = spack.config.ConfigScope(
'modules', 'modules',
os.path.join(spack.test_path, 'data', 'config') os.path.join(spack.paths.test_path, 'data', 'config')
) )
data = config_scope.get_section('modules') data = config_scope.get_section('modules')

View File

@ -36,6 +36,7 @@
from llnl.util.filesystem import remove_linked_tree from llnl.util.filesystem import remove_linked_tree
import spack import spack
import spack.paths
import spack.architecture import spack.architecture
import spack.database import spack.database
import spack.directory_layout import spack.directory_layout
@ -77,11 +78,11 @@ def no_chdir():
@pytest.fixture(scope='session', autouse=True) @pytest.fixture(scope='session', autouse=True)
def mock_stage(tmpdir_factory): def mock_stage(tmpdir_factory):
"""Mocks up a fake stage directory for use by tests.""" """Mocks up a fake stage directory for use by tests."""
stage_path = spack.stage_path stage_path = spack.paths.stage_path
new_stage = str(tmpdir_factory.mktemp('mock_stage')) new_stage = str(tmpdir_factory.mktemp('mock_stage'))
spack.stage_path = new_stage spack.paths.stage_path = new_stage
yield new_stage yield new_stage
spack.stage_path = stage_path spack.paths.stage_path = stage_path
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
@ -118,14 +119,14 @@ def check_for_leftover_stage_files(request, mock_stage, _ignore_stage_files):
yield yield
files_in_stage = set() files_in_stage = set()
if os.path.exists(spack.stage_path): if os.path.exists(spack.paths.stage_path):
files_in_stage = set( files_in_stage = set(
os.listdir(spack.stage_path)) - _ignore_stage_files os.listdir(spack.paths.stage_path)) - _ignore_stage_files
if 'disable_clean_stage_check' in request.keywords: if 'disable_clean_stage_check' in request.keywords:
# clean up after tests that are expected to be dirty # clean up after tests that are expected to be dirty
for f in files_in_stage: for f in files_in_stage:
path = os.path.join(spack.stage_path, f) path = os.path.join(spack.paths.stage_path, f)
remove_whatever_it_is(path) remove_whatever_it_is(path)
else: else:
_ignore_stage_files |= files_in_stage _ignore_stage_files |= files_in_stage
@ -134,7 +135,7 @@ def check_for_leftover_stage_files(request, mock_stage, _ignore_stage_files):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_fetch_cache(monkeypatch): def mock_fetch_cache(monkeypatch):
"""Substitutes spack.fetch_cache with a mock object that does nothing """Substitutes spack.paths.fetch_cache with a mock object that does nothing
and raises on fetch. and raises on fetch.
""" """
class MockCache(object): class MockCache(object):
@ -171,7 +172,7 @@ def __str__(self):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def repo_path(): def repo_path():
"""Session scoped RepoPath object pointing to the mock repository""" """Session scoped RepoPath object pointing to the mock repository"""
return spack.repository.RepoPath(spack.mock_packages_path) return spack.repository.RepoPath(spack.paths.mock_packages_path)
@pytest.fixture(scope='module') @pytest.fixture(scope='module')
@ -216,7 +217,7 @@ def configuration_dir(tmpdir_factory, linux_os):
""" """
tmpdir = tmpdir_factory.mktemp('configurations') tmpdir = tmpdir_factory.mktemp('configurations')
# Name of the yaml files in the test/data folder # Name of the yaml files in the test/data folder
test_path = py.path.local(spack.test_path) test_path = py.path.local(spack.paths.test_path)
compilers_yaml = test_path.join('data', 'compilers.yaml') compilers_yaml = test_path.join('data', 'compilers.yaml')
packages_yaml = test_path.join('data', 'packages.yaml') packages_yaml = test_path.join('data', 'packages.yaml')
config_yaml = test_path.join('data', 'config.yaml') config_yaml = test_path.join('data', 'config.yaml')

View File

@ -31,6 +31,7 @@
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path
import spack import spack
import spack.paths
from spack.directory_layout import YamlDirectoryLayout from spack.directory_layout import YamlDirectoryLayout
from spack.directory_layout import InvalidDirectoryLayoutParametersError from spack.directory_layout import InvalidDirectoryLayoutParametersError
from spack.repository import RepoPath from spack.repository import RepoPath
@ -186,7 +187,7 @@ def test_handle_unknown_package(
or query them again if the package goes away. or query them again if the package goes away.
""" """
layout, _ = layout_and_dir layout, _ = layout_and_dir
mock_db = RepoPath(spack.mock_packages_path) mock_db = RepoPath(spack.paths.mock_packages_path)
not_in_mock = set.difference( not_in_mock = set.difference(
set(spack.repo.all_package_names()), set(spack.repo.all_package_names()),

View File

@ -26,7 +26,7 @@
import pytest import pytest
import spack.environment as environment import spack.environment as environment
from spack import spack_root from spack.paths import spack_root
from spack.environment import EnvironmentModifications from spack.environment import EnvironmentModifications
from spack.environment import RemovePath, PrependPath, AppendPath from spack.environment import RemovePath, PrependPath, AppendPath
from spack.environment import SetEnv, UnsetEnv from spack.environment import SetEnv, UnsetEnv

View File

@ -22,16 +22,17 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import fnmatch
import os import os
import fnmatch
import pytest
import six import six
import spack import pytest
from llnl.util.filesystem import LibraryList, HeaderList from llnl.util.filesystem import LibraryList, HeaderList
from llnl.util.filesystem import find_libraries, find_headers, find from llnl.util.filesystem import find_libraries, find_headers, find
import spack.paths
@pytest.fixture() @pytest.fixture()
def library_list(): def library_list():
@ -211,7 +212,7 @@ def test_add(self, header_list):
#: Directory where the data for the test below is stored #: Directory where the data for the test below is stored
search_dir = os.path.join(spack.test_path, 'data', 'directory_search') search_dir = os.path.join(spack.paths.test_path, 'data', 'directory_search')
@pytest.mark.parametrize('search_fn,search_list,root,kwargs', [ @pytest.mark.parametrize('search_fn,search_list,root,kwargs', [

View File

@ -22,16 +22,17 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os.path
import collections import collections
import contextlib import contextlib
import inspect import inspect
import os.path
import yaml
from six import StringIO import yaml
import pytest import pytest
import spack from six import StringIO
import spack.paths
import spack.spec
import spack.modules.common import spack.modules.common
import spack.util.path import spack.util.path
@ -110,7 +111,7 @@ def patch_configuration(monkeypatch, request):
writer_key = str(writer_mod.__name__).split('.')[-1] writer_key = str(writer_mod.__name__).split('.')[-1]
# Root folder for configuration # Root folder for configuration
root_for_conf = os.path.join( root_for_conf = os.path.join(
spack.test_path, 'data', 'modules', writer_key spack.paths.test_path, 'data', 'modules', writer_key
) )
def _impl(filename): def _impl(filename):

View File

@ -23,12 +23,12 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
"""This test does sanity checks on Spack's builtin package database.""" """This test does sanity checks on Spack's builtin package database."""
import re import re
import pytest import pytest
import spack import spack
from spack.paths import mock_packages_path
from spack.repository import RepoPath from spack.repository import RepoPath
@ -46,7 +46,7 @@ def test_get_all_packages():
def test_get_all_mock_packages(): def test_get_all_mock_packages():
"""Get the mock packages once each too.""" """Get the mock packages once each too."""
db = RepoPath(spack.mock_packages_path) db = RepoPath(mock_packages_path)
spack.repo.swap(db) spack.repo.swap(db)
check_db() check_db()
spack.repo.swap(db) spack.repo.swap(db)

View File

@ -22,10 +22,12 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import spack
import pytest import pytest
from llnl.util.filesystem import join_path from llnl.util.filesystem import join_path
import spack
from spack.paths import mock_packages_path
from spack.repository import Repo from spack.repository import Repo
from spack.util.naming import mod_to_class from spack.util.naming import mod_to_class
from spack.spec import Spec from spack.spec import Spec
@ -42,20 +44,20 @@ def test_package_name(self):
assert pkg.name == 'mpich' assert pkg.name == 'mpich'
def test_package_filename(self): def test_package_filename(self):
repo = Repo(spack.mock_packages_path) repo = Repo(mock_packages_path)
filename = repo.filename_for_package_name('mpich') filename = repo.filename_for_package_name('mpich')
assert filename == join_path( assert filename == join_path(
spack.mock_packages_path, mock_packages_path,
'packages', 'packages',
'mpich', 'mpich',
'package.py' 'package.py'
) )
def test_nonexisting_package_filename(self): def test_nonexisting_package_filename(self):
repo = Repo(spack.mock_packages_path) repo = Repo(mock_packages_path)
filename = repo.filename_for_package_name('some-nonexisting-package') filename = repo.filename_for_package_name('some-nonexisting-package')
assert filename == join_path( assert filename == join_path(
spack.mock_packages_path, mock_packages_path,
'packages', 'packages',
'some-nonexisting-package', 'some-nonexisting-package',
'package.py' 'package.py'

View File

@ -39,6 +39,7 @@
import spack.binary_distribution as bindist import spack.binary_distribution as bindist
import spack.cmd.buildcache as buildcache import spack.cmd.buildcache as buildcache
from spack.spec import Spec from spack.spec import Spec
from spack.paths import mock_gpg_keys_path
from spack.fetch_strategy import URLFetchStrategy, FetchStrategyComposite from spack.fetch_strategy import URLFetchStrategy, FetchStrategyComposite
from spack.util.executable import ProcessError from spack.util.executable import ProcessError
from spack.relocate import needs_binary_relocation, needs_text_relocation from spack.relocate import needs_binary_relocation, needs_text_relocation
@ -201,7 +202,7 @@ def test_buildcache(mock_archive, tmpdir):
buildcache.buildcache(parser, args) buildcache.buildcache(parser, args)
# Copy a key to the mirror to have something to download # Copy a key to the mirror to have something to download
shutil.copyfile(spack.mock_gpg_keys_path + '/external.key', shutil.copyfile(mock_gpg_keys_path + '/external.key',
mirror_path + '/external.key') mirror_path + '/external.key')
args = parser.parse_args(['keys']) args = parser.parse_args(['keys'])

View File

@ -29,7 +29,7 @@
from llnl.util.filesystem import working_dir, mkdirp from llnl.util.filesystem import working_dir, mkdirp
import spack import spack.paths
import spack.util.compression import spack.util.compression
from spack.stage import Stage from spack.stage import Stage
from spack.spec import Spec from spack.spec import Spec
@ -39,11 +39,11 @@
def mock_stage(tmpdir, monkeypatch): def mock_stage(tmpdir, monkeypatch):
# don't disrupt the spack install directory with tests. # don't disrupt the spack install directory with tests.
mock_path = str(tmpdir) mock_path = str(tmpdir)
monkeypatch.setattr(spack, 'stage_path', mock_path) monkeypatch.setattr(spack.paths, 'stage_path', mock_path)
return mock_path return mock_path
data_path = os.path.join(spack.test_path, 'data', 'patch') data_path = os.path.join(spack.paths.test_path, 'data', 'patch')
@pytest.mark.parametrize('filename, sha256, archive_sha256', [ @pytest.mark.parametrize('filename, sha256, archive_sha256', [

View File

@ -40,7 +40,10 @@
import pytest import pytest
import llnl.util.tty as tty import llnl.util.tty as tty
import spack
import spack.paths
from spack.paths import lib_path as spack_lib_path
# #
# This test uses pyqver, by Greg Hewgill, which is a dual-source module. # This test uses pyqver, by Greg Hewgill, which is a dual-source module.
@ -55,10 +58,10 @@
exclude_paths = [ exclude_paths = [
# Jinja 2 has some 'async def' functions that are not treated correctly # Jinja 2 has some 'async def' functions that are not treated correctly
# by pyqver.py # by pyqver.py
os.path.join(spack.lib_path, 'external', 'jinja2', 'asyncfilters.py'), os.path.join(spack_lib_path, 'external', 'jinja2', 'asyncfilters.py'),
os.path.join(spack.lib_path, 'external', 'jinja2', 'asyncsupport.py'), os.path.join(spack_lib_path, 'external', 'jinja2', 'asyncsupport.py'),
os.path.join(spack.lib_path, 'external', 'yaml', 'lib3'), os.path.join(spack_lib_path, 'external', 'yaml', 'lib3'),
os.path.join(spack.lib_path, 'external', 'pyqver3.py')] os.path.join(spack_lib_path, 'external', 'pyqver3.py')]
else: else:
import pyqver3 as pyqver import pyqver3 as pyqver
@ -68,10 +71,10 @@
exclude_paths = [ exclude_paths = [
# Jinja 2 has some 'async def' functions that are not treated correctly # Jinja 2 has some 'async def' functions that are not treated correctly
# by pyqver.py # by pyqver.py
os.path.join(spack.lib_path, 'external', 'jinja2', 'asyncfilters.py'), os.path.join(spack_lib_path, 'external', 'jinja2', 'asyncfilters.py'),
os.path.join(spack.lib_path, 'external', 'jinja2', 'asyncsupport.py'), os.path.join(spack_lib_path, 'external', 'jinja2', 'asyncsupport.py'),
os.path.join(spack.lib_path, 'external', 'yaml', 'lib'), os.path.join(spack_lib_path, 'external', 'yaml', 'lib'),
os.path.join(spack.lib_path, 'external', 'pyqver2.py')] os.path.join(spack_lib_path, 'external', 'pyqver2.py')]
def pyfiles(search_paths, exclude=()): def pyfiles(search_paths, exclude=()):
@ -85,7 +88,7 @@ def pyfiles(search_paths, exclude=()):
python files in the search path. python files in the search path.
""" """
# first file is the spack script. # first file is the spack script.
yield spack.spack_file yield spack.paths.spack_script
# Iterate through the whole spack source tree. # Iterate through the whole spack source tree.
for path in search_paths: for path in search_paths:
@ -135,8 +138,8 @@ def check_python_versions(files):
messages = [] messages = []
for path in sorted(all_issues[v].keys()): for path in sorted(all_issues[v].keys()):
short_path = path short_path = path
if path.startswith(spack.prefix): if path.startswith(spack.paths.prefix):
short_path = path[len(spack.prefix):] short_path = path[len(spack.paths.prefix):]
reasons = [r for r in set(all_issues[v][path]) if r] reasons = [r for r in set(all_issues[v][path]) if r]
for lineno, cause in reasons: for lineno, cause in reasons:
@ -159,10 +162,11 @@ def check_python_versions(files):
@pytest.mark.maybeslow @pytest.mark.maybeslow
def test_core_module_compatibility(): def test_core_module_compatibility():
"""Test that all core spack modules work with supported Python versions.""" """Test that all core spack modules work with supported Python versions."""
check_python_versions(pyfiles([spack.lib_path], exclude=exclude_paths)) check_python_versions(
pyfiles([spack_lib_path], exclude=exclude_paths))
@pytest.mark.maybeslow @pytest.mark.maybeslow
def test_package_module_compatibility(): def test_package_module_compatibility():
"""Test that all spack packages work with supported Python versions.""" """Test that all spack packages work with supported Python versions."""
check_python_versions(pyfiles([spack.packages_path])) check_python_versions(pyfiles([spack.paths.packages_path]))

View File

@ -22,17 +22,18 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import spack
import pytest import pytest
import spack.repository
import spack.paths
# Unlike the repo_path fixture defined in conftest, this has a test-level # Unlike the repo_path fixture defined in conftest, this has a test-level
# scope rather than a session level scope, since we want to edit the # scope rather than a session level scope, since we want to edit the
# given RepoPath # given RepoPath
@pytest.fixture() @pytest.fixture()
def repo_for_test(): def repo_for_test():
return spack.repository.RepoPath(spack.mock_packages_path) return spack.repository.RepoPath(spack.paths.mock_packages_path)
@pytest.fixture() @pytest.fixture()

View File

@ -34,7 +34,7 @@
from llnl.util.filesystem import mkdirp from llnl.util.filesystem import mkdirp
import spack import spack.paths
from spack.hooks.sbang import shebang_too_long, filter_shebangs_in_directory from spack.hooks.sbang import shebang_too_long, filter_shebangs_in_directory
from spack.util.executable import which from spack.util.executable import which
@ -47,7 +47,7 @@
node_line = "#!/this/" + ('x' * 200) + "/is/node\n" node_line = "#!/this/" + ('x' * 200) + "/is/node\n"
node_in_text = ("line\n") * 100 + "lua\n" + ("line\n" * 100) node_in_text = ("line\n") * 100 + "lua\n" + ("line\n" * 100)
node_line_patched = "//!/this/" + ('x' * 200) + "/is/node\n" node_line_patched = "//!/this/" + ('x' * 200) + "/is/node\n"
sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.spack_root sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.paths.prefix
last_line = "last!\n" last_line = "last!\n"

View File

@ -23,13 +23,14 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
"""Test that the Stage class works correctly.""" """Test that the Stage class works correctly."""
import collections
import os import os
import collections
import pytest
from llnl.util.filesystem import join_path, working_dir from llnl.util.filesystem import join_path, working_dir
import pytest import spack.paths
import spack
import spack.stage import spack.stage
import spack.util.executable import spack.util.executable
from spack.stage import Stage from spack.stage import Stage
@ -101,18 +102,18 @@ def get_stage_path(stage, stage_name):
""" """
if stage_name is not None: if stage_name is not None:
# If it is a named stage, we know where the stage should be # If it is a named stage, we know where the stage should be
return join_path(spack.stage_path, stage_name) return os.path.join(spack.paths.stage_path, stage_name)
else: else:
# If it's unnamed, ensure that we ran mkdtemp in the right spot. # If it's unnamed, ensure that we ran mkdtemp in the right spot.
assert stage.path is not None assert stage.path is not None
assert stage.path.startswith(spack.stage_path) assert stage.path.startswith(spack.paths.stage_path)
return stage.path return stage.path
@pytest.fixture() @pytest.fixture()
def tmpdir_for_stage(mock_archive): def tmpdir_for_stage(mock_archive):
"""Uses a temporary directory for staging""" """Uses a temporary directory for staging"""
current = spack.stage_path current = spack.paths.stage_path
spack.config.update_config( spack.config.update_config(
'config', 'config',
{'build_stage': [str(mock_archive.test_tmp_dir)]}, {'build_stage': [str(mock_archive.test_tmp_dir)]},

View File

@ -25,12 +25,12 @@
"""Tests for web.py.""" """Tests for web.py."""
import os import os
import spack import spack.paths
from spack.util.web import spider, find_versions_of_archive from spack.util.web import spider, find_versions_of_archive
from spack.version import ver from spack.version import ver
web_data_path = os.path.join(spack.test_path, 'data', 'web') web_data_path = os.path.join(spack.paths.test_path, 'data', 'web')
root = 'file://' + web_data_path + '/index.html' root = 'file://' + web_data_path + '/index.html'
root_tarball = 'file://' + web_data_path + '/foo-0.0.0.tar.gz' root_tarball = 'file://' + web_data_path + '/foo-0.0.0.tar.gz'

View File

@ -29,7 +29,7 @@
import sys import sys
import llnl.util.tty as tty import llnl.util.tty as tty
import spack
import spack.error import spack.error
__all__ = ['Executable', 'which', 'ProcessError'] __all__ = ['Executable', 'which', 'ProcessError']

View File

@ -22,14 +22,13 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import os import os
import spack import spack.paths
from spack.util.executable import Executable from spack.util.executable import Executable
GNUPGHOME = spack.gpg_path GNUPGHOME = spack.paths.gpg_path
class Gpg(object): class Gpg(object):

View File

@ -29,7 +29,7 @@
import re import re
from six import StringIO from six import StringIO
import spack import spack.error
__all__ = [ __all__ = [
'mod_to_class', 'mod_to_class',

View File

@ -28,17 +28,19 @@
""" """
import os import os
import re import re
import spack
import getpass import getpass
import tempfile import tempfile
import spack.paths
__all__ = [ __all__ = [
'substitute_config_variables', 'substitute_config_variables',
'canonicalize_path'] 'canonicalize_path']
# Substitutions to perform # Substitutions to perform
replacements = { replacements = {
'spack': spack.prefix, 'spack': spack.paths.prefix,
'user': getpass.getuser(), 'user': getpass.getuser(),
'tempdir': tempfile.gettempdir(), 'tempdir': tempfile.gettempdir(),
} }

View File

@ -25,14 +25,14 @@
from spack import * from spack import *
import os import os
import spack import spack.paths
class UrlListTest(Package): class UrlListTest(Package):
"""Mock package with url_list.""" """Mock package with url_list."""
homepage = "http://www.url-list-example.com" homepage = "http://www.url-list-example.com"
web_data_path = os.path.join(spack.test_path, 'data', 'web') web_data_path = os.path.join(spack.paths.test_path, 'data', 'web')
url = 'file://' + web_data_path + '/foo-0.0.0.tar.gz' url = 'file://' + web_data_path + '/foo-0.0.0.tar.gz'
list_url = 'file://' + web_data_path + '/index.html' list_url = 'file://' + web_data_path + '/index.html'
list_depth = 3 list_depth = 3

View File

@ -41,7 +41,6 @@
########################################################################## ##########################################################################
from spack import * from spack import *
import spack
import spack.store import spack.store

View File

@ -23,7 +23,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
from spack import * from spack import *
from spack import spack_root from spack.paths import spack_root
class GobjectIntrospection(Package): class GobjectIntrospection(Package):

View File

@ -42,7 +42,6 @@
from spack import * from spack import *
import spack
import spack.store import spack.store
import os import os

View File

@ -30,12 +30,14 @@
# Author: Justin Too <justin@doubleotoo.com> # Author: Justin Too <justin@doubleotoo.com>
# Date: September 6, 2015 # Date: September 6, 2015
# #
from spack import *
import os import os
from contextlib import contextmanager from contextlib import contextmanager
import spack
from llnl.util.lang import match_predicate from llnl.util.lang import match_predicate
import spack.store
from spack import *
class Perl(Package): # Perl doesn't use Autotools, it should subclass Package class Perl(Package): # Perl doesn't use Autotools, it should subclass Package
"""Perl 5 is a highly capable, feature-rich programming language with over """Perl 5 is a highly capable, feature-rich programming language with over

View File

@ -32,11 +32,11 @@
from llnl.util.lang import match_predicate from llnl.util.lang import match_predicate
from llnl.util.filesystem import force_remove from llnl.util.filesystem import force_remove
import spack import spack.store
from spack import * import spack.util.spack_json as sjson
from spack.util.environment import is_system_path from spack.util.environment import is_system_path
from spack.util.prefix import Prefix from spack.util.prefix import Prefix
import spack.util.spack_json as sjson from spack import *
class Python(AutotoolsPackage): class Python(AutotoolsPackage):