Skip to content

Commit 2557ea6

Browse files
committed
init: factor paths out of spack/__init__.py and into spack.paths module
1 parent 546b562 commit 2557ea6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+367
-296
lines changed

lib/spack/spack/__init__.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,7 @@
2727
import sys
2828
import multiprocessing
2929

30-
from llnl.util.filesystem import ancestor
31-
32-
#-----------------------------------------------------------------------------
33-
# Variables describing how Spack is laid out in its prefix.
34-
#-----------------------------------------------------------------------------
35-
# This file lives in $prefix/lib/spack/spack/__file__
36-
spack_root = ancestor(__file__, 4)
37-
38-
# The spack script itself
39-
spack_file = os.path.join(spack_root, "bin", "spack")
40-
41-
# spack directory hierarchy
42-
lib_path = os.path.join(spack_root, "lib", "spack")
43-
external_path = os.path.join(lib_path, "external")
44-
build_env_path = os.path.join(lib_path, "env")
45-
module_path = os.path.join(lib_path, "spack")
46-
platform_path = os.path.join(module_path, 'platforms')
47-
compilers_path = os.path.join(module_path, "compilers")
48-
build_systems_path = os.path.join(module_path, 'build_systems')
49-
operating_system_path = os.path.join(module_path, 'operating_systems')
50-
test_path = os.path.join(module_path, "test")
51-
hooks_path = os.path.join(module_path, "hooks")
52-
var_path = os.path.join(spack_root, "var", "spack")
53-
stage_path = os.path.join(var_path, "stage")
54-
repos_path = os.path.join(var_path, "repos")
55-
share_path = os.path.join(spack_root, "share", "spack")
56-
57-
# Paths to built-in Spack repositories.
58-
packages_path = os.path.join(repos_path, "builtin")
59-
mock_packages_path = os.path.join(repos_path, "builtin.mock")
60-
61-
# User configuration location
62-
user_config_path = os.path.expanduser('~/.spack')
63-
64-
prefix = spack_root
65-
opt_path = os.path.join(prefix, "opt")
66-
etc_path = os.path.join(prefix, "etc")
67-
system_etc_path = '/etc'
68-
69-
# GPG paths.
70-
gpg_keys_path = os.path.join(var_path, "gpg")
71-
mock_gpg_data_path = os.path.join(var_path, "gpg.mock", "data")
72-
mock_gpg_keys_path = os.path.join(var_path, "gpg.mock", "keys")
73-
gpg_path = os.path.join(opt_path, "spack", "gpg")
74-
30+
from spack.paths import var_path, user_config_path
7531

7632
#-----------------------------------------------------------------------------
7733
# Below code imports spack packages.
@@ -280,4 +236,3 @@ def editor_not_found(*args, **kwargs):
280236
# Add default values for attributes that would otherwise be modified from
281237
# Spack main script
282238
debug = False
283-
spack_working_dir = None

lib/spack/spack/architecture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@
8383
from llnl.util.filesystem import join_path
8484
import llnl.util.tty as tty
8585

86-
import spack
86+
import spack.paths
87+
import spack.error as serr
8788
from spack.util.naming import mod_to_class
8889
from spack.util.environment import get_path
8990
from spack.util.multiproc import parmap
9091
from spack.util.spack_yaml import syaml_dict
91-
import spack.error as serr
9292

9393

9494
class NoPlatformError(serr.SpackError):
@@ -463,7 +463,7 @@ def arch_for_spec(arch_spec):
463463
@memoized
464464
def all_platforms():
465465
classes = []
466-
mod_path = spack.platform_path
466+
mod_path = spack.paths.platform_path
467467
parent_module = "spack.platforms"
468468

469469
for name in list_modules(mod_path):

lib/spack/spack/build_environment.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@
6363

6464
import llnl.util.tty as tty
6565
from llnl.util.tty.color import colorize
66-
from llnl.util.filesystem import join_path, mkdirp, install, install_tree
66+
from llnl.util.filesystem import mkdirp, install, install_tree
6767

68-
import spack
68+
import spack.main
69+
import spack.paths
6970
import spack.store
7071
from spack.environment import EnvironmentModifications, validate
7172
from spack.util.environment import env_flag, filter_system_paths, get_path
@@ -138,21 +139,21 @@ def set_compiler_environment_variables(pkg, env):
138139
# and return it
139140
# TODO : add additional kwargs for better diagnostics, like requestor,
140141
# ttyout, ttyerr, etc.
141-
link_dir = spack.build_env_path
142+
link_dir = spack.paths.build_env_path
142143

143144
# Set SPACK compiler variables so that our wrapper knows what to call
144145
if compiler.cc:
145146
env.set('SPACK_CC', compiler.cc)
146-
env.set('CC', join_path(link_dir, compiler.link_paths['cc']))
147+
env.set('CC', os.path.join(link_dir, compiler.link_paths['cc']))
147148
if compiler.cxx:
148149
env.set('SPACK_CXX', compiler.cxx)
149-
env.set('CXX', join_path(link_dir, compiler.link_paths['cxx']))
150+
env.set('CXX', os.path.join(link_dir, compiler.link_paths['cxx']))
150151
if compiler.f77:
151152
env.set('SPACK_F77', compiler.f77)
152-
env.set('F77', join_path(link_dir, compiler.link_paths['f77']))
153+
env.set('F77', os.path.join(link_dir, compiler.link_paths['f77']))
153154
if compiler.fc:
154155
env.set('SPACK_FC', compiler.fc)
155-
env.set('FC', join_path(link_dir, compiler.link_paths['fc']))
156+
env.set('FC', os.path.join(link_dir, compiler.link_paths['fc']))
156157

157158
# Set SPACK compiler rpath flags so that our wrapper knows what to use
158159
env.set('SPACK_CC_RPATH_ARG', compiler.cc_rpath_arg)
@@ -302,20 +303,21 @@ def set_build_environment_variables(pkg, env, dirty):
302303
env.prepend_path('PATH', bin_dir)
303304

304305
# Add spack build environment path with compiler wrappers first in
305-
# the path. We add both spack.env_path, which includes default
306+
# the path. We add the compiler wrapper path, which includes default
306307
# wrappers (cc, c++, f77, f90), AND a subdirectory containing
307308
# compiler-specific symlinks. The latter ensures that builds that
308-
# are sensitive to the *name* of the compiler see the right name
309-
# when we're building with the wrappers.
309+
# are sensitive to the *name* of the compiler see the right name when
310+
# we're building with the wrappers.
310311
#
311312
# Conflicts on case-insensitive systems (like "CC" and "cc") are
312313
# handled by putting one in the <build_env_path>/case-insensitive
313314
# directory. Add that to the path too.
314315
env_paths = []
315-
compiler_specific = join_path(spack.build_env_path, pkg.compiler.name)
316-
for item in [spack.build_env_path, compiler_specific]:
316+
compiler_specific = os.path.join(
317+
spack.paths.build_env_path, pkg.compiler.name)
318+
for item in [spack.paths.build_env_path, compiler_specific]:
317319
env_paths.append(item)
318-
ci = join_path(item, 'case-insensitive')
320+
ci = os.path.join(item, 'case-insensitive')
319321
if os.path.isdir(ci):
320322
env_paths.append(ci)
321323

@@ -328,12 +330,12 @@ def set_build_environment_variables(pkg, env, dirty):
328330
env.set(SPACK_DEBUG, 'TRUE')
329331
env.set(SPACK_SHORT_SPEC, pkg.spec.short_spec)
330332
env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format('${PACKAGE}-${HASH:7}'))
331-
env.set(SPACK_DEBUG_LOG_DIR, spack.spack_working_dir)
333+
env.set(SPACK_DEBUG_LOG_DIR, spack.main.spack_working_dir)
332334

333335
# Add any pkgconfig directories to PKG_CONFIG_PATH
334336
for prefix in build_link_prefixes:
335337
for directory in ('lib', 'lib64', 'share'):
336-
pcdir = join_path(prefix, directory, 'pkgconfig')
338+
pcdir = os.path.join(prefix, directory, 'pkgconfig')
337339
if os.path.isdir(pcdir):
338340
env.prepend_path('PKG_CONFIG_PATH', pcdir)
339341

@@ -374,11 +376,11 @@ def set_module_variables_for_package(pkg, module):
374376
m.std_cmake_args = spack.CMakePackage._std_args(pkg)
375377

376378
# Put spack compiler paths in module scope.
377-
link_dir = spack.build_env_path
378-
m.spack_cc = join_path(link_dir, pkg.compiler.link_paths['cc'])
379-
m.spack_cxx = join_path(link_dir, pkg.compiler.link_paths['cxx'])
380-
m.spack_f77 = join_path(link_dir, pkg.compiler.link_paths['f77'])
381-
m.spack_fc = join_path(link_dir, pkg.compiler.link_paths['fc'])
379+
link_dir = spack.paths.build_env_path
380+
m.spack_cc = os.path.join(link_dir, pkg.compiler.link_paths['cc'])
381+
m.spack_cxx = os.path.join(link_dir, pkg.compiler.link_paths['cxx'])
382+
m.spack_f77 = os.path.join(link_dir, pkg.compiler.link_paths['f77'])
383+
m.spack_fc = os.path.join(link_dir, pkg.compiler.link_paths['fc'])
382384

383385
# Emulate some shell commands for convenience
384386
m.pwd = os.getcwd

lib/spack/spack/cmd/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
from llnl.util.tty.color import colorize
3434
from llnl.util.filesystem import working_dir
3535

36-
import spack
3736
import spack.config
37+
import spack.paths
3838
import spack.spec
3939
import spack.store
4040
from spack.error import SpackError
@@ -58,8 +58,6 @@
5858
SETUP_PARSER = "setup_parser"
5959
DESCRIPTION = "description"
6060

61-
command_path = os.path.join(spack.lib_path, "spack", "cmd")
62-
6361
#: Names of all commands
6462
all_commands = []
6563

@@ -74,7 +72,7 @@ def cmd_name(python_name):
7472
return python_name.replace('_', '-')
7573

7674

77-
for file in os.listdir(command_path):
75+
for file in os.listdir(spack.paths.command_path):
7876
if file.endswith(".py") and not re.search(ignore_files, file):
7977
cmd = re.sub(r'.py$', '', file)
8078
all_commands.append(cmd_name(cmd))
@@ -316,5 +314,5 @@ def fmt(s):
316314

317315
def spack_is_git_repo():
318316
"""Ensure that this instance of Spack is a git clone."""
319-
with working_dir(spack.prefix):
317+
with working_dir(spack.paths.prefix):
320318
return os.path.isdir('.git')

lib/spack/spack/cmd/blame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from llnl.util.filesystem import working_dir
3131
from llnl.util.tty.colify import colify_table
3232

33-
import spack
33+
import spack.paths
3434
from spack.util.executable import which
3535
from spack.cmd import spack_is_git_repo
3636

@@ -67,15 +67,15 @@ def blame(parser, args):
6767
blame_file = None
6868
if os.path.isfile(args.package_name):
6969
path = os.path.realpath(args.package_name)
70-
if path.startswith(spack.prefix):
70+
if path.startswith(spack.paths.prefix):
7171
blame_file = path
7272

7373
if not blame_file:
7474
pkg = spack.repo.get(args.package_name)
7575
blame_file = pkg.module.__file__.rstrip('c') # .pyc -> .py
7676

7777
# get git blame for the package
78-
with working_dir(spack.prefix):
78+
with working_dir(spack.paths.prefix):
7979
if args.view == 'git':
8080
git('blame', blame_file)
8181
return

lib/spack/spack/cmd/clone.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import llnl.util.tty as tty
2828
from llnl.util.filesystem import mkdirp, working_dir
2929

30-
import spack
30+
import spack.paths
3131
from spack.util.executable import ProcessError, which
3232

3333
_SPACK_UPSTREAM = 'https://github.com/spack/spack'
@@ -47,7 +47,7 @@ def setup_parser(subparser):
4747

4848

4949
def get_origin_info(remote):
50-
git_dir = os.path.join(spack.prefix, '.git')
50+
git_dir = os.path.join(spack.paths.prefix, '.git')
5151
git = which('git', required=True)
5252
try:
5353
branch = git('symbolic-ref', '--short', 'HEAD', output=str)

lib/spack/spack/cmd/common/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2424
##############################################################################
2525

26-
import spack
26+
import spack.paths
2727
from llnl.util import tty
2828

2929

@@ -35,9 +35,10 @@ def print_module_placeholder_help():
3535
"To initialize spack's shell commands, you must run one of",
3636
"the commands below. Choose the right command for your shell.",
3737
"", "For bash and zsh:",
38-
" . %s/setup-env.sh" % spack.share_path, "",
39-
"For csh and tcsh:", " setenv SPACK_ROOT %s" % spack.prefix,
40-
" source %s/setup-env.csh" % spack.share_path, "",
38+
" . %s/setup-env.sh" % spack.paths.share_path, "",
39+
"For csh and tcsh:",
40+
" setenv SPACK_ROOT %s" % spack.paths.prefix,
41+
" source %s/setup-env.csh" % spack.paths.share_path, "",
4142
"This exposes a 'spack' shell function, which you can use like",
4243
" $ spack load package-foo", "",
4344
"Running the Spack executable directly (for example, invoking",

lib/spack/spack/cmd/debug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import llnl.util.tty as tty
3131
from llnl.util.filesystem import working_dir
3232

33-
import spack
33+
import spack.paths
3434
from spack.util.executable import which
3535

3636
description = "debugging commands for troubleshooting Spack"
@@ -52,7 +52,7 @@ def _debug_tarball_suffix():
5252
if not git:
5353
return 'nobranch-nogit-%s' % suffix
5454

55-
with working_dir(spack.spack_root):
55+
with working_dir(spack.paths.prefix):
5656
if not os.path.isdir('.git'):
5757
return 'nobranch.nogit.%s' % suffix
5858

lib/spack/spack/cmd/edit.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
import llnl.util.tty as tty
2929

30-
import spack
3130
import spack.cmd
31+
import spack.paths
3232
from spack.spec import Spec
3333
from spack.repository import Repo
3434

@@ -74,23 +74,23 @@ def setup_parser(subparser):
7474
# Edits package files by default
7575
excl_args.add_argument(
7676
'-b', '--build-system', dest='path', action='store_const',
77-
const=spack.build_systems_path,
77+
const=spack.paths.build_systems_path,
7878
help="Edit the build system with the supplied name.")
7979
excl_args.add_argument(
8080
'-c', '--command', dest='path', action='store_const',
81-
const=spack.cmd.command_path,
81+
const=spack.paths.command_path,
8282
help="edit the command with the supplied name")
8383
excl_args.add_argument(
8484
'-d', '--docs', dest='path', action='store_const',
85-
const=os.path.join(spack.lib_path, 'docs'),
85+
const=os.path.join(spack.paths.lib_path, 'docs'),
8686
help="edit the docs with the supplied name")
8787
excl_args.add_argument(
8888
'-t', '--test', dest='path', action='store_const',
89-
const=spack.test_path,
89+
const=spack.paths.test_path,
9090
help="edit the test with the supplied name")
9191
excl_args.add_argument(
9292
'-m', '--module', dest='path', action='store_const',
93-
const=spack.module_path,
93+
const=spack.paths.module_path,
9494
help="edit the main spack module with the supplied name")
9595

9696
# Options for editing packages
@@ -110,14 +110,14 @@ def edit(parser, args):
110110
name = args.name
111111

112112
# By default, edit package files
113-
path = spack.packages_path
113+
path = spack.paths.packages_path
114114

115115
# If `--command`, `--test`, or `--module` is chosen, edit those instead
116116
if args.path:
117117
path = args.path
118118
if name:
119119
# convert command names to python module name
120-
if path == spack.cmd.command_path:
120+
if path == spack.paths.command_path:
121121
name = spack.cmd.python_name(name)
122122

123123
path = os.path.join(path, name)

0 commit comments

Comments
 (0)