Repository: microsoft/nni
File: setup.py (Python)

Code before:

Build wheel package:

  $ NNI_RELEASE=2.0 python setup.py build_ts
  $ NNI_RELEASE=2.0 python setup.py bdist_wheel -p manylinux1_x86_64

for jupyterlab 2.x package:
  $ JUPYTER_LAB_VERSION=2.3.1 NNI_RELEASE=2.0 python setup.py build_ts
  $ JUPYTER_LAB_VERSION=2.3.1 NNI_RELEASE=2.0 python setup.py bdist_wheel -p manylinux1_x86_64

Where "2.0" is version string and "manylinux1_x86_64" is platform.
The platform may also be "macosx_10_9_x86_64" or "win_amd64".

`build_ts` must be manually invoked before `bdist_wheel`,
or setuptools cannot locate JS files which should be packed into wheel.
"""

from distutils.cmd import Command
from distutils.command.build import build
from distutils.command.clean import clean
import glob
import os
import shutil
import sys

import jupyterlab
import setuptools
from setuptools.command.develop import develop

import setup_ts

release = os.environ.get('NNI_RELEASE')

jupyter_lab_version = jupyterlab.__version__.split('.')[0]

def check_jupyter_lab_version():
    environ_version = os.environ.get('JUPYTER_LAB_VERSION')

    if environ_version:
        if jupyterlab.__version__.split('.')[0] != environ_version.split('.')[0]:
            sys.exit(f'ERROR: To build a jupyter lab extension, run "JUPYTER_LAB_VERSION={jupyterlab.__version__}", current: {environ_version} ')
    elif jupyterlab.__version__.split('.')[0] != '3':
            sys.exit(f'ERROR: To build a jupyter lab extension, run "JUPYTER_LAB_VERSION={jupyterlab.__version__}" first for nondefault version(3.x)')

def _setup():
    setuptools.setup(
        name = 'nni',
        version = release or '999.dev0',
        description = 'Neural Network Intelligence project',
        long_description = open('README.md', encoding='utf-8').read(),
        long_description_content_type = 'text/markdown',

Review comment (bug):
Please add try-catch for this import. The script should not crash when building machine has not installed jupyter.
And I personally suggest put this and `jupyter_lab_version = ...` into a function `get_jupyter_lab_version()`.

Code after:

Build wheel package:

  $ NNI_RELEASE=2.0 python setup.py build_ts
  $ NNI_RELEASE=2.0 python setup.py bdist_wheel -p manylinux1_x86_64

for jupyterlab 2.x package:
  $ JUPYTER_LAB_VERSION=2.3.1 NNI_RELEASE=2.0 python setup.py build_ts
  $ JUPYTER_LAB_VERSION=2.3.1 NNI_RELEASE=2.0 python setup.py bdist_wheel -p manylinux1_x86_64

Where "2.0" is version string and "manylinux1_x86_64" is platform.
The platform may also be "macosx_10_9_x86_64" or "win_amd64".

`build_ts` must be manually invoked before `bdist_wheel`,
or setuptools cannot locate JS files which should be packed into wheel.
"""

from distutils.cmd import Command
from distutils.command.build import build
from distutils.command.clean import clean
import glob
import os
import shutil
import sys

import setuptools
from setuptools.command.develop import develop

import setup_ts

release = os.environ.get('NNI_RELEASE')

def _get_jupyter_lab_version():
    try:
        import jupyterlab
        return jupyterlab.__version__
    except ImportError:
        return '3.x'

jupyter_lab_major_version = _get_jupyter_lab_version().split('.')[0]

def check_jupyter_lab_version():
    environ_version = os.environ.get('JUPYTER_LAB_VERSION')

    jupyter_lab_version = _get_jupyter_lab_version()

    if environ_version:
        if jupyter_lab_version.split('.')[0] != environ_version.split('.')[0]:
            sys.exit(f'ERROR: To build a jupyter lab extension, run "JUPYTER_LAB_VERSION={jupyter_lab_version}", current: {environ_version} ')
    elif jupyter_lab_version.split('.')[0] != '3':
        sys.exit(f'ERROR: To build a jupyter lab extension, run "JUPYTER_LAB_VERSION={jupyter_lab_version}" first for nondefault version(3.x)')