Browse Source

Add back replace hyphens with underscores

Carlos Herrero 4 years ago
parent
commit
99629c3f1e
3 changed files with 17 additions and 9 deletions
  1. 16 8
      jupyterlab/federated_labextensions.py
  2. 0 0
      scripts/ci_install.sh
  3. 1 1
      scripts/ci_script.sh

+ 16 - 8
jupyterlab/federated_labextensions.py

@@ -362,7 +362,7 @@ def _get_labextension_metadata(module):
 
     mod_path = osp.abspath(module)
     if not osp.exists(mod_path):
-        raise FileNotFoundError('The path `{}` does not exist.'.format(module))
+        raise FileNotFoundError('The path `{}` does not exist.'.format(mod_path))
 
     # Check if the path is a valid labextension
     try:
@@ -392,19 +392,27 @@ def _get_labextension_metadata(module):
         sys.path.insert(0, mod_path)
     
     # Importing module with the same name as package
-    m = importlib.import_module(package)
-    if hasattr(m, '_jupyter_labextension_paths') :
-        return m, m._jupyter_labextension_paths()
-
+    try:
+        # Replace hyphens with underscores to match Python convention
+        package = package.replace('-', '_')
+        m = importlib.import_module(package)
+        if hasattr(m, '_jupyter_labextension_paths') :
+            return m, m._jupyter_labextension_paths()
+    except Exception:
+        m = None
+    
     # Looking for modules in the package
     from setuptools import find_packages
     packages = find_packages(mod_path)
 
     # Looking for the labextension metadata
     for package in packages :
-        m = importlib.import_module(package)
-        if hasattr(m, '_jupyter_labextension_paths') :
-            return m, m._jupyter_labextension_paths()
+        try:
+            m = importlib.import_module(package)
+            if hasattr(m, '_jupyter_labextension_paths') :
+                return m, m._jupyter_labextension_paths()
+        except Exception:
+            m = None
 
     raise ModuleNotFoundError('There is not a labextensions at {}'.format(module))
 

+ 0 - 0
scripts/ci_install.sh


+ 1 - 1
scripts/ci_script.sh

@@ -193,7 +193,7 @@ if [[ $GROUP == usage ]]; then
     # Test develop script with hyphens and underscores in the module name
     jupyter labextension develop test-hyphens --debug
     jupyter labextension develop test_no_hyphens --debug
-    jupyter labextension develop test-hyphens-underscores --debug
+    jupyter labextension develop test-hyphens-underscore --debug
 
     python -m jupyterlab.browser_check
     jupyter labextension list 1>labextensions 2>&1