@@ -1484,10 +1484,22 @@ def _enable_installed(installed: InstInfo, plugin_name: str) -> Union[str, None]
14841484    if  enable (installed .name ):
14851485        return  f"{ installed .source_loc }  " 
14861486
1487-     log .error (('dynamic activation failed: ' 
1488-               f'{ installed .name }   not found in reckless directory' ))
1487+     log .error ('dynamic activation failed' )
14891488    return  None 
14901489
1490+ 
1491+ def  cleanup_plugin_installation (plugin_name ):
1492+     """Remove traces of an installation attempt.""" 
1493+     inst_path  =  Path (RECKLESS_CONFIG .reckless_dir ) /  plugin_name 
1494+     if  not  inst_path .exists ():
1495+         log .warning (f'asked to clean up { inst_path }  , but nothing is present.' )
1496+         return 
1497+ 
1498+     log .info (f'Cleaning up partial installation of { plugin_name }   at { inst_path }  ' )
1499+     shutil .rmtree (inst_path )
1500+     return 
1501+ 
1502+ 
14911503def  install (plugin_name : str ) ->  Union [str , None ]:
14921504    """Downloads plugin from source repos, installs and activates plugin. 
14931505    Returns the location of the installed plugin or "None" in the case of 
@@ -1504,7 +1516,7 @@ def install(plugin_name: str) -> Union[str, None]:
15041516    direct_location , name  =  location_from_name (name )
15051517    src  =  None 
15061518    if  direct_location :
1507-         logging .debug (f"install of { name }   requested from { direct_location }  " )
1519+         log .debug (f"install of { name }   requested from { direct_location }  " )
15081520        src  =  InstInfo (name , direct_location , name )
15091521        # Treating a local git repo as a directory allows testing 
15101522        # uncommitted changes. 
@@ -1529,8 +1541,17 @@ def install(plugin_name: str) -> Union[str, None]:
15291541    except  FileExistsError  as  err :
15301542        log .error (f'File exists: { err .filename }  ' )
15311543        return  None 
1532-     return  _enable_installed (installed , plugin_name )
1544+     except  InstallationFailure  as  err :
1545+         cleanup_plugin_installation (plugin_name )
1546+         if  log .capture :
1547+             log .warning (err )
1548+             return  None 
1549+         raise  err 
15331550
1551+     result  =  _enable_installed (installed , plugin_name )
1552+     if  not  result :
1553+         cleanup_plugin_installation (plugin_name )
1554+     return  result 
15341555
15351556
15361557def  uninstall (plugin_name : str ) ->  str :
0 commit comments