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

Add . to the PYTHONPATH in ImageSpec #2447

Merged
merged 6 commits into from
Jun 3, 2024
Merged

Add . to the PYTHONPATH in ImageSpec #2447

merged 6 commits into from
Jun 3, 2024

Conversation

pingsutw
Copy link
Member

@pingsutw pingsutw commented May 28, 2024

Tracking issue

https://flyte-org.slack.com/archives/CP2HDHKE1/p1716911881652929

Why are the changes needed?

Module not found while running on a remote cluster since Python can not find the local module unless you explicitly add the local directory to the PYTHONPATH

Note: when you are using non-default base_image, the WORKDIR might be others (/ or /home, etc).

What changes were proposed in this pull request?

Add . to PYTHONPATH

How was this patch tested?

from flytekit import task, workflow, ImageSpec

new_flytekit = "git+https://github.com/flyteorg/flytekit@554dd6dd4882d703839dc4b846285b7b2f9f66dc"

image_spec = ImageSpec(
    name="helloworld",
    base_image="python:3.11.5-slim-bullseye",
    packages=[new_flytekit, "mypy"],
    apt_packages=["git"],
    registry="localhost:30000",
)


@task(container_image=image_spec)
def say_hello() -> str:
    return "Hello, World!"


@workflow
def wf() -> str:
    res = say_hello()
    return res


if __name__ == "__main__":
    print(f"Running hello_world_wf() {wf()}")

Setup process

Screenshots

Screenshot 2024-05-28 at 12 40 22 PM

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

NA

Docs link

NA

pingsutw added 4 commits May 28, 2024 11:12
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For custom base images, should ImageSpec change the WORKDIR to /root?

@@ -91,7 +91,7 @@ def create_envd_config(image_spec: ImageSpec) -> str:
run_commands = _create_str_from_package_list(image_spec.commands)
conda_channels = _create_str_from_package_list(image_spec.conda_channels)
apt_packages = _create_str_from_package_list(image_spec.apt_packages)
env = {"PYTHONPATH": "/root", _F_IMG_ID: image_spec.image_name()}
env = {"PYTHONPATH": "/root:.", _F_IMG_ID: image_spec.image_name()}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "." is easy to miss. I think using PWD works too?

Suggested change
env = {"PYTHONPATH": "/root:.", _F_IMG_ID: image_spec.image_name()}
env = {"PYTHONPATH": "/root:$PWD", _F_IMG_ID: image_spec.image_name()}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need . you just need the :

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work? I was under the impression that the current working directory was already part of sys.path when the python interpreter starts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For custom base images, should ImageSpec change the WORKDIR to /root?

we don't need to. It should use the workdir in the base image.

pingsutw added 2 commits May 28, 2024 14:05
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
@eapolinario
Copy link
Collaborator

Can we add a description of the problem to this PR? I'd love to understand why this fixes the problem.

@pingsutw pingsutw merged commit e2847f0 into master Jun 3, 2024
43 of 46 checks passed
fiedlerNr9 pushed a commit that referenced this pull request Jul 25, 2024
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants