From aa6651fe27dda47c69042c06b5d56ffdb9d582e0 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Tue, 17 Sep 2024 17:06:16 +0200 Subject: [PATCH] drop main dep from build_environment/subprocess_context (#46426) --- lib/spack/spack/build_environment.py | 3 +-- lib/spack/spack/main.py | 14 +------------- lib/spack/spack/paths.py | 13 +++++++++++++ lib/spack/spack/subprocess_context.py | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index bf8ac6c1ea1..26eb0e79f68 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -62,7 +62,6 @@ import spack.config import spack.deptypes as dt import spack.error -import spack.main import spack.multimethod import spack.package_base import spack.paths @@ -451,7 +450,7 @@ def set_wrapper_variables(pkg, env): env.set(SPACK_DEBUG, "TRUE") env.set(SPACK_SHORT_SPEC, pkg.spec.short_spec) env.set(SPACK_DEBUG_LOG_ID, pkg.spec.format("{name}-{hash:7}")) - env.set(SPACK_DEBUG_LOG_DIR, spack.main.spack_working_dir) + env.set(SPACK_DEBUG_LOG_DIR, spack.paths.spack_working_dir) if spack.config.get("config:ccache"): # Enable ccache in the compiler wrapper diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index eb15789c769..c0bb3d33552 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -100,24 +100,12 @@ #: Properties that commands are required to set. required_command_properties = ["level", "section", "description"] -#: Recorded directory where spack command was originally invoked -spack_working_dir = None spack_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "") #: Whether to print backtraces on error SHOW_BACKTRACE = False -def set_working_dir(): - """Change the working directory to getcwd, or spack prefix if no cwd.""" - global spack_working_dir - try: - spack_working_dir = os.getcwd() - except OSError: - os.chdir(spack.paths.prefix) - spack_working_dir = spack.paths.prefix - - def add_all_commands(parser): """Add all spack subcommands to the parser.""" for cmd in spack.cmd.all_commands(): @@ -998,7 +986,7 @@ def finish_parse_and_run(parser, cmd_name, main_args, env_format_error): raise env_format_error # many operations will fail without a working directory. - set_working_dir() + spack.paths.set_working_dir() # now we can actually execute the command. if main_args.spack_profile or main_args.sorted_profile: diff --git a/lib/spack/spack/paths.py b/lib/spack/spack/paths.py index aa642764215..84583cd552f 100644 --- a/lib/spack/spack/paths.py +++ b/lib/spack/spack/paths.py @@ -136,3 +136,16 @@ def _get_system_config_path(): #: System configuration location system_config_path = _get_system_config_path() + +#: Recorded directory where spack command was originally invoked +spack_working_dir = None + + +def set_working_dir(): + """Change the working directory to getcwd, or spack prefix if no cwd.""" + global spack_working_dir + try: + spack_working_dir = os.getcwd() + except OSError: + os.chdir(prefix) + spack_working_dir = prefix diff --git a/lib/spack/spack/subprocess_context.py b/lib/spack/spack/subprocess_context.py index f96e530e971..c823e657036 100644 --- a/lib/spack/spack/subprocess_context.py +++ b/lib/spack/spack/subprocess_context.py @@ -22,7 +22,7 @@ import spack.config import spack.environment -import spack.main +import spack.paths import spack.platforms import spack.repo import spack.store @@ -72,12 +72,12 @@ def __init__(self, pkg): else: self.pkg = pkg self.env = spack.environment.active_environment() - self.spack_working_dir = spack.main.spack_working_dir + self.spack_working_dir = spack.paths.spack_working_dir self.test_state = TestState() def restore(self): self.test_state.restore() - spack.main.spack_working_dir = self.spack_working_dir + spack.paths.spack_working_dir = self.spack_working_dir env = pickle.load(self.serialized_env) if _SERIALIZE else self.env if env: spack.environment.activate(env)