Browse Source

Merge pull request #9326 from martinRenou/federated_ext_package_name_logic

Federated extension script: Change package name logic
Steven Silvester 4 years ago
parent
commit
38fba0e759
1 changed files with 13 additions and 17 deletions
  1. 13 17
      jupyterlab/federated_labextensions.py

+ 13 - 17
jupyterlab/federated_labextensions.py

@@ -45,18 +45,18 @@ HERE = osp.abspath(osp.dirname(__file__))
 
 
 def develop_labextension(path, symlink=True, overwrite=False,
 def develop_labextension(path, symlink=True, overwrite=False,
                         user=False, labextensions_dir=None,
                         user=False, labextensions_dir=None,
-                        destination=None, 
+                        destination=None,
                         logger=None, sys_prefix=False
                         logger=None, sys_prefix=False
                         ):
                         ):
     """Install a federated extension for JupyterLab
     """Install a federated extension for JupyterLab
-    
+
     Stages files and/or directories into the labextensions directory.
     Stages files and/or directories into the labextensions directory.
     By default, this compares modification time, and only stages files that need updating.
     By default, this compares modification time, and only stages files that need updating.
     If `overwrite` is specified, matching files are purged before proceeding.
     If `overwrite` is specified, matching files are purged before proceeding.
-    
+
     Parameters
     Parameters
     ----------
     ----------
-    
+
     path : path to file, directory, zip or tarball archive, or URL to install
     path : path to file, directory, zip or tarball archive, or URL to install
         By default, the file will be installed with its base name, so '/path/to/foo'
         By default, the file will be installed with its base name, so '/path/to/foo'
         will install to 'labextensions/foo'. See the destination argument below to change this.
         will install to 'labextensions/foo'. See the destination argument below to change this.
@@ -84,10 +84,10 @@ def develop_labextension(path, symlink=True, overwrite=False,
     labext = _get_labextension_dir(user=user, sys_prefix=sys_prefix, labextensions_dir=labextensions_dir)
     labext = _get_labextension_dir(user=user, sys_prefix=sys_prefix, labextensions_dir=labextensions_dir)
     # make sure labextensions dir exists
     # make sure labextensions dir exists
     ensure_dir_exists(labext)
     ensure_dir_exists(labext)
-    
+
     if isinstance(path, (list, tuple)):
     if isinstance(path, (list, tuple)):
         raise TypeError("path must be a string pointing to a single extension to install; call this function multiple times to install multiple extensions")
         raise TypeError("path must be a string pointing to a single extension to install; call this function multiple times to install multiple extensions")
-    
+
     path = cast_unicode_py2(path)
     path = cast_unicode_py2(path)
 
 
     if not destination:
     if not destination:
@@ -257,7 +257,7 @@ def _ensure_builder(ext_path, core_path):
         target = osp.dirname(target)
         target = osp.dirname(target)
 
 
     return osp.join(target, 'node_modules', '@jupyterlab', 'builder', 'lib', 'build-labextension.js')
     return osp.join(target, 'node_modules', '@jupyterlab', 'builder', 'lib', 'build-labextension.js')
-    
+
 
 
 def _should_copy(src, dest, logger=None):
 def _should_copy(src, dest, logger=None):
     """Should a file be copied, if it doesn't exist, or is newer?
     """Should a file be copied, if it doesn't exist, or is newer?
@@ -369,16 +369,12 @@ def _get_labextension_metadata(module):
         mod_path = osp.abspath(module)
         mod_path = osp.abspath(module)
         if osp.exists(mod_path):
         if osp.exists(mod_path):
 
 
-            # First see if the module is already installed
-            from setuptools import find_packages
-            packages = find_packages(mod_path)
-
-            # If not, get the package name from setup.py
-            if not packages:
-                name = subprocess.check_output([sys.executable, 'setup.py', '--name'], cwd=mod_path)
-                packages = [name.decode('utf8').strip()]
-            
-            package = packages[0]
+            # Try getting the package name from setup.py
+            try:
+                package = subprocess.check_output([sys.executable, 'setup.py', '--name'], cwd=mod_path).decode('utf8').strip()
+            except subprocess.CalledProcessError:
+                from setuptools import find_packages
+                package = find_packages(mod_path)[0]
 
 
             # Make sure the package is installed
             # Make sure the package is installed
             import pkg_resources
             import pkg_resources