Skip to content

Commit

Permalink
Merge pull request #793 from linsword13/cleanup
Browse files Browse the repository at this point in the history
Minor cleanups for pkgman
  • Loading branch information
douglasjacobsen authored Dec 9, 2024
2 parents 69765cb + 8252441 commit 0e0f5b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/ramble/ramble/util/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_version(self):

def set_dry_run(self, dry_run=False):
"""
Set the dry_run state of this spack runner
Set the dry_run state of this runner
"""
self.dry_run = dry_run

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _extract_pkg_name(pkg_spec):
return match.group("pkg_name") if match else None


class PipRunner(ramble.util.command_runner.CommandRunner):
class PipRunner(CommandRunner):
"""Runner for executing pip+venv commands."""

_venv_name = ".venv"
Expand All @@ -273,10 +273,6 @@ def configure_env(self, path):
"""Configure the venv path for subsequent commands"""
self.env_path = path

def set_dry_run(self, dry_run=False):
"""Set the dry_run state of this pip runner"""
self.dry_run = dry_run

def create_env(self, env_path):
"""Ensure a venv environment is created"""
if os.path.exists(env_path) and not os.path.isdir(env_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import ramble.config
import ramble.error
import ramble.util.hashing
import ramble.util.command_runner
from ramble.util.logger import logger


Expand Down Expand Up @@ -92,7 +91,7 @@ def _software_install_requested_compilers(self, workspace, app_inst=None):
logger.debug(f"Installing compiler: {compiler_spec}")
self.runner.install_compiler(compiler_spec)

except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
logger.die(e)

register_phase("software_create_env", pipeline="mirror")
Expand Down Expand Up @@ -197,7 +196,7 @@ def _software_create_env(self, workspace, app_inst=None):

self.runner.deactivate()

except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
logger.die(e)

register_phase(
Expand Down Expand Up @@ -238,7 +237,7 @@ def _software_configure(self, workspace, app_inst=None):
if not env_concretized:
self.runner.concretize()

except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
logger.die(e)

register_phase(
Expand Down Expand Up @@ -320,7 +319,7 @@ def _mirror_software(self, workspace, app_inst=None):
for i in range(error_start, error_start + failed):
workspace.software_mirror_stats.errors.add(i)

except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
if self.environment_required():
logger.die(e)
pass
Expand Down Expand Up @@ -348,7 +347,7 @@ def _push_to_spack_cache(self, workspace, app_inst=None):
self.runner.push_to_spack_cache(workspace.spack_cache_path)

self.runner.deactivate()
except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
if self.environment_required():
logger.die(e)
pass
Expand All @@ -365,7 +364,7 @@ def populate_inventory(

try:
pkgman_version = self.runner.get_version()
except ramble.util.command_runner.RunnerError:
except RunnerError:
pkgman_version = "unknown"

self.app_inst.hash_inventory["package_manager"].append(
Expand Down Expand Up @@ -433,7 +432,7 @@ def _deploy_artifacts(self, workspace, app_inst=None):

self.runner.deactivate()

except ramble.util.command_runner.RunnerError as e:
except RunnerError as e:
if self.environment_required():
logger.die(e)
pass
Expand Down Expand Up @@ -523,7 +522,7 @@ def _add_software_to_results(self, workspace, app_inst=None):
package_name_regex = re.compile(r"[\s-]*(?P<package_name>[\w][\w-]+).*")


class SpackRunner(ramble.util.command_runner.CommandRunner):
class SpackRunner(CommandRunner):
"""Runner for executing several spack commands
The SpackRunner class is primarily used to manage spack environments
Expand Down Expand Up @@ -638,12 +637,6 @@ def get_version(self):

return spack_version

def set_dry_run(self, dry_run=False):
"""
Set the dry_run state of this spack runner
"""
self.dry_run = dry_run

def set_compiler_config_dir(self, path=None):
"""
Set the config path to use when installing compilers
Expand Down Expand Up @@ -711,9 +704,7 @@ def create_env(self, path, output=None, error=None):
this runner.
"""
if os.path.exists(path) and not os.path.isdir(path):
raise ramble.util.command_runner.RunnerError(
"Unable to create environment %s" % path
)
raise RunnerError("Unable to create environment %s" % path)

if not os.path.exists(path):
fs.mkdirp(path)
Expand Down Expand Up @@ -753,9 +744,7 @@ def load_compiler(self, spec):
)
shell_flag = "--fish"
else:
raise ramble.util.command_runner.RunnerError(
"Shell %s not supported" % self.shell
)
raise RunnerError("Shell %s not supported" % self.shell)

self._load_compiler_shell(spec, shell_flag, regex)

Expand Down Expand Up @@ -853,7 +842,7 @@ def activate(self):
Ensure the spack environment is active in subsequent commands.
"""
if not self.env_path:
raise ramble.util.command_runner.NoPathRunnerError(
raise NoPathRunnerError(
"Environment runner has no path configured"
)

Expand All @@ -868,7 +857,7 @@ def deactivate(self):
Ensure the spack environment is not active in subsequent commands.
"""
if not self.env_path:
raise ramble.util.command_runner.NoPathRunnerError(
raise NoPathRunnerError(
"Environment runner has no path configured"
)

Expand All @@ -880,7 +869,7 @@ def deactivate(self):

def _check_active(self):
if not self.env_path:
raise ramble.util.command_runner.NoPathRunnerError(
raise NoPathRunnerError(
"Environment runner has no path configured"
)

Expand Down Expand Up @@ -1354,10 +1343,10 @@ def package_provenance(self):
yield info_dict


class NoActiveEnvironmentError(ramble.util.command_runner.RunnerError):
class NoActiveEnvironmentError(RunnerError):
"""Raised when an environment command is executed without an active
environment."""


class InvalidExternalEnvironment(ramble.util.command_runner.RunnerError):
class InvalidExternalEnvironment(RunnerError):
"""Raised when an invalid external spack environment is passed in"""

0 comments on commit 0e0f5b1

Please sign in to comment.