Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an 'all' flag to uninstall all labextensions in the app-dir #6058

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion jupyterlab/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ def install_extension(extension, app_dir=None, logger=None):
return handler.install_extension(extension)


def uninstall_extension(name, app_dir=None, logger=None):
def uninstall_extension(name=None, app_dir=None, logger=None, all_=False):
"""Uninstall an extension by name or path.

Returns `True` if a rebuild is recommended, `False` otherwise.
"""
logger = _ensure_logger(logger)
_node_check(logger)
handler = _AppHandler(app_dir, logger)
if all_ is True:
return handler.uninstall_all_extensions()
return handler.uninstall_extension(name)


Expand Down Expand Up @@ -615,6 +617,17 @@ def uninstall_extension(self, name):
self.logger.warn('No labextension named "%s" installed' % name)
return False

def uninstall_all_extensions(self):
"""Uninstalls all extensions

Returns `True` if a rebuild is recommended, `False` otherwise
"""
should_rebuild = False
for (extname, _) in self.info['extensions'].items():
uninstalled = self.uninstall_extension(extname)
should_rebuild = should_rebuild or uninstalled
return should_rebuild

def update_all_extensions(self):
"""Update all non-local extensions.

Expand Down
12 changes: 11 additions & 1 deletion jupyterlab/labextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"Update all extensions"
)

uninstall_flags = copy(flags)
uninstall_flags['all'] = (
{'UninstallLabExtensionApp': {'all': True}},
"Uninstall all extensions"
)

aliases = dict(base_aliases)
aliases['app-dir'] = 'BaseExtensionApp.app_dir'

Expand Down Expand Up @@ -158,11 +164,15 @@ def run_task(self):

class UninstallLabExtensionApp(BaseExtensionApp):
description = "Uninstall labextension(s) by name"
flags = uninstall_flags

all = Bool(False, config=True,
help="Whether to uninstall all extensions")

def run_task(self):
self.extra_args = self.extra_args or [os.getcwd()]
return any([
uninstall_extension(arg, self.app_dir, logger=self.log)
uninstall_extension(arg, all_=self.all, app_dir=self.app_dir, logger=self.log)
for arg in self.extra_args
])

Expand Down
15 changes: 14 additions & 1 deletion jupyterlab/tests/test_jupyterlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
build, link_package, unlink_package, build_check,
disable_extension, enable_extension, get_app_info,
check_extension, _test_overlap, _get_core_data,
update_extension,
update_extension
)

here = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -196,6 +196,19 @@ def test_uninstall_extension(self):
assert name not in extensions
assert not check_extension(name)

def test_uninstall_all_extensions(self):
install_extension(self.mock_extension)
install_extension(self.mock_mimeextension)
ext_name = self.pkg_names['extension']
mime_ext_name = self.pkg_names['mimeextension']
assert check_extension(ext_name) is True
assert check_extension(mime_ext_name) is True
assert uninstall_extension(all_=True) is True
extensions = get_app_info(self.app_dir)['extensions']
assert ext_name not in extensions
assert mime_ext_name not in extensions


def test_uninstall_core_extension(self):
assert uninstall_extension('@jupyterlab/console-extension') is True
app_dir = self.app_dir
Expand Down