Compare commits

..
Author SHA1 Message Date
Josh RogersandRobin e8e0c568ef fix(cli): avoid Hadolint warnings for local Python packages
Co-authored-by: Robin <open-swe@users.noreply.github.com>
2026-12-03 15:42:47 +00:00
3 changed files with 54 additions and 45 deletions

No files matched your search

+22 -16
View File
@@ -1237,19 +1237,15 @@ def _update_http_app_path(
def _build_python_install_commands(
config: Config, install_cmd: str
config: Config, install_cmd: str, *, editable_install_cmd: str | None = None
) -> tuple[str, str, str]:
base_install = f"PYTHONDONTWRITEBYTECODE=1 {install_cmd} --no-cache-dir -c /api/constraints.txt"
local_reqs_pip_install = base_install
global_reqs_pip_install = base_install
env = "PYTHONDONTWRITEBYTECODE=1"
if config.get("pip_config_file"):
local_reqs_pip_install = (
f"PIP_CONFIG_FILE=/pipconfig.txt {local_reqs_pip_install}"
)
global_reqs_pip_install = (
f"PIP_CONFIG_FILE=/pipconfig.txt {global_reqs_pip_install}"
)
env = f"PIP_CONFIG_FILE=/pipconfig.txt {env}"
options = "--no-cache-dir -c /api/constraints.txt"
local_reqs_pip_install = f"{env} {install_cmd} {options}"
global_reqs_pip_install = f"{env} {editable_install_cmd or install_cmd} {options}"
pip_config_file_str = (
f"ADD {config['pip_config_file']} /pipconfig.txt"
@@ -1426,11 +1422,19 @@ def python_config_to_docker(
else:
raise ValueError(f"Invalid pip_installer: {pip_installer}")
dep_vname = "$$dep" if escape_variables else "$dep"
use_uv = pip_installer == "uv"
(
local_reqs_pip_install,
global_reqs_pip_install,
pip_config_file_str,
) = _build_python_install_commands(config, install_cmd)
) = _build_python_install_commands(
config,
install_cmd,
editable_install_cmd=f'uv --directory "{dep_vname}" pip install --system'
if use_uv
else None,
)
# collect dependencies
pypi_deps = [dep for dep in config["dependencies"] if not dep.startswith(".")]
@@ -1476,7 +1480,7 @@ def python_config_to_docker(
COPY --from=outer-{fullpath.name} . {destpath}"""
if fullpath in local_deps.additional_contexts
else f"""# -- Adding non-package dependency {fullpath.name} --
ADD {relpath} {destpath}"""
COPY {relpath} {destpath}"""
)
+ f"""
RUN set -ex && \\
@@ -1501,7 +1505,7 @@ COPY --from={name} . /deps/{name}
# -- End of local package {relpath} --"""
if fullpath in local_deps.additional_contexts
else f"""# -- Adding local package {relpath} --
ADD {relpath} /deps/{name}
COPY {relpath} /deps/{name}
# -- End of local package {relpath} --"""
)
for fullpath, (relpath, name) in local_deps.real_pkgs.items()
@@ -1578,12 +1582,14 @@ ADD {relpath} /deps/{name}
)
# Add main dockerfile content
dep_vname = "$$dep" if escape_variables else "$dep"
editable_install = f"{global_reqs_pip_install} -e ."
if not use_uv:
editable_install = f'(cd "{dep_vname}" && {editable_install})'
local_deps_install_str = f"""RUN for dep in /deps/*; do \
echo "Installing {dep_vname}"; \
if [ -d "{dep_vname}" ]; then \
echo "Installing {dep_vname}"; \
(cd "{dep_vname}" && {global_reqs_pip_install} -e .); \
{editable_install}; \
fi; \
done"""
docker_file_contents.extend(
+2 -2
View File
@@ -136,13 +136,13 @@ services:
# syntax=docker/dockerfile:1.4
FROM langchain/langgraph-api:3.11
# -- Adding local package . --
ADD . /deps/cli
COPY . /deps/cli
# -- End of local package . --
# -- Adding local package ../../.. --
COPY --from=cli_1 . /deps/cli_1
# -- End of local package ../../.. --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}
+30 -27
View File
@@ -918,7 +918,7 @@ RUN PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/con
COPY --from=examples . /deps/examples
# -- End of local package ../../examples --
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -946,7 +946,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency graphs_reqs_a --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGGRAPH_HTTP='{{"app": "/deps/examples/my_app.py:app"}}'
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
@@ -975,7 +975,7 @@ def test_config_to_docker_outside_path():
# syntax=docker/dockerfile:1.4
FROM langchain/langgraph-api:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -1003,7 +1003,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}'
"""
@@ -1036,7 +1036,7 @@ def test_config_to_docker_pipconfig():
FROM langchain/langgraph-api:3.11
ADD pipconfig.txt /pipconfig.txt
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -1050,7 +1050,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}'
"""
@@ -1098,7 +1098,7 @@ def test_config_to_docker_local_deps():
expected_docker_stdin = f"""\
FROM langchain/langgraph-api-custom:3.11
# -- Adding non-package dependency graphs --
ADD ./graphs /deps/outer-graphs/src
COPY ./graphs /deps/outer-graphs/src
RUN set -ex && \\
for line in '[project]' \\
'name = "graphs"' \\
@@ -1112,7 +1112,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency graphs --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-graphs/src/agent.py:graph"}}'
{FORMATTED_CLEANUP_LINES}\
@@ -1145,10 +1145,10 @@ dependencies = ["langchain"]"""
expected_docker_stdin = (
"""FROM langchain/langgraph-api:3.11
# -- Adding local package . --
ADD . /deps/unit_tests
COPY . /deps/unit_tests
# -- End of local package . --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{"agent": "/deps/unit_tests/graphs/agent.py:graph"}'
"""
@@ -1182,7 +1182,7 @@ ARG foo
ADD pipconfig.txt /pipconfig.txt
RUN PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt langchain langchain_openai
# -- Adding non-package dependency graphs --
ADD ./graphs/ /deps/outer-graphs/src
COPY ./graphs/ /deps/outer-graphs/src
RUN set -ex && \\
for line in '[project]' \\
'name = "graphs"' \\
@@ -1196,7 +1196,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency graphs --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PIP_CONFIG_FILE=/pipconfig.txt PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-graphs/src/agent.py:graph"}}'
{FORMATTED_CLEANUP_LINES}"""
@@ -1526,7 +1526,7 @@ def test_config_to_docker_gen_ui_python():
expected_docker_stdin = f"""FROM langchain/langgraph-api:3.11
RUN /storage/install-node.sh
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -1540,7 +1540,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGGRAPH_UI='{{"agent": "./graphs/agent.ui.jsx"}}'
ENV LANGGRAPH_UI_CONFIG='{{"shared": ["nuqs"]}}'
@@ -1573,7 +1573,7 @@ def test_config_to_docker_multiplatform():
expected_docker_stdin = f"""FROM langchain/langgraph-api:3.11
RUN /storage/install-node.sh
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -1587,7 +1587,7 @@ RUN set -ex && \\
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; (cd "$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $dep"; if [ -d "$dep" ]; then echo "Installing $dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"python": "/deps/outer-unit_tests/unit_tests/multiplatform/python.py:graph", "js": "/deps/outer-unit_tests/unit_tests/multiplatform/js.mts:graph"}}'
# -- Installing JS dependencies --
@@ -1681,7 +1681,10 @@ def test_config_to_docker_pip_installer():
PATH_TO_CONFIG, config_pip, base_image="langchain/langgraph-api:0.2.47"
)
assert "uv pip install --system " not in docker_pip
assert "pip install" in docker_pip
assert (
'(cd "$dep" && PYTHONDONTWRITEBYTECODE=1 pip install '
"--no-cache-dir -c /api/constraints.txt -e .)" in docker_pip
)
assert "rm /usr/bin/uv" not in docker_pip
# Test explicit uv setting
@@ -2844,7 +2847,7 @@ def test_config_to_compose_simple_config():
dockerfile_inline: |
FROM langchain/langgraph-api:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -2858,7 +2861,7 @@ def test_config_to_compose_simple_config():
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}
@@ -2885,7 +2888,7 @@ def test_config_to_compose_env_vars():
dockerfile_inline: |
FROM langchain/langgraph-api-custom:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -2899,7 +2902,7 @@ def test_config_to_compose_env_vars():
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}
@@ -2930,7 +2933,7 @@ def test_config_to_compose_env_file():
dockerfile_inline: |
FROM langchain/langgraph-api:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -2944,7 +2947,7 @@ def test_config_to_compose_env_file():
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}
@@ -2968,7 +2971,7 @@ def test_config_to_compose_watch():
dockerfile_inline: |
FROM langchain/langgraph-api:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -2982,7 +2985,7 @@ def test_config_to_compose_watch():
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}
@@ -3015,7 +3018,7 @@ def test_config_to_compose_end_to_end():
dockerfile_inline: |
FROM langchain/langgraph-api:3.11
# -- Adding non-package dependency unit_tests --
ADD . /deps/outer-unit_tests/unit_tests
COPY . /deps/outer-unit_tests/unit_tests
RUN set -ex && \\
for line in '[project]' \\
'name = "unit_tests"' \\
@@ -3029,7 +3032,7 @@ def test_config_to_compose_end_to_end():
done
# -- End of non-package dependency unit_tests --
# -- Installing all local dependencies --
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; (cd "$$dep" && PYTHONDONTWRITEBYTECODE=1 uv pip install --system --no-cache-dir -c /api/constraints.txt -e .); fi; done
RUN for dep in /deps/*; do echo "Installing $$dep"; if [ -d "$$dep" ]; then echo "Installing $$dep"; PYTHONDONTWRITEBYTECODE=1 uv --directory "$$dep" pip install --system --no-cache-dir -c /api/constraints.txt -e .; fi; done
# -- End of local dependencies install --
ENV LANGSERVE_GRAPHS='{{"agent": "/deps/outer-unit_tests/unit_tests/agent.py:graph"}}'
{textwrap.indent(textwrap.dedent(FORMATTED_CLEANUP_LINES), " ")}