Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure a space is added if both args are set in ImageSpec #2806

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions flytekit/image_spec/default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,21 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
requirements_uv_path = tmp_dir / "requirements_uv.txt"
requirements_uv_path.write_text("\n".join(requirements))

pip_extra_args = ""
pip_extra_args = []

if image_spec.pip_index:
pip_extra_args += f"--index-url {image_spec.pip_index}"
pip_extra_args.append(f"--index-url {image_spec.pip_index}")
if image_spec.pip_extra_index_url:
extra_urls = [f"--extra-index-url {url}" for url in image_spec.pip_extra_index_url]
pip_extra_args += " ".join(extra_urls)
pip_extra_args.extend(extra_urls)

pip_extra_args = " ".join(pip_extra_args)

uv_python_install_command = UV_PYTHON_INSTALL_COMMAND_TEMPLATE.substitute(PIP_EXTRA=pip_extra_args)

# Normalize whitespace to remove any extra spaces
uv_python_install_command = " ".join(uv_python_install_command.split())
blaketastic2 marked this conversation as resolved.
Show resolved Hide resolved

env_dict = {"PYTHONPATH": "/root", _F_IMG_ID: image_spec.id}

if image_spec.env:
Expand Down
2 changes: 2 additions & 0 deletions tests/flytekit/unit/core/image_spec/test_default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_create_docker_context(tmp_path):
source_root=os.fspath(source_root),
commands=["mkdir my_dir"],
entrypoint=["/bin/bash"],
pip_index="https://url.com",
pip_extra_index_url=["https://extra-url.com"],
source_copy_mode=CopyFileDetection.ALL,
copy=[tmp_file.relative_to(Path.cwd()).as_posix()],
Expand All @@ -52,6 +53,7 @@ def test_create_docker_context(tmp_path):
assert "scipy==1.13.0 numpy" in dockerfile_content
assert "python=3.12" in dockerfile_content
assert "--requirement requirements_uv.txt" in dockerfile_content
assert "--index-url" in dockerfile_content
assert "--extra-index-url" in dockerfile_content
assert "COPY --chown=flytekit ./src /root" in dockerfile_content
assert "RUN mkdir my_dir" in dockerfile_content
Expand Down