|
| 1 | +from subprocess import check_call, CalledProcessError |
| 2 | + |
| 3 | + |
| 4 | +FIX_PREFIX = '----->' |
| 5 | + |
| 6 | +tutorial_name = 'Jupyter widget ecosystem' |
| 7 | + |
| 8 | +requirements = [ |
| 9 | + 'notebook', |
| 10 | + 'ipywidgets', |
| 11 | + 'bqplot', |
| 12 | + 'ipyleaflet', |
| 13 | + 'ipyvolume', |
| 14 | + 'pythreejs', |
| 15 | + 'ipyevents', |
| 16 | + 'ipysheet', |
| 17 | + 'ipytree', |
| 18 | + 'pywwt', |
| 19 | + 'jupyterlab' |
| 20 | +] |
| 21 | + |
| 22 | +import_result = {p: False for p in requirements} |
| 23 | + |
| 24 | +print("Checking requirements for {}".format(tutorial_name), end='') |
| 25 | + |
| 26 | +for package in requirements: |
| 27 | + try: |
| 28 | + __import__(package) |
| 29 | + import_result[package] = True |
| 30 | + except ImportError: |
| 31 | + pass |
| 32 | + print('.', end='', flush=True) |
| 33 | + |
| 34 | +print() |
| 35 | +success = all(import_result.values()) |
| 36 | + |
| 37 | +# List compatible versions for each package |
| 38 | +version_check_packages = {'ipywidgets': ['7.5'], |
| 39 | + 'notebook': ['6'], |
| 40 | + 'jupyterlab': ['2'], |
| 41 | + 'ipyvolume': ['0.6.0-alpha.6'], |
| 42 | + } |
| 43 | + |
| 44 | +if success: |
| 45 | + print('\tAll required packages installed') |
| 46 | +else: |
| 47 | + print(FIX_PREFIX, 'Please install these missing packages ' |
| 48 | + 'for the tutorial "{}":'.format(tutorial_name)) |
| 49 | + missing = [k for k, v in import_result.items() if not v] |
| 50 | + print('\t' + '\n\t'.join(missing)) |
| 51 | + |
| 52 | +print('Checking voila version:') |
| 53 | + |
| 54 | +try: |
| 55 | + check_call(['voila', '--version']) |
| 56 | + print('\tVoila is correctly installed') |
| 57 | +except CalledProcessError: |
| 58 | + print('\tVoila is not installed! Please install it by running one ' |
| 59 | + 'of the following:') |
| 60 | + print(' conda install -c conda-forge voila') |
| 61 | + print(' pip install voila') |
| 62 | + |
| 63 | +print('Checking version numbers of these packages: ', |
| 64 | + ', '.join(version_check_packages.keys())) |
| 65 | + |
| 66 | + |
| 67 | +def version_checker(package_name, version, nbextension=None): |
| 68 | + good_version = any(version.startswith(v) for |
| 69 | + v in version_check_packages[package_name]) |
| 70 | + if nbextension is None: |
| 71 | + nbextension = package_name |
| 72 | + if not good_version: |
| 73 | + newest = version_check_packages[package_name][-1] |
| 74 | + print('\n**** Please upgrade {} to version {} by running:'.format(package_name, |
| 75 | + newest)) |
| 76 | + print(' conda install {}={} # if you use conda'.format(package_name, newest)) |
| 77 | + print(' pip install {}=={}'.format(package_name, newest)) |
| 78 | + else: |
| 79 | + print('\t{} version is good!'.format(package_name)) |
| 80 | + |
| 81 | + |
| 82 | +# Check as many packages as we can... |
| 83 | + |
| 84 | + |
| 85 | +try: |
| 86 | + import ipywidgets |
| 87 | +except ImportError: |
| 88 | + pass |
| 89 | +else: |
| 90 | + ipywidgets_version = ipywidgets.__version__ |
| 91 | + version_checker('ipywidgets', ipywidgets_version) |
| 92 | + |
| 93 | +try: |
| 94 | + import notebook |
| 95 | +except ImportError: |
| 96 | + pass |
| 97 | +else: |
| 98 | + notebook_version = notebook.__version__ |
| 99 | + version_checker('notebook', notebook_version) |
| 100 | + |
| 101 | +try: |
| 102 | + import jupyterlab |
| 103 | +except ImportError: |
| 104 | + pass |
| 105 | +else: |
| 106 | + jupyterlab_version = jupyterlab.__version__ |
| 107 | + version_checker('jupyterlab', jupyterlab_version) |
| 108 | + |
| 109 | +try: |
| 110 | + import ipyvolume |
| 111 | +except ImportError: |
| 112 | + pass |
| 113 | +else: |
| 114 | + ipyvolume_version = ipyvolume.__version__ |
| 115 | + version_checker('ipyvolume', ipyvolume_version) |
| 116 | + |
| 117 | +# Check that the appropriate kernel has been created |
| 118 | + |
| 119 | +required_kernel = 'widgets-tutorial' |
| 120 | + |
| 121 | +print('Checking whether kernel {} exists'.format(required_kernel)) |
| 122 | + |
| 123 | +import jupyter_client |
| 124 | + |
| 125 | +known_kernels = list(jupyter_client.kernelspec.find_kernel_specs().keys()) |
| 126 | +if required_kernel not in known_kernels: |
| 127 | + print(FIX_PREFIX, 'Please create custom kernel with: ', |
| 128 | + 'ipython kernel install --name widgets-tutorial --display-name widgets-tutorial --sys-prefix') |
| 129 | +else: |
| 130 | + print('\tCustom kernel is correctly installed') |
| 131 | + |
| 132 | +# Check that lab extensions are installed |
| 133 | + |
| 134 | +print('Checking whether all Jupyter lab extensions are installed') |
| 135 | + |
| 136 | +lab_extensions = [ |
| 137 | + '@jupyter-widgets/jupyterlab-manager', |
| 138 | + '@jupyter-widgets/jupyterlab-sidecar', |
| 139 | + 'bqplot', |
| 140 | + 'jupyter-threejs', |
| 141 | + 'jupyter-leaflet', |
| 142 | + 'ipyvolume', |
| 143 | + 'ipyevents', |
| 144 | + 'ipysheet', |
| 145 | + 'ipytree', |
| 146 | + 'ipycanvas', |
| 147 | + 'jupyter-matplotlib', |
| 148 | + 'jupyter-vuetify', |
| 149 | +] |
| 150 | + |
| 151 | +try: |
| 152 | + from jupyterlab.commands import check_extension |
| 153 | +except ImportError: |
| 154 | + print(FIX_PREFIX, 'Please install jupyterlab before checking extensions.') |
| 155 | +else: |
| 156 | + missing_extensions = [] |
| 157 | + |
| 158 | + for extension in lab_extensions: |
| 159 | + if not check_extension(extension): |
| 160 | + missing_extensions.append(extension) |
| 161 | + |
| 162 | + if missing_extensions: |
| 163 | + print(FIX_PREFIX, 'These lab extensions are missing: ', |
| 164 | + ', '.join(missing_extensions)) |
| 165 | + print(FIX_PREFIX,' Run this to install them: jupyter labextension install ', |
| 166 | + ' '.join(missing_extensions)) |
| 167 | + else: |
| 168 | + print('\tAll extensions are installed!') |
0 commit comments