Shaoyi Zhang
04/25/2024, 6:47 PMMarvin
04/25/2024, 6:48 PM__init__.py
files) so that Python can recognize and handle relative imports correctly.
2. Mounting: When running flows in Kubernetes, if your source code is stored in S3, you'll need a way to make that code available to the execution environment. This could involve downloading the code at the start of the run or using a tool to mount the S3 bucket as a volume in the Kubernetes pod.
3. Flow Design: Flows should be defined in a way that supports dynamic loading of modules when the flow starts. This might require ensuring that all import statements are compatible with the way your packages are stored and accessed on S3.
4. Version Controlled Storage: Use Prefect's storage options that support version control and package management. This ensures that your flows can pull the correct version of the code with all dependencies correctly resolved.
The Prefect documentation does not directly address the specific scenario of handling relative imports with S3 and Kubernetes. However, running flows with Kubernetes and using Prefect integrations with AWS services like S3 can be referenced to guide you through setting up your flows in Kubernetes and interfacing with S3.
If you encounter any issues or specific error messages, you can search for GitHub issues or raise new ones in Prefect's repositories to receive community support.Nate
04/25/2024, 6:50 PM.relative_import
or just local helpers? for the latter, here's an example
https://github.com/zzstoatzz/prefect-monorepo/blob/main/src/demo_project/uses_local_helpers.pyShaoyi Zhang
04/25/2024, 7:29 PM/python-flows
folder. The current working directory for the running flow is /
, and the flow file itself is located at /python-flows/Sandbox/example_flow_v2.py
while the helpers are located in /python-flows/Sandbox/helpers.py
.
I’ve tried these two approaches
Traceback (most recent call last):
File "/python-flows/Sandbox/example_flow_v2.py", line 62, in duck
from helper import plus_one
ModuleNotFoundError: No module named 'helper'
and
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/engine.py", line 2099, in orchestrate_task_run
result = await call.aresult()
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 293, in aresult
return await asyncio.wrap_future(self.future)
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 318, in _run_sync
result = self.fn(*self.args, **self.kwargs)
File "/python-flows/Sandbox/example_flow_v2.py", line 67, in duck
from .helper import plus_one
ModuleNotFoundError: No module named '__prefect_loader__'
Shaoyi Zhang
04/25/2024, 7:30 PMNate
04/25/2024, 8:02 PMpyproject.toml
in your dockerfile and then just clone your flow code that uses itNate
04/25/2024, 8:02 PMMarvin
04/25/2024, 8:02 PMShaoyi Zhang
04/25/2024, 9:00 PMNate
04/25/2024, 9:05 PMfrom_source
https://github.com/zzstoatzz/prefect-monorepo/blob/main/src/demo_project/uses_local_helpers.py#L10-L17
which is not possible with agentsNate
04/25/2024, 9:06 PMConverting utils code into a package was what we did with Prefect 1, but I’m curious if there’s a more natural waybuilding a package is what I find most natural for reusing python modules, but thats just my preference