def install_libs(cluster_id, host, token): """Install ipywidgets, databrickslabs_jupyterlab libraries on the driver Args: host (str): host from databricks cli config for given profile string python_path (str): Remote python path to be used for kernel """ python_path = get_python_path(cluster_id) packages = get_local_libs() deps = { p["name"]: p["version"] for p in packages if p["name"] in ["ipywidgets", "ipykernel"] } libs = [ "ipywidgets==%s" % deps["ipywidgets"], "ipykernel==%s" % deps["ipykernel"], "databrickslabs-jupyterlab==%s" % __version__, ] print(" => Installing ", " ".join(libs)) ssh = os.environ.get("SSH") or "ssh" cmd = [ssh, cluster_id, "sudo", python_path + "/pip", "install"] + libs result = execute(cmd) if result["returncode"] == 0: if result["stdout"].startswith("Requirement already satisfied"): return (0, "Requirement already satisfied") else: return (0, "Installed") return (result["returncode"], result["stdout"] + "\n" + result["stderr"])
def install_libs(cluster_id, host, token): """Install ipywidgets, sidecar and databrickslabs_jupyterlab libraries on the driver Args: host (str): host from databricks cli config for given profile string python_path (str): Remote python path to be used for kernel """ python_path = get_python_path(cluster_id) packages = get_local_libs() deps = { p["name"]: p["version"] for p in packages if p["name"] in ["ipywidgets", "sidecar", "ipykernel"] } libs = [ "ipywidgets==%s" % deps["ipywidgets"], "sidecar==%s" % deps["sidecar"], "ipykernel==%s" % deps["ipykernel"], "databrickslabs-jupyterlab==%s" % __version__, ] pip_cmd = [ "%s/pip" % python_path, "install", "-q", "--no-warn-conflicts", "--disable-pip-version-check", ] + libs cmd = ("import subprocess, json; " + ("ret = subprocess.run(%s, stderr=subprocess.PIPE); " % pip_cmd) + "print(json.dumps([ret.returncode, str(ret.stderr)]))") print(" => Installing %s" % ", ".join(libs)) print(" ", end="") try: command = Command(url=host, cluster_id=cluster_id, token=token) result = command.execute(cmd) command.close() print() except DatabricksApiException as ex: print("REST API error", ex) return False if result[0] == 0: return tuple(json.loads(utf8_decode(result[1]))) else: return result
def version_check(cluster_id, host, token, flag): """Compare local and remote library versions Args: cluster_id (str): Cluster ID host (str): host from databricks cli config for given profile string token (str): token from databricks cli config for given profile string flag (str): all|diff|same """ def normalize(key): return key.lower().replace("-", "_") packages = get_local_libs() deps = {normalize(p["name"]): p["version"] for p in packages} result = get_remote_packages(cluster_id, host, token) if result[0] == 0: remote_packages = json.loads(result[1]) else: return remote_deps = {normalize(p["name"]): p["version"] for p in remote_packages} joint_keys = sorted(list(set(list(deps.keys()) + list(remote_deps.keys())))) print("%-30s %-10s%-10s" % ("Package", "local", "remote")) if str(flag) == "all": scope = joint_keys elif str(flag) == "same": scope = [ key for key in joint_keys if deps.get(key, None) == remote_deps.get(key, None) ] else: scope = [ key for key in joint_keys if deps.get(key, None) != remote_deps.get(key, None) # and deps.get(key, None) is not None and remote_deps.get(key, None) is not None ] for key in scope: result = "%-30s %-10s %-10s" % (key, deps.get( key, "--"), remote_deps.get(key, "--")) if deps.get(key) == remote_deps.get(key): print_ok(result) else: print_error(result)