Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Fully handle uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Silvester committed Jul 31, 2020
1 parent d2dc6a5 commit a89a6a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
33 changes: 27 additions & 6 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,25 +805,46 @@ def uninstall_extension(self, name):
Returns `True` if a rebuild is recommended, `False` otherwise.
"""
info = self.info
logger = self.logger

# Handle dynamic extensions first
if name in info['dynamic_exts']:
data = info['dynamic_exts'].pop(name)
target = os.path.dirname(data['ext_dir'])
logger.info("Removing: %s" % target)
if os.path.isdir(target) and not os.path.islink(target):
shutil.rmtree(target)
else:
os.remove(target)
# Remove empty parent dir if necessary
if '/' in data['name']:
files = os.listdir(os.path.dirname(target))
if not len(files):
target = os.path.dirname(target)
if os.path.isdir(target) and not os.path.islink(target):
shutil.rmtree(target)
return False

# Allow for uninstalled core extensions.
if name in self.info['core_extensions']:
if name in info['core_extensions']:
config = self._read_build_config()
uninstalled = config.get('uninstalled_core_extensions', [])
if name not in uninstalled:
self.logger.info('Uninstalling core extension %s' % name)
logger.info('Uninstalling core extension %s' % name)
uninstalled.append(name)
config['uninstalled_core_extensions'] = uninstalled
self._write_build_config(config)
return True
return False

local = self.info['local_extensions']
local = info['local_extensions']

for (extname, data) in self.info['extensions'].items():
for (extname, data) in info['extensions'].items():
path = data['path']
if extname == name:
msg = 'Uninstalling %s from %s' % (name, osp.dirname(path))
self.logger.info(msg)
logger.info(msg)
os.remove(path)
# Handle local extensions.
if extname in local:
Expand All @@ -833,7 +854,7 @@ def uninstall_extension(self, name):
self._write_build_config(config)
return True

self.logger.warn('No labextension named "%s" installed' % name)
logger.warn('No labextension named "%s" installed' % name)
return False

def uninstall_all_extensions(self):
Expand Down
22 changes: 0 additions & 22 deletions labextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,28 +242,6 @@ class UninstallLabExtensionApp(BaseExtensionApp):

def run_task(self):
self.extra_args = self.extra_args or [os.getcwd()]
# TODO: uninstall dynamic extension first

for name in self.extra_args:
for ext_dir in jupyter_path('labextensions'):
ext_pattern = ext_dir + '/**/package.json.orig'
for ext_path in [path for path in glob(ext_pattern, recursive=True)]:
with open(ext_path) as fid:
data = json.load(fid)
if data['name'] == name:
target = os.path.dirname(ext_path)
self.log.info("Removing: %s" % target)
if os.path.isdir(target) and not os.path.islink(target):
shutil.rmtree(target)
else:
os.remove(target)
# Remove empty parent dir if necessary
if '/' in data['name']:
files = os.listdir(os.path.dirname(target))
if not len(files):
target = os.path.dirname(target)
if os.path.isdir(target) and not os.path.islink(target):
shutil.rmtree(target)

options = AppOptions(
app_dir=self.app_dir, logger=self.log,
Expand Down

0 comments on commit a89a6a2

Please sign in to comment.