Hi al, Im super new here. My team and I are workin...
# flyte-support
b
Hi al, Im super new here. My team and I are working in a larger mono repo and would like to reuse code from other local packages. What is the best way to do that? My repo is setup as a uv workspace and I have a view project related packages as well as some utility packages which I would like to reuse across project. Thanks for the help in advance!
f
multiple ways to do that, just import and run, use bazel rules, or use reference tasks and workflows
b
Thanks for the reply! Sorry but I dont get it. My repo looks like this.
Copy code
.
├── dist
├── main.py
├── projects
│  ├── flyte-examples
│  │  ├── README.md
│  │  ├── pyproject.toml
│  │  └── src
│  │      └── flyte_examples
│  │          ├── __init__.py
│  │          ├── workflows
│  │          │  └──hellow_world
│  │          └── py.typed
│  ├── flyte-helper
│  │  ├── README.md
│  │  ├── pyproject.toml
│  │  └── src
│  │      └── flyte_helper
│  │          ├── __init__.py
│  │          ├── utils.py
│  │          └── py.typed
 ...
├── pyproject.toml
├── .venv
└── uv.lock
with the hello_world.py
Copy code
from typing import Tuple

from flytekit import task, workflow

from flyte_helper.utils import f


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


@workflow
def hello_world_wf() -> Tuple[str, int]:
    res = say_hello()
    res2 = f(1)
    return res, res2


if __name__ == "__main__":
    print(f"Running hello_world_wf() {hello_world_wf()}")
and flyte_helper/utils.py
Copy code
import random


def f(_: int) -> int:
    x = random.random() * 2 - 1
    y = random.random() * 2 - 1
    return 1 if x**2 + y**2 <= 1 else 0
running this with
Copy code
pyflyte run --remote src/flyte_example/examle_workflows/hello_world.py hello_world_wf
will result in
Copy code
Traceback (most recent call last):
      File "/usr/local/lib/python3.10/site-packages/flytekit/bin/entrypoint.py", line 163, in _dispatch_execute
        task_def = load_task()
      File "/usr/local/lib/python3.10/site-packages/flytekit/bin/entrypoint.py", line 578, in load_task
        return resolver_obj.load_task(loader_args=resolver_args)
      File "/usr/local/lib/python3.10/site-packages/flytekit/core/utils.py", line 312, in wrapper
        return func(*args, **kwargs)
      File "/usr/local/lib/python3.10/site-packages/flytekit/core/python_auto_container.py", line 273, in load_task
        task_module = importlib.import_module(name=task_module)  # type: ignore
      File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/root/flyte_example/examle_workflows/hello_world.py", line 5, in <module>
        from flyte_helper.utils import f
    ModuleNotFoundError: No module named 'flyte_helper'

Message:

    ModuleNotFoundError: No module named 'flyte_helper'
Locally it works fine
Copy code
python src/flyte_example/examle_workflows/hello_world.py 
Running hello_world_wf() DefaultNamedTupleOutput(o0='Hello, World!', o1=1)
Copy code
pyflyte run src/flyte_example/examle_workflows/hello_world.py hello_world_wf                                     
Running Execution on local.
DefaultNamedTupleOutput(o0='Hello, World!', o1=1)
as f is not a workflow or task I think references wont help here or am I missing something? Thanks for the help!
would be super happy to buy everyone a coffee who can help here!
f
Hey @brainy-carpenter-31280 I will answer maybe once I get some time over the weekend
ohh you have 2 different pyproject.tomls
do you then create a library and install it?
if so, then you will have to install the library into the container, sadly
because flyte today needs
python
packages to load the task definitions at runtime
b
Yes, Im using uv to build the packages and add them as local deps in the projects toml. The image is build locally when submitting the task/ workflow. Couldn't we add logic to the image spec to install local dependencies in the container?