Skip to content

Commit

Permalink
start 3/4 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Oct 24, 2023
1 parent 8eb2afb commit ae53683
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _output/
.env
.ipynb_checkpoints/
.pabotsuitenames
.venv/
.venv*/
.yarn-packages/
*.doit.*
*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion atest/resources/CodeMirror.resource
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Library JupyterLibrary
*** Keywords ***
Initialize CodeMirror
[Documentation] Fix apparently-broken CSS/JS variable updates.
Update Globals For JupyterLab 4
Update Globals For JupyterLab Version
Set Suite Variable ${CM CSS EDITOR} ${CM CSS EDITOR} children=${TRUE}
Set Suite Variable ${CM JS INSTANCE} ${CM JS INSTANCE} children=${TRUE}

Expand Down
3 changes: 3 additions & 0 deletions atest/resources/LabSelectors.resource
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ ${CSS_LAB_CMD_MARKDOWN_PREVIEW} [data-command="fileeditor:markdown-preview"]
# lab 7
${XP_LAB4_COLLAPSED_PANEL} //*[contains(@class, 'jp-Collapse-header-collapsed')]
${XP_LAB4_COLLAPSED_PANEL_TITLE} ${XP_LAB4_COLLAPSED_PANEL}//*[contains(@class, 'jp-Collapser-title')]

# rfjl bugs
${CM CSS EDITOR} .CodeMirror
5 changes: 3 additions & 2 deletions atest/resources/Screenshots.resource
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Resume Screenshots

Empty Screenshot Trash
[Documentation] Clean out trash.
Run Keyword And Ignore Error
... Remove Directory ${SCREENSHOT_TRASH} ${TRUE}
Log TODO: restore
# Run Keyword And Ignore Error
# ... Remove Directory ${SCREENSHOT_TRASH} ${TRUE}

Capture Page Screenshot And Tag With Error
[Documentation] Capture a screenshot if not going to the trash
Expand Down
1 change: 0 additions & 1 deletion atest/resources/Server.resource
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Build Custom JupyterLab Args
... --port\=${port}
... --IdentityProvider.token\=${token}
... --ServerApp.base_url\=${base url}
... --LabApp.check_for_updates_class\=jupyterlab.NeverCheckForUpdate
Log ${args}
RETURN @{args}

Expand Down
174 changes: 113 additions & 61 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class C:
PY_VERSION = f"{sys.version_info[0]}.{sys.version_info[1]}"
ROBOT_DRYRUN = "--dryrun"
NYC = ["jlpm", "nyc", "report"]
HISTORY = "conda-meta/history"
CONDA_RUN = ["conda", "run", "--no-capture-output", "--prefix"]


class P:
Expand Down Expand Up @@ -127,7 +129,9 @@ class E:

class B:
ENV = P.ROOT / ".venv" if E.LOCAL else Path(sys.prefix)
HISTORY = [ENV / "conda-meta/history"] if E.LOCAL else []
HISTORY = [ENV / C.HISTORY] if E.LOCAL else []
ENV_LEGACY = P.ROOT / ".venv-legacy" if E.LOCAL else Path(sys.prefix)
HISTORY_LEGACY = ENV_LEGACY / C.HISTORY
NODE_MODULES = P.ROOT / "node_modules"
YARN_INTEGRITY = NODE_MODULES / ".yarn-state.yml"
JS_META_TSBUILDINFO = P.JS_META / ".src.tsbuildinfo"
Expand Down Expand Up @@ -301,15 +305,21 @@ def update_env_fragments(dest_env: Path, src_envs: typing.List[Path]):
dest_env.write_text(dest_text.strip() + "\n")

@staticmethod
def make_robot_tasks(extra_args=None):
def make_robot_tasks(lab_env=None, extra_args=None):
lab_env = lab_env or B.ENV
extra_args = extra_args or []
name = "robot"
file_dep = [*B.HISTORY, *L.ALL_ROBOT]
file_dep = [lab_env / C.HISTORY, *L.ALL_ROBOT]
if C.ROBOT_DRYRUN in extra_args:
name = f"{name}:dryrun"
else:
file_dep += [B.PIP_FROZEN, *L.ALL_PY_SRC, *L.ALL_TS, *L.ALL_JSON]
out_dir = B.ROBOT / U.get_robot_stem(attempt=1, extra_args=extra_args)
name = f"{name}:{lab_env.name}"
out_dir = B.ROBOT / U.get_robot_stem(
lab_env=lab_env,
attempt=1,
extra_args=extra_args,
)
targets = [
out_dir / "output.xml",
out_dir / "log.html",
Expand All @@ -328,12 +338,12 @@ def make_robot_tasks(extra_args=None):
doit.tools.config_changed({"cov": E.WITH_JS_COV, "args": E.ROBOT_ARGS}),
],
"file_dep": file_dep,
"actions": [*actions, (U.run_robot_with_retries, [extra_args])],
"actions": [*actions, (U.run_robot_with_retries, [lab_env, extra_args])],
"targets": targets,
}

