-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added Docker image cleanup method to SimpleDocker class * Rename Clearer Class -> Uninstaller| Added Docker Image CleanUp * Feat: Remove Ersillia installation * Refactor: Changed clear command to uninstall * Feat: Removed Docker Images/ Extra Dependecies * Corrected uninstall_cmd docstring | Cmd help * Changed Print statements to logger.debug() * Added log statement to cleanup_ersilia_images * Renamed cl variable to ui * Initialized Logger instance for Simple Docker Class --------- Co-authored-by: Dhanshree Arora <DhanshreeA@users.noreply.github.com>
- Loading branch information
1 parent
c5b2651
commit a9de77c
Showing
7 changed files
with
124 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from . import ersilia_cli | ||
from ...utils.uninstall import Uninstaller | ||
|
||
|
||
def uninstall_cmd(): | ||
"""Uninstalls all Ersilia artifacts present locally on the user's system""" | ||
|
||
# Example usage: ersilia setup | ||
@ersilia_cli.command( | ||
short_help="Uninstall ersilia", | ||
help="Uninstalls all Ersilia artifacts present locally on the user's system.", | ||
) | ||
def uninstall(): | ||
ui = Uninstaller() | ||
ui.uninstall() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
from .conda import SimpleConda | ||
from .docker import SimpleDocker | ||
from ..default import EOS, BENTOML_PATH | ||
from .logging import logger | ||
|
||
|
||
class Uninstaller(object): | ||
def __init__(self): | ||
self.docker_cleaner = SimpleDocker() | ||
|
||
def _uninstall_ersilia_package(self): | ||
"""Uninstall the Ersilia package if installed via pip.""" | ||
try: | ||
logger.info("Uninstalling Ersilia package...") | ||
subprocess.run(["pip", "uninstall", "-y", "ersilia"], check=True) | ||
logger.info("Ersilia package uninstalled successfully.") | ||
except subprocess.CalledProcessError as e: | ||
logger.error(f"Failed to uninstall Ersilia package: {e}") | ||
|
||
def _directories(self): | ||
"""Remove additional directories.""" | ||
dirs_to_remove = [EOS, BENTOML_PATH] | ||
for dir in dirs_to_remove: | ||
if os.path.exists(dir): | ||
try: | ||
logger.info(f"Removing directory: {dir}...") | ||
shutil.rmtree(dir) | ||
logger.info(f"Directory {dir} removed successfully.") | ||
except Exception as e: | ||
logger.error(f"Failed to remove directory {dir}: {e}") | ||
|
||
def _conda(self): | ||
sc = SimpleConda() | ||
|
||
for env in sc._env_list(): | ||
if env.startswith("#"): | ||
continue | ||
if not env.startswith("eos"): | ||
continue | ||
env = env.split(" ")[0] | ||
if len(env.split("-")[0]) == 7: | ||
try: | ||
logger.info(f"Removing conda environment: {env}") | ||
sc.delete(env) | ||
except Exception as e: | ||
logger.error(f"Failed to remove conda environment {env}: {e}") | ||
|
||
|
||
env_name = "ersilia" | ||
|
||
try: | ||
logger.info(f"Removing Conda environment: {env_name}...") | ||
sc.delete(env_name) | ||
logger.info(f"Conda environment {env_name} removed successfully.") | ||
except Exception as e: | ||
logger.error(f"Failed to remove Conda environment {env_name}: {e}") | ||
|
||
def uninstall(self): | ||
"""Main uninstallation method""" | ||
|
||
try: | ||
logger.info("Starting Ersillia uninstallation...") | ||
|
||
self.docker_cleaner.cleanup_ersilia_images() | ||
self._uninstall_ersilia_package() | ||
self._conda() | ||
self._directories() | ||
|
||
logger.info("Ersilia uninstallation completed") | ||
except Exception as e: | ||
logger.error(f"Uninstallation failed: {e}") | ||
raise |