Browse Source

Merge pull request #7461 from fcollonval/fix-7456

Fix #7456
Jason Grout 5 years ago
parent
commit
172e664aa6
2 changed files with 21 additions and 1 deletions
  1. 6 1
      jupyterlab/commands.py
  2. 15 0
      jupyterlab/tests/test_registry.py

+ 6 - 1
jupyterlab/commands.py

@@ -1762,8 +1762,13 @@ def _yarn_config(logger):
     -------
     {"yarn config": dict, "npm config": dict} if unsuccessfull the subdictionary are empty
     """
-    node = which('node')
     configuration = {"yarn config": {}, "npm config": {}}
+    try:
+        node = which('node')
+    except ValueError:  # Node not found == user with no need for building jupyterlab
+        logger.debug("NodeJS was not found. Yarn user configuration is ignored.")
+        return configuration
+
     try:
         output_binary = subprocess.check_output([node, YARN_PATH, 'config', 'list', '--json'], stderr=subprocess.PIPE, cwd=HERE)
         output = output_binary.decode('utf-8')

+ 15 - 0
jupyterlab/tests/test_registry.py

@@ -19,6 +19,21 @@ from .test_jupyterlab import AppHandlerTest
 
 class TestAppHandlerRegistry(AppHandlerTest):
 
+    def test_node_not_available(self):
+        # patch should be applied on `jupyterlab.commands` and not on `jupyterlab_server.process`
+        # See https://docs.python.org/3/library/unittest.mock.html#where-to-patch
+        with patch("jupyterlab.commands.which") as which:
+            which.side_effect = ValueError("Command not found")
+
+            logger = logging.getLogger('jupyterlab')
+            config = commands._yarn_config(logger)
+
+            which.assert_called_once_with('node')
+            self.assertDictEqual(config, 
+                {"yarn config": {}, 
+                "npm config": {}}
+            )
+
     def test_yarn_config(self):
         with patch("subprocess.check_output") as check_output:
             yarn_registry = "https://private.yarn/manager"