Skip to content

Commit 7c3edfc

Browse files
committed
Init
Signed-off-by: Kevin Su <pingsutw@apache.org>
1 parent 665a4ef commit 7c3edfc

10 files changed

Lines changed: 201 additions & 1 deletion

File tree

.github/workflows/migration.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build
2+
3+
# Schedule runs to run twice a day
4+
5+
on:
6+
push:
7+
branches:
8+
- master
9+
- 'release-v**'
10+
pull_request:
11+
12+
env:
13+
FLYTE_SDK_LOGGING_LEVEL: 10 # debug
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
needs:
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os:
27+
- ubuntu-24.04-arm
28+
# - ubuntu-latest
29+
# - windows-latest
30+
# - macos-latest
31+
python-version:
32+
- "3.12"
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: "Clear action cache"
36+
uses: ./.github/actions/clear-action-cache
37+
- name: Set up Python ${{ matrix.python-version }}
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
- name: Install dependencies
42+
run: |
43+
pip install uv
44+
make setup-global-uv
45+
uv pip install --pre flyte
46+
uv pip freeze
47+
- name: Test migrations
48+
run: |
49+
python migrate_examples/hello.py
50+

.github/workflows/pythonbuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches:
88
- master
99
- 'release-v**'
10-
pull_request:
10+
# pull_request:
1111
schedule:
1212
- cron: "0 13 * * *" # This schedule runs at 1pm UTC every day
1313

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ coverage.xml
4040
# Version file is auto-generated by setuptools_scm
4141
flytekit/_version.py
4242
testing
43+
.flyte/

