Skip to content

Commit

Permalink
Better Exit Usage (#255)
Browse files Browse the repository at this point in the history
Removes use of `exit` and replaces with `sys.exit` to handle the unlikely case
where users (foolishly) try to use the `smart` cli without fully initializing 
site module

[ committed by @MattToast ]
[ reviewed by @al-rigazzi ]
  • Loading branch information
MattToast authored Feb 8, 2023
1 parent bf9a5c4 commit 0675031
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions smartsim/_core/_cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self):

except (SetupError, BuildError) as e:
logger.error(str(e))
exit(1)
sys.exit(1)

logger.info("SmartSim build complete!")

Expand Down Expand Up @@ -204,13 +204,13 @@ def build_redis_ai(
if self.build_env.PLATFORM == "darwin":
if device == "gpu":
logger.error("SmartSim does not support GPU on MacOS")
exit(1)
sys.exit(1)
if onnx and self.versions.REDISAI < "1.2.6":
logger.error("RedisAI < 1.2.6 does not support ONNX on MacOS")
exit(1)
sys.exit(1)
if self.versions.REDISAI == "1.2.4" or self.versions.REDISAI == "1.2.5":
logger.error("RedisAI support for MacOS is broken in 1.2.4 and 1.2.5")
exit(1)
sys.exit(1)

# decide which runtimes to build
print("\nML Backends Requested")
Expand Down Expand Up @@ -241,7 +241,7 @@ def build_redis_ai(
# pip so if we can't find it we know the user suggested a torch
# installation path that doesn't exist
logger.error("Could not find requested user Torch installation")
exit(1)
sys.exit(1)
else:
# install pytorch wheel, and get the path to the cmake dir
# we will use in the RAI build
Expand Down Expand Up @@ -389,10 +389,10 @@ def check_backends_install(self):
logger.error(
f"Before running 'smart build', unset your RAI_PATH environment variable with 'unset RAI_PATH'."
)
exit(1)
sys.exit(1)
else:
if installed_redisai_backends():
logger.error(
"If you wish to re-run `smart build`, you must first run `smart clean`."
)
exit(1)
sys.exit(1)
16 changes: 8 additions & 8 deletions smartsim/_core/_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@ def __init__(self):
# smart
if len(sys.argv) < 2:
parser.print_help()
exit(0)
sys.exit(0)

args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
parser.print_help()
exit(0)
sys.exit(0)
getattr(self, args.command)()

def build(self):
Build()
exit(0)
sys.exit(0)

def clean(self):
Clean()
exit(0)
sys.exit(0)

def clobber(self):
Clean(clean_all=True)
exit(0)
sys.exit(0)

def site(self):
print(get_install_path())
exit(0)
sys.exit(0)

def dbcli(self):
bin_path = get_install_path() / "_core" / "bin"
for option in bin_path.iterdir():
if option.name in ("redis-cli", "keydb-cli"):
print(option)
exit(0)
sys.exit(0)
print("Database (Redis or KeyDB) dependencies not found")
exit(1)
sys.exit(1)


def main():
Expand Down
2 changes: 1 addition & 1 deletion smartsim/_core/entrypoints/colocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@ def cleanup():
# we do not want to have start a colocated process. Only one process
# per node should be running.
except filelock.Timeout:
exit(0)
sys.exit(0)

0 comments on commit 0675031

Please sign in to comment.