Skip to content

Commit ec4ded1

Browse files
committed
feat: expand python-agent-driver to 103 pip packages
Add 85 new pip packages to the rootfs, bringing the total from 18 to 103. Six of the new packages (docx, pptx, chardet, charset_normalizer, requests, httpx) are pre-imported during warmup for zero-cost access. Bump heap from 1.5 GB to 2.5 GB across pyhl CLI, pyhl library, pydriver_run, and the Justfile to accommodate the larger initrd. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 20ccc2d commit ec4ded1

6 files changed

Lines changed: 58 additions & 9 deletions

File tree

examples/python-agent-driver/Dockerfile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,35 @@ FROM python:3.12-slim AS deps
1313
RUN pip install --target=/deps --no-cache-dir \
1414
tqdm pyyaml jinja2 beautifulsoup4 tabulate click tenacity \
1515
python-dotenv pypdf openpyxl markdown-it-py pydantic pillow \
16-
lxml cryptography python-dateutil numpy pandas
16+
lxml cryptography python-dateutil numpy pandas \
17+
python-docx python-pptx \
18+
chardet charset-normalizer \
19+
requests httpx aiohttp \
20+
feedparser markdown markdownify \
21+
Faker pycountry \
22+
loguru schedule send2trash \
23+
duckdb polars \
24+
xlrd xlsxwriter pyxlsb odfpy \
25+
pdfplumber pdfrw PyPDF2 \
26+
qrcode svgwrite \
27+
rapidfuzz \
28+
networkx sympy \
29+
pydub srt mutagen \
30+
plotly altair bokeh \
31+
statsmodels scikit-learn scipy \
32+
wordcloud \
33+
nltk textblob gensim \
34+
fastapi uvicorn hypercorn \
35+
typer pygments platformdirs distro \
36+
pytest pytest-cov pytest-asyncio coverage hypothesis \
37+
ruff pylint pyflakes bandit vulture radon rope \
38+
websockets \
39+
fpdf2 reportlab \
40+
APScheduler celery \
41+
numpy-financial docx2txt pipdeptree watchdog rarfile \
42+
boto3 google-api-python-client slack-sdk praw tweepy \
43+
scrapy trafilatura builtwith edgartools exchange-calendars \
44+
paramiko fabric pexpect gitpython
1745
RUN set -eux; \
1846
find /deps -maxdepth 1 -type d -name '*.dist-info' -exec rm -rf {} + 2>/dev/null || true; \
1947
find /deps \( -type d -name tests -o -type d -name test \) -exec rm -rf {} + 2>/dev/null || true; \

examples/python-agent-driver/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export DOCKER_BUILDKIT := "0"
1414

1515
kernel := ".unikraft/build/python-agent-driver-hyperlight_hyperlight-x86_64"
1616
initrd := "python-agent-driver-initrd.cpio"
17-
memory := "1Gi"
17+
memory := "2560Mi"
1818
image := "python-agent-driver-hyperlight"
1919
script := "../python-agent/agent.py"
2020

examples/python-agent-driver/hl_pydriver.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ static void py_initialize_once(void)
252252
" 'numpy', 'pandas', 'pydantic', 'yaml', 'jinja2',"
253253
" 'bs4', 'tabulate', 'click', 'tenacity', 'tqdm',"
254254
" 'openpyxl', 'pypdf', 'markdown_it', 'PIL', 'lxml',"
255-
" 'cryptography', 'dateutil', 'dotenv'):\n"
255+
" 'cryptography', 'dateutil', 'dotenv',"
256+
" 'docx', 'pptx', 'chardet', 'charset_normalizer',"
257+
" 'requests', 'httpx'):\n"
256258
" try:\n"
257259
" importlib.import_module(_mod)\n"
258260
" except Exception as _e:\n"

host/src/bin/pydriver_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> Result<()> {
4444
let t_evolve = Instant::now();
4545
let mut sandbox = Sandbox::builder(&kernel)
4646
.initrd_file(&initrd)
47-
.heap_size(2 * 1024 * 1024 * 1024)
47+
.heap_size(5 * 512 * 1024 * 1024)
4848
.build()?;
4949
eprintln!(
5050
"[timing] evolve={:.1}ms",

host/src/bin/pyhl.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ const PREIMPORTED_MODULES: &[&str] = &[
8989
"cryptography",
9090
"dateutil",
9191
"dotenv",
92+
"docx",
93+
"pptx",
94+
"chardet",
95+
"charset_normalizer",
96+
"requests",
97+
"httpx",
9298
];
9399

94100
/// Build the long-about blurb shown by `pyhl --help`. Lists the
@@ -114,9 +120,22 @@ fn long_about() -> String {
114120
}
115121
s.push_str(
116122
"\n\n\
117-
Other third-party packages shipped in the rootfs still work — \
118-
they just pay the usual import cost on first access. Packages \
119-
not in the rootfs will raise ModuleNotFoundError.",
123+
Additional packages shipped in the rootfs (pay import cost on \
124+
first use): aiohttp, altair, APScheduler, bandit, bokeh, \
125+
boto3, builtwith, celery, coverage, distro, docx2txt, duckdb, \
126+
edgartools, exchange-calendars, fabric, Faker, fastapi, \
127+
feedparser, fpdf2, gensim, gitpython, \
128+
google-api-python-client, hypercorn, hypothesis, loguru, \
129+
markdown, markdownify, mutagen, networkx, nltk, \
130+
numpy-financial, odfpy, paramiko, pdfplumber, pdfrw, pexpect, \
131+
pipdeptree, platformdirs, plotly, polars, praw, pycountry, \
132+
pydub, pyflakes, pygments, pylint, PyPDF2, pytest, \
133+
pytest-asyncio, pytest-cov, pyxlsb, qrcode, radon, rapidfuzz, \
134+
rarfile, reportlab, rope, ruff, schedule, scikit-learn, scipy, \
135+
scrapy, send2trash, slack-sdk, srt, statsmodels, svgwrite, \
136+
sympy, textblob, trafilatura, tweepy, typer, uvicorn, vulture, \
137+
watchdog, websockets, wordcloud, xlrd, xlsxwriter.\n\n\
138+
Packages not in the rootfs will raise ModuleNotFoundError.",
120139
);
121140
s
122141
}
@@ -435,7 +454,7 @@ fn cmd_setup(args: SetupArgs) -> Result<()> {
435454
{
436455
let mut builder = Sandbox::builder(&dst_kernel)
437456
.initrd_file(&dst_initrd)
438-
.heap_size(3 * 512 * 1024 * 1024);
457+
.heap_size(5 * 512 * 1024 * 1024);
439458
for p in &setup_preopens {
440459
builder = builder.preopen(p.clone());
441460
}

host/src/pyhl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub fn install(opts: &InstallOptions<'_>) -> Result<InstallReport> {
197197
{
198198
let mut builder = Sandbox::builder(&dst_kernel)
199199
.initrd_file(&dst_initrd)
200-
.heap_size(3 * 512 * 1024 * 1024);
200+
.heap_size(5 * 512 * 1024 * 1024);
201201
for p in opts.mounts {
202202
builder = builder.preopen(p.clone());
203203
}

0 commit comments

Comments
 (0)