Browse Source

Clean up handling of python version

Steven Silvester 8 years ago
parent
commit
934248fe41
4 changed files with 13 additions and 11 deletions
  1. 1 6
      jupyterlab/__init__.py
  2. 2 0
      jupyterlab/labapp.py
  3. 1 1
      jupyterlab/labextensions.py
  4. 9 4
      setup.py

+ 1 - 6
jupyterlab/__init__.py

@@ -10,7 +10,7 @@ from tornado import web
 from notebook.base.handlers import IPythonHandler, FileFindHandler
 from jinja2 import FileSystemLoader
 from notebook.utils import url_path_join as ujoin
-
+from ._version import __version__
 
 #-----------------------------------------------------------------------------
 # Module globals
@@ -32,11 +32,6 @@ BUILT_FILES = os.path.join(HERE, 'build')
 PREFIX = '/lab'
 EXTENSION_PREFIX = '/labextension'
 
-with open(os.path.join(os.path.dirname(HERE), 'package.json')) as f:
-    packagejson = json.load(f)
-
-__version__ = packagejson['version']
-
 
 def get_labextension_manifest_data_by_folder(folder):
     """Get the manifest data for a given lab extension folder

+ 2 - 0
jupyterlab/labapp.py

@@ -12,6 +12,7 @@ from traitlets import List, Unicode, default
 from traitlets.config.manager import BaseJSONConfigManager
 
 from .labextensions import validate_labextension
+from ._version import __version__
 
 
 def get_labextensions(parent=None):
@@ -35,6 +36,7 @@ def get_labextensions(parent=None):
 
 
 class LabApp(NotebookApp):
+    version = __version__
 
     description = """
         JupyterLab - An extensible computational environment for Jupyter.

+ 1 - 1
jupyterlab/labextensions.py

@@ -18,7 +18,7 @@ from jupyter_core.paths import (
 )
 from ipython_genutils.path import ensure_dir_exists
 from ipython_genutils.py3compat import string_types, cast_unicode_py2
-from . import __version__
+from ._version import __version__
 
 from traitlets.config.manager import BaseJSONConfigManager
 from traitlets.utils.importstring import import_item

+ 9 - 4
setup.py

@@ -4,21 +4,22 @@
 # Distributed under the terms of the Modified BSD License.
 
 from __future__ import print_function
+from distutils import log
 from setuptools import setup, find_packages, Command
 from setuptools.command.sdist import sdist
 from setuptools.command.build_py import build_py
 from setuptools.command.egg_info import egg_info
 from setuptools.command.bdist_egg import bdist_egg
 from subprocess import check_call
+import json
 import os
 import sys
-import platform
-import shutil
 
 here = os.path.dirname(os.path.abspath(__file__))
 extension_root = os.path.join(here, 'jupyterlab')
 is_repo = os.path.exists(os.path.join(here, '.git'))
 
+
 def run(cmd, cwd=None):
     """Run a command
 
@@ -28,13 +29,14 @@ def run(cmd, cwd=None):
     shell = (sys.platform == 'win32')
     check_call(cmd.split(), shell=shell, cwd=cwd, stdout=sys.stdout, stderr=sys.stderr)
 
-from distutils import log
+
 log.set_verbosity(log.DEBUG)
 log.info('setup.py entered')
 
 DESCRIPTION = 'An alpha preview of the JupyterLab notebook server extension.'
 LONG_DESCRIPTION = 'This is an alpha preview of JupyterLab. It is not ready for general usage yet. Development happens on https://github.com/jupyter/jupyterlab, with chat on https://gitter.im/jupyter/jupyterlab.'
 
+
 def js_prerelease(command, strict=False):
     """decorator for building minified js/css prior to another command"""
     class DecoratedCommand(command):
@@ -119,9 +121,12 @@ class NPM(Command):
         # update package data in case this created new files
         update_package_data(self.distribution)
 
-import json
+
 with open(os.path.join(here, 'package.json')) as f:
     packagejson = json.load(f)
+with open(os.path.join(here, 'jupyterlab', '_version.py'), 'w') as f:
+    f.write('# This file is auto-generated, do not edit!\n')
+    f.write('__version__ = "%s"\n' % packagejson['version'])
 
 setup_args = {
     'name': 'jupyterlab',