Skip to content

Commit

Permalink
move handler func out of CLI definition code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Jun 28, 2023
1 parent 18056f5 commit 2175c31
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
42 changes: 1 addition & 41 deletions smartsim/_core/_cli/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,15 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import argparse
import shutil
import typing as t

from smartsim._core._cli.utils import get_install_path, MenuItem
from smartsim._core._cli.utils import get_install_path, MenuItem, clean
from smartsim.log import get_logger

smart_logger_format = "[%(name)s] %(levelname)s %(message)s"
logger = get_logger("Smart", fmt=smart_logger_format)


def clean(core_path: str, _all: bool = False) -> None:
"""Remove pre existing installations of ML runtimes
:param _all: Remove all non-python dependencies
:type _all: bool, optional
"""

build_temp = core_path / ".third-party"
if build_temp.is_dir():
shutil.rmtree(build_temp, ignore_errors=True)

lib_path = core_path / "lib"
if lib_path.is_dir():

# remove RedisAI
rai_path = lib_path / "redisai.so"
if rai_path.is_file():
rai_path.unlink()
logger.info("Successfully removed existing RedisAI installation")

backend_path = lib_path / "backends"
if backend_path.is_dir():
shutil.rmtree(backend_path, ignore_errors=True)
logger.info("Successfully removed ML runtimes")

bin_path = core_path / "bin"
if bin_path.is_dir() and _all:
files_to_remove = ["redis-server", "redis-cli", "keydb-server", "keydb-cli"]
removed = False
for _file in files_to_remove:
file_path = bin_path.joinpath(_file)

if file_path.is_file():
removed = True
file_path.unlink()
if removed:
logger.info("Successfully removed SmartSim database installation")


class Clean(MenuItem):
def execute(self, args: argparse.Namespace) -> None:
core_path = get_install_path() / "_core"
Expand Down
40 changes: 40 additions & 0 deletions smartsim/_core/_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import shutil
import subprocess
import typing as t
from argparse import ArgumentParser, Namespace
Expand Down Expand Up @@ -84,6 +85,45 @@ def pip_install(packages: t.List[str], end_point: t.Optional[str] = None, verbos
logger.info(f"{packages} installed successfully")


def clean(core_path: str, _all: bool = False) -> None:
"""Remove pre existing installations of ML runtimes
:param _all: Remove all non-python dependencies
:type _all: bool, optional
"""

build_temp = core_path / ".third-party"
if build_temp.is_dir():
shutil.rmtree(build_temp, ignore_errors=True)

lib_path = core_path / "lib"
if lib_path.is_dir():

# remove RedisAI
rai_path = lib_path / "redisai.so"
if rai_path.is_file():
rai_path.unlink()
logger.info("Successfully removed existing RedisAI installation")

backend_path = lib_path / "backends"
if backend_path.is_dir():
shutil.rmtree(backend_path, ignore_errors=True)
logger.info("Successfully removed ML runtimes")

bin_path = core_path / "bin"
if bin_path.is_dir() and _all:
files_to_remove = ["redis-server", "redis-cli", "keydb-server", "keydb-cli"]
removed = False
for _file in files_to_remove:
file_path = bin_path.joinpath(_file)

if file_path.is_file():
removed = True
file_path.unlink()
if removed:
logger.info("Successfully removed SmartSim database installation")


class MenuItem(t.Protocol):
@staticmethod
def configure_parser(parser: ArgumentParser) -> ArgumentParser:
Expand Down

0 comments on commit 2175c31

Please sign in to comment.