@staticmethod
def run_robot_with_retries(extra_args=None):
def run_robot_with_retries(lab_env, extra_args=None):
extra_args = [*(extra_args or []), *E.ROBOT_ARGS]
is_dryrun = C.ROBOT_DRYRUN in extra_args

Expand All @@ -350,7 +360,7 @@ def run_robot_with_retries(extra_args=None):
attempt += 1
print(f"attempt {attempt} of {retries + 1}...", flush=True)
start_time = time.time()
fail_count = U.run_robot(attempt=attempt, extra_args=extra_args)
fail_count = U.run_robot(lab_env, attempt=attempt, extra_args=extra_args)
print(
fail_count,
"failed in",
Expand Down Expand Up @@ -383,9 +393,14 @@ def run_robot_with_retries(extra_args=None):
if p != final and "dry_run" not in str(p) and "pabot_results" not in str(p)
]

runner = ["python"]

if lab_env != B.ENV:
runner = [*C.CONDA_RUN, str(lab_env), *runner]

subprocess.call(
[
"python",
*runner,
"-m",
"robot.rebot",
"--name",
Expand All @@ -408,26 +423,56 @@ def run_robot_with_retries(extra_args=None):
return fail_count == 0

@staticmethod
def get_robot_stem(attempt=0, extra_args=None, browser="headlessfirefox"):
def get_robot_stem(
lab_env: Path,
attempt=0,
extra_args=None,
browser="headlessfirefox",
):
"""Get the directory in B.ROBOT for this platform/app."""
extra_args = extra_args or []

browser = browser.replace("headless", "")

stem = f"{C.PLATFORM[:3].lower()}_{C.PY_VERSION}_{browser}_{attempt}"
stem = f"{C.PLATFORM[:3].lower()}_{C.PY_VERSION}_{lab_env.name}_{browser}_{attempt}"

if C.ROBOT_DRYRUN in extra_args:
stem = "dry_run"

return stem

@staticmethod
def run_robot(attempt=0, extra_args=None):
def prep_robot(out_dir: Path):
if out_dir.exists():
print(f">>> trying to clean out {out_dir}", flush=True)
try:
shutil.rmtree(out_dir)
except Exception as err:
print(
f"... error, hopefully harmless: {err}",
flush=True,
)

if not out_dir.exists():
print(
f">>> trying to prepare output directory: {out_dir}",
flush=True,
)
try:
out_dir.mkdir(parents=True)
except Exception as err:
print(
f"... Error, hopefully harmless: {err}",
flush=True,
)

@staticmethod
def run_robot(lab_env: Path, attempt=0, extra_args=None):
import lxml.etree as ET

extra_args = extra_args or []

stem = U.get_robot_stem(attempt=attempt, extra_args=extra_args)
stem = U.get_robot_stem(lab_env, attempt=attempt, extra_args=extra_args)
out_dir = B.ROBOT / stem

if attempt > 1:
Expand All @@ -444,6 +489,10 @@ def run_robot(attempt=0, extra_args=None):
*E.PABOT_ARGS,
]

if lab_env == B.ENV_LEGACY:
runner = [*C.CONDA_RUN, str(lab_env), *runner]
extra_args += ["--exclude", "app:nb"]

if C.ROBOT_DRYRUN in extra_args:
runner = ["robot"]

Expand All @@ -464,40 +513,12 @@ def run_robot(attempt=0, extra_args=None):
*extra_args,
]

if out_dir.exists():
print(f">>> trying to clean out {out_dir}", flush=True)
try:
shutil.rmtree(out_dir)
except Exception as err:
print(
f"... error, hopefully harmless: {err}",
flush=True,
)

if not out_dir.exists():
print(
f">>> trying to prepare output directory: {out_dir}",
flush=True,
)
try:
out_dir.mkdir(parents=True)
except Exception as err:
print(
f"... Error, hopefully harmless: {err}",
flush=True,
)
str_args = [*map(str, [*args, P.ROBOT_SUITES])]

str_args = [
*map(
str,
[
*args,
P.ROBOT_SUITES,
],
),
]
print(">>> ", " ".join(str_args), flush=True)

U.prep_robot(out_dir)

proc = subprocess.Popen(str_args, cwd=P.ATEST)

try:
Expand Down Expand Up @@ -589,6 +610,27 @@ def task_setup():
],
}

legacy_pip = [*C.CONDA_RUN, B.ENV_LEGACY, "python", "-m", "pip"]

yield {
"name": "conda:legacy",
"file_dep": [P.TEST_35_ENV_YAML, B.WHEEL],
"targets": [B.HISTORY_LEGACY],
"actions": [
[
"mamba",
"env",
"update",
"--prefix",
B.ENV_LEGACY,
"--file",
P.TEST_35_ENV_YAML,
],
[*legacy_pip, "install", "--no-deps", "--ignore-installed", B.WHEEL],
[*legacy_pip, "check"],
],
}

if E.LOCAL or not B.YARN_INTEGRITY.exists():
yield {
"name": "yarn",
Expand Down Expand Up @@ -802,6 +844,7 @@ def task_test():
}

yield from U.make_robot_tasks()
yield from U.make_robot_tasks(lab_env=B.ENV_LEGACY)


def task_lint():
Expand Down Expand Up @@ -917,7 +960,13 @@ def task_build():

uptodate = [doit.tools.config_changed({"WITH_JS_COV": E.WITH_JS_COV})]

ext_dep = [*P.JS_PACKAGE_JSONS, P.EXT_JS_WEBPACK, *L.ALL_CSS_SRC]
ext_dep = [
*P.JS_PACKAGE_JSONS,
P.EXT_JS_WEBPACK,
*L.ALL_CSS_SRC,
*L.ALL_TS,
*L.ALL_CSS_SRC,
]

if E.WITH_JS_COV:
ext_task = "labextension:build:cov"
Expand Down Expand Up @@ -992,22 +1041,18 @@ def task_lite():
def task_serve():
import subprocess

def lab():
proc = subprocess.Popen(
list(
map(
str,
[
"jupyter",
"lab",
"--no-browser",
"--debug",
"--LanguageServerManager.autodetect=0",
],
),
),
stdin=subprocess.PIPE,
)
def lab(lab_env: Path, extra_args=None):
args = [
*C.CONDA_RUN,
str(lab_env),
"jupyter",
"lab",
"--no-browser",
"--debug",
"--LanguageServerManager.autodetect=0",
*(extra_args or []),
]
proc = subprocess.Popen(list(map(str, args)), stdin=subprocess.PIPE)

try:
proc.wait()
Expand All @@ -1023,7 +1068,14 @@ def lab():
"name": "lab",
"uptodate": [lambda: False],
"file_dep": [B.ENV_PKG_JSON, B.PIP_FROZEN],
"actions": [doit.tools.PythonInteractiveAction(lab)],
"actions": [doit.tools.PythonInteractiveAction(lab, [B.ENV])],
}

yield {
"name": "lab:legacy",
"uptodate": [lambda: False],
"file_dep": [B.HISTORY_LEGACY],
"actions": [doit.tools.PythonInteractiveAction(lab, [B.ENV_LEGACY])],
}


Expand Down
19 changes: 19 additions & 0 deletions js/jupyterlab-deck/src/labcompat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { toArray } from '@lumino/algorithm';
import { JSONExt } from '@lumino/coreutils';
import type { DockPanel, TabBar, Widget } from '@lumino/widgets';

const { emptyArray } = JSONExt;

export function tabBars(dockPanel: DockPanel): TabBar<Widget>[] {
if (!dockPanel) {
return emptyArray as any as TabBar<Widget>[];
}

let tabBars = dockPanel.tabBars();

if (Array.isArray(tabBars)) {
return tabBars;
}

return toArray(tabBars);
}
9 changes: 5 additions & 4 deletions js/jupyterlab-deck/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Signal, ISignal } from '@lumino/signaling';
import { Widget, DockPanel } from '@lumino/widgets';

import { ICONS } from './icons';
import { tabBars } from './labcompat';
import {
IDeckManager,
DATA,
Expand Down Expand Up @@ -164,8 +165,8 @@ export class DeckManager implements IDeckManager {
}
document.body.dataset[DATA.deckMode] = DATA.presenting;
if (this._dockPanel) {
for (const tabBar of this._dockPanel.tabBars()) {
tabBar.hide();
for (const bar of tabBars(this._dockPanel)) {
bar.hide();
}
}
if (_labShell) {
Expand Down Expand Up @@ -246,8 +247,8 @@ export class DeckManager implements IDeckManager {
}

if (_dockPanel) {
for (const tabBar of _dockPanel.tabBars()) {
tabBar.show();
for (const bar of tabBars(_dockPanel)) {
bar.show();
}
}

Expand Down

0 comments on commit ae53683

Please sign in to comment.