flytekit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
- BlobType
100100
101101
"""
102+
import flytekit.migrate # isort: skip
102103

103104
import os
104105
import sys

flytekit/migrate/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from flytekit.migrate import task, dynamic, workflow # noqa: F401
2+

flytekit/migrate/dynamic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Callable, Union
2+
3+
import flytekit
4+
5+
import flytekit.migrate
6+
from flyte._task import AsyncFunctionTaskTemplate, P, R
7+
8+
9+
def dynamic_shim(**kwargs) -> Union[AsyncFunctionTaskTemplate, Callable[P, R]]:
10+
return flytekit.migrate.task.task_shim(**kwargs)
11+
12+
13+
flytekit.dynamic = dynamic_shim

flytekit/migrate/task.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import datetime
2+
from typing import Callable, Dict, Iterable, List, Literal, Optional, Tuple, Union, TYPE_CHECKING
3+
4+
5+
import flyte
6+
from flyte import Image, Resources, TaskEnvironment
7+
from flyte._doc import Documentation
8+
from flyte._task import AsyncFunctionTaskTemplate, P, R
9+
10+
import flytekit
11+
12+
if TYPE_CHECKING:
13+
from flytekit import Cache, Resources, Secret, ImageSpec, Documentation, PodTemplate
14+
from flytekit.core.base_task import T, TaskResolverMixin
15+
from flytekit.core.python_function_task import PythonFunctionTask
16+
from flytekit.core.task import FuncOut
17+
from flytekit.deck import DeckField
18+
from flytekit.extras.accelerators import BaseAccelerator
19+
20+
21+
def task_shim(
22+
_task_function: Optional[Callable[P, "FuncOut"]] = None,
23+
task_config: Optional["T"] = None,
24+
cache: Union[bool, "Cache"] = False,
25+
retries: int = 0,
26+
interruptible: Optional[bool] = None,
27+
deprecated: str = "",
28+
timeout: Union[datetime.timedelta, int] = 0,
29+
container_image: Optional[Union[str, "ImageSpec"]] = None,
30+
environment: Optional[Dict[str, str]] = None,
31+
requests: Optional[Resources] = None,
32+
limits: Optional[Resources] = None,
33+
secret_requests: Optional[List["Secret"]] = None,
34+
docs: Optional["Documentation"] = None,
35+
disable_deck: Optional[bool] = None,
36+
enable_deck: Optional[bool] = None,
37+
pod_template: Optional["PodTemplate"] = None,
38+
pod_template_name: Optional[str] = None,
39+
accelerator: Optional["BaseAccelerator"] = None,
40+
pickle_untyped: bool = False,
41+
shared_memory: Optional[Union[Literal[True], str]] = None,
42+
resources: Optional[Resources] = None,
43+
labels: Optional[dict[str, str]] = None,
44+
annotations: Optional[dict[str, str]] = None,
45+
**kwargs,
46+
) -> Union[AsyncFunctionTaskTemplate, Callable[P, R]]:
47+
plugin_config = task_config
48+
pod_template = (
49+
flyte.PodTemplate(
50+
pod_spec=pod_template.pod_spec,
51+
primary_container_name=pod_template.primary_container_name,
52+
labels=pod_template.labels,
53+
annotations=pod_template.annotations,
54+
)
55+
if pod_template
56+
else None
57+
)
58+
59+
if isinstance(container_image, flytekit.ImageSpec):
60+
image = Image.from_debian_base()
61+
if container_image.apt_packages:
62+
image = image.with_apt_packages(*container_image.apt_packages)
63+
pip_packages = ["flytekit"]
64+
if container_image.packages:
65+
pip_packages.extend(container_image.packages)
66+
image = image.with_pip_packages(*pip_packages)
67+
elif isinstance(container_image, str):
68+
image = Image.from_base(container_image).with_pip_packages("flyte")
69+
else:
70+
image = Image.from_debian_base().with_pip_packages("flytekit")
71+
72+
docs = Documentation(description=docs.short_description) if docs else None
73+
74+
env = TaskEnvironment(
75+
name="flytekit",
76+
resources=Resources(cpu=0.8, memory="800Mi"),
77+
image=image,
78+
cache="enabled" if cache else "disable",
79+
plugin_config=plugin_config,
80+
)
81+
return env.task(retries=retries, pod_template=pod_template_name or pod_template, docs=docs)
82+
83+
84+
flytekit.task = task_shim

flytekit/migrate/workflow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import flytekit
2+
3+
from flyte import Image, Resources, TaskEnvironment
4+
5+
env = TaskEnvironment(
6+
name="flytekit",
7+
resources=Resources(cpu=0.8, memory="800Mi"),
8+
image=Image.from_debian_base().with_apt_packages("vim").with_pip_packages("flytekit", "pandas"),
9+
)
10+
11+
# TODO: Build subtask's image
12+
13+
flytekit.workflow = env.task

flytekit/remote/remote.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import functools
1313
import gzip
1414
import hashlib
15+
import logging
1516
import os
1617
import pathlib
1718
import tempfile
@@ -1932,6 +1933,12 @@ def execute(
19321933
)
19331934
raise NotImplementedError(f"entity type {type(entity)} not recognized for execution")
19341935

1936+
def execute_v2(self, entity, **kwargs):
1937+
import flyte
1938+
flyte.init_from_config()
1939+
run = flyte.with_runcontext(log_level=logging.DEBUG).run(entity, **kwargs)
1940+
print(run.url)
1941+
19351942
# Flyte Remote Entities
19361943
# ---------------------
19371944

migrate_exmaples/hello.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
3+
from flytekit import ImageSpec, dynamic, task, workflow
4+
5+
image = ImageSpec(apt_packages=["vim"], packages=["pandas"])
6+
7+
8+
@task(cache=True, cache_version="1.0", retries=3, container_image=image)
9+
def say_hello(name: str):
10+
print(f"Hello, {name}!")
11+
12+
13+
@dynamic(container_image=image)
14+
def dynamic_task(name: str):
15+
say_hello(name=name)
16+
17+
18+
@workflow
19+
def wf(name: str):
20+
say_hello(name=name)
21+
dynamic_task(name=name)
22+
23+
24+
if __name__ == "__main__":
25+
import flyte
26+
flyte.init_from_config(log_level=logging.DEBUG)
27+
# run = flyte.with_runcontext(log_level=logging.DEBUG).run(wf, name="flyte")
28+
# print(run.name)
29+
# print(run.url)

0 commit comments

Comments
 (0)