From 110e5e474e88680562aac618931d013e2b640bbf Mon Sep 17 00:00:00 2001 From: Graham Hukill Date: Thu, 21 Aug 2025 10:27:13 -0400 Subject: [PATCH 1/2] Utilize uv script and tool building Why these changes are being introduced: Where formerly we were using a very low level, manual way of invoking the CLI with 'uv run python -m launcher.cli`, uv provides quite a bit of tooling around invoking a project. Because we invoke the CLI in multiple contexts -- local dev work, Docker container, standalone for running a notebook -- leaning into uv conventions can streamline a lot of that. How this addresses that need: Added a 'project.scripts' section with commands 'marimo-launcher' and 'mitlib-marimo-launcher' (more globally unique) that creates a console entry point for the CLI application. With this in place, we can now change how the CLI is invoked in all contexts: - local dev us 'uv run marimo-launcher' - Docker container installs this project like a library into the system wide python installation - can even support standalone installation and usage with 'uv tool install --from marimo-launcher' Side effects of this change: * No side effects, just easier invocation Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/IN-1434 --- Dockerfile | 39 +++++++++++---------------------------- Makefile | 9 ++++----- pyproject.toml | 12 ++++++++++-- uv.lock | 6 +++--- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index f69bcc8..87d5790 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,24 @@ -#======================================== -# builder layer -#======================================== -FROM python:3.13-slim AS builder - -# install uv and use system python -COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv -ENV UV_SYSTEM_PYTHON=1 - -COPY pyproject.toml pyproject.toml -COPY uv.lock uv.lock - -RUN uv export --no-dev --format requirements.txt -o /requirements.txt - -#======================================== -# final image -#======================================== FROM python:3.13-slim -# install git RUN apt-get update && \ - apt-get install -y --no-install-recommends git ca-certificates + apt-get install -y --no-install-recommends git ca-certificates && \ + rm -rf /var/lib/apt/lists/* -# install uv and use system python COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv ENV UV_SYSTEM_PYTHON=1 -# get pylock.toml from builder layer -COPY --from=builder /requirements.txt /requirements.txt +WORKDIR /app + +# Copy project metadata +COPY pyproject.toml uv.lock* ./ -# install dependencies to global python -RUN uv pip install -r /requirements.txt +# Copy CLI source +COPY launcher ./launcher -# copy application -WORKDIR /app -COPY ./launcher /app/launcher +# Install package into system python, includes "marimo-launcher" script +RUN uv pip install --system . EXPOSE 2718 -ENTRYPOINT ["python", "-m", "launcher.cli"] +ENTRYPOINT ["marimo-launcher"] CMD [] diff --git a/Makefile b/Makefile index 150463b..9b01d0d 100644 --- a/Makefile +++ b/Makefile @@ -75,18 +75,18 @@ ruff-apply: # Resolve 'fixable errors' with 'ruff' # CLI #################################### cli-test-inline-run: - uv run python -m launcher.cli \ + uv run marimo-launcher \ run \ --mount=tests/fixtures/inline_deps cli-test-reqs-txt-run: - uv run python -m launcher.cli \ + uv run marimo-launcher \ run \ --mount=tests/fixtures/static_deps_reqs_txt \ --requirements=requirements.txt cli-test-token-authenticated: - uv run python -m launcher.cli \ + uv run marimo-launcher \ run \ --mount=tests/fixtures/inline_deps \ --token="iamsecret" @@ -104,8 +104,7 @@ docker-test-run: # Test local docker container with test fixture notebook docker run \ -p "2718:2718" \ -v "$(CURDIR)/tests/fixtures:/tmp/fixtures" \ - -e NOTEBOOK_MOUNT="/tmp/fixtures" \ - -e NOTEBOOK_PATH="helloworld.py" \ + -e NOTEBOOK_MOUNT="/tmp/fixtures/inline_deps" \ marimo-launcher:latest \ run diff --git a/pyproject.toml b/pyproject.toml index 89321cc..83a01f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ [project] name = "marimo-launcher" -version = "1.0.0" +version = "1.1.0" requires-python = ">=3.13" dependencies = [ @@ -31,7 +31,7 @@ line-length = 90 [tool.mypy] disallow_untyped_calls = true disallow_untyped_defs = true -exclude = ["tests/"] +exclude = ["tests/","build/"] [tool.pytest.ini_options] log_level = "INFO" @@ -95,3 +95,11 @@ max-doc-length = 90 [tool.ruff.lint.pydocstyle] convention = "google" + +[project.scripts] +marimo-launcher = "launcher.cli:cli" +mitlib-marimo-launcher = "launcher.cli:cli" + +[build-system] +requires = ["setuptools>=61"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/uv.lock b/uv.lock index 67be7e7..e1ed41c 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 2 +revision = 3 requires-python = ">=3.13" [[package]] @@ -444,8 +444,8 @@ wheels = [ [[package]] name = "marimo-launcher" -version = "1.0.0" -source = { virtual = "." } +version = "1.1.0" +source = { editable = "." } dependencies = [ { name = "click" }, { name = "marimo" }, From 6c820f2c04420ecb316f807dd446e56e03df7d4f Mon Sep 17 00:00:00 2001 From: Graham Hukill Date: Thu, 21 Aug 2025 11:54:24 -0400 Subject: [PATCH 2/2] Add CLI command 'run' to Dockerfile entrypoint --- Dockerfile | 2 +- Makefile | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87d5790..dc28a47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,5 +20,5 @@ RUN uv pip install --system . EXPOSE 2718 -ENTRYPOINT ["marimo-launcher"] +ENTRYPOINT ["marimo-launcher", "run"] CMD [] diff --git a/Makefile b/Makefile index 9b01d0d..3ee4b1f 100644 --- a/Makefile +++ b/Makefile @@ -105,8 +105,7 @@ docker-test-run: # Test local docker container with test fixture notebook -p "2718:2718" \ -v "$(CURDIR)/tests/fixtures:/tmp/fixtures" \ -e NOTEBOOK_MOUNT="/tmp/fixtures/inline_deps" \ - marimo-launcher:latest \ - run + marimo-launcher:latest #################################### # Terraform