Commit 29af7ecb authored by Nicholas Bollweg's avatar Nicholas Bollweg
Browse files

start integrating pyolite packages

parent e2d053b1
......@@ -123,8 +123,6 @@ app/test/data
# do not include kernels such as Pyodide
app/kernels
yarn-error.log
!packages/pyolite-kernel/py/dist/
*.log
.doit*
......@@ -6,20 +6,6 @@ import tarfile
import shutil
from pathlib import Path
os.environ.update(
NODE_OPTS="--max-old-space-size=4096",
PYTHONIOENCODING="utf-8",
PIP_DISABLE_PIP_VERSION_CHECK="1",
MAMBA_NO_BANNER="1",
)
DOIT_CONFIG = {
"backend": "sqlite3",
"verbosity": 2,
"par_type": "thread",
"default_tasks": ["lint", "build"],
}
def task_setup():
yield dict(
......@@ -34,7 +20,7 @@ def task_lint():
yield U.ok(
B.OK_PRETTIER,
name="prettier",
file_dep=[*P.ALL_PRETTIER, B.YARN_INTEGRITY],
file_dep=[*L.ALL_PRETTIER, B.YARN_INTEGRITY],
actions=[U.do("jlpm", "prettier")],
)
......@@ -48,24 +34,33 @@ def task_lint():
yield U.ok(
B.OK_BLACK,
name="black",
file_dep=P.ALL_BLACK,
actions=[U.do("black", *P.ALL_BLACK)],
file_dep=L.ALL_BLACK,
actions=[U.do("black", *L.ALL_BLACK)],
)
def task_build():
yield dict(
name="js:lib",
file_dep=[*P.ALL_TS, P.ROOT_PACKAGE_JSON, *P.PACKAGE_JSONS, B.YARN_INTEGRITY],
file_dep=[*L.ALL_TS, P.ROOT_PACKAGE_JSON, *P.PACKAGE_JSONS, B.YARN_INTEGRITY],
actions=[
U.do("jlpm", "build:lib"),
],
targets=[B.META_BUILDINFO],
)
for py_pkg in P.PYOLITE_PACKAGES:
yield dict(
name=f"py:{py_pkg.parent.name}",
file_dep=[*py_pkg.rglob("*.py")],
actions=[
doit.tools.CmdAction(["flit", "build"], shell=False, cwd=py_pkg)
]
)
for app_json in P.APP_JSONS:
app = app_json.parent
app_data = json.loads(app_json.read_text(encoding="utf-8"))
app_data = json.loads(app_json.read_text(**C.ENC))
yield dict(
name=f"js:app:{app.name}",
file_dep=[B.META_BUILDINFO, app_json, P.WEBPACK_CONFIG, app / "index.js"],
......@@ -89,6 +84,7 @@ def task_build():
class C:
NAME = "jupyterlite"
APPS = ["classic", "lab"]
ENC = dict(encoding="utf-8")
class P:
......@@ -99,7 +95,8 @@ class P:
ROOT_PACKAGE_JSON = ROOT / "package.json"
YARN_LOCK = ROOT / "yarn.lock"
PY_SRC = ROOT / "src/jupyterlite"
# set later
PYOLITE_PACKAGES = []
APP = ROOT / "app"
APP_PACKAGE_JSON = APP / "package.json"
......@@ -116,18 +113,30 @@ class P:
# CI
CI = ROOT / ".github"
# linting
ALL_TS = [*PACKAGES.rglob("*/src/**/*.js"), *PACKAGES.rglob("*/src/**/*.ts")]
ALL_JSON = [*PACKAGE_JSONS, *APP_JSONS, ROOT_PACKAGE_JSON, *ALL_TS]
ALL_MD = [CONTRIBUTING, README, *CI.rglob("*.md")]
ALL_YAML = [*BINDER.glob("*.yml"), *CI.rglob("*.yml")]
ALL_PRETTIER = [*ALL_JSON, *ALL_MD, *ALL_YAML]
ALL_BLACK = [DODO]
class D:
# DATA
APP = json.loads(P.APP_PACKAGE_JSON.read_text(encoding="utf-8"))
# data
APP = json.loads(P.APP_PACKAGE_JSON.read_text(**C.ENC))
PACKAGE_JSONS = {
p.parent.name: json.loads(p.read_text(**C.ENC)) for p in P.PACKAGE_JSONS
}
P.PYOLITE_PACKAGES = [
P.PACKAGES / pkg / pyp
for pkg, pkg_data in D.PACKAGE_JSONS.items()
for pyp in pkg_data.get("pyolite", {}).get("packages", [])
]
class L:
# linting
ALL_TS = [*P.PACKAGES.rglob("*/src/**/*.js"), *P.PACKAGES.rglob("*/src/**/*.ts")]
ALL_JSON = [*P.PACKAGE_JSONS, *P.APP_JSONS, P.ROOT_PACKAGE_JSON, *ALL_TS]
ALL_MD = [P.CONTRIBUTING, P.README, *P.CI.rglob("*.md")]
ALL_YAML = [*P.BINDER.glob("*.yml"), *P.CI.rglob("*.yml")]
ALL_PRETTIER = [*ALL_JSON, *ALL_MD, *ALL_YAML]
ALL_BLACK = [P.DODO, *sum([[*p.rglob("*.py")] for p in P.PYOLITE_PACKAGES], [])]
class B:
......@@ -164,3 +173,19 @@ class U:
lambda: [ok.touch(), None][-1],
]
return task
# environment overloads
os.environ.update(
NODE_OPTS="--max-old-space-size=4096",
PYTHONIOENCODING=C.ENC["encoding"],
PIP_DISABLE_PIP_VERSION_CHECK="1",
)
# doit configuration
DOIT_CONFIG = {
"backend": "sqlite3",
"verbosity": 2,
"par_type": "thread",
"default_tasks": ["lint", "build"],
}
......@@ -61,6 +61,11 @@
"ts-jest": "^26.3.0",
"typescript": "~4.2.3"
},
"pyolite": {
"packages": [
"py/pyolite"
]
},
"publishConfig": {
"access": "public"
}
......
import base64
MIMETYPES = [
('text/html', '_repr_html_'),
('text/markdown', '_repr_markdown_'),
('text/latex', '_repr_latex_'),
('image/svg+xml', '_repr_svg_'),
('image/png', '_repr_png_'),
('application/json', '_repr_json_'),
MIMETYPES = [
("text/html", "_repr_html_"),
("text/markdown", "_repr_markdown_"),
("text/latex", "_repr_latex_"),
("image/svg+xml", "_repr_svg_"),
("image/png", "_repr_png_"),
("application/json", "_repr_json_"),
]
......@@ -20,6 +20,7 @@ class DisplayPublisher:
formatted = format_result(obj)
self.display_callback(formatted)
display_publisher = DisplayPublisher()
......@@ -34,10 +35,7 @@ def format_result(result):
if hasattr(result, method):
# TODO: repr methods should return data and metadata
data[mimetype] = getattr(result, method)()
bundle = {
'data': data,
'metadata': metadata
}
bundle = {"data": data, "metadata": metadata}
return bundle
......@@ -69,9 +67,9 @@ class JSON(DisplayObject):
return self.data
class Image():
class Image:
def __init__(self, data):
self.data = base64.b64encode(data).decode()
def _repr_png_(self):
return self.data
\ No newline at end of file
return self.data
from io import BytesIO
import os
os.environ['MPLBACKEND'] = 'AGG'
os.environ["MPLBACKEND"] = "AGG"
import matplotlib.pyplot
......@@ -13,7 +13,7 @@ def ensure_matplotlib_patch():
def show():
buf = BytesIO()
matplotlib.pyplot.savefig(buf, format='png')
matplotlib.pyplot.savefig(buf, format="png")
buf.seek(0)
display(Image(buf.read()))
matplotlib.pyplot.clf()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment