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

Fix extract_task_module #1829

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
6 changes: 3 additions & 3 deletions flytekit/core/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@
"""

if isinstance(f, TrackedInstance):
if f.instantiated_in:
if hasattr(f, "task_function"):
mod, mod_name, name = _task_module_from_callable(f.task_function)

Check warning on line 302 in flytekit/core/tracker.py

View check run for this annotation

Codecov / codecov/patch

flytekit/core/tracker.py#L302

Added line #L302 was not covered by tests
elif f.instantiated_in:
mod = importlib.import_module(f.instantiated_in)
mod_name = mod.__name__
name = f.lhs
elif hasattr(f, "task_function"):
mod, mod_name, name = _task_module_from_callable(f.task_function)
else:
mod, mod_name, name = _task_module_from_callable(f)

Expand Down
28 changes: 28 additions & 0 deletions tests/flytekit/unit/cli/pyflyte/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def my_workflow(x: int, y: int) -> int:
return sum(x=square(z=x), y=square(z=y))
"""

shell_task = """
from flytekit.extras.tasks.shell import ShellTask

t = ShellTask(
name="test",
script="echo 'Hello World'",
)
"""


@mock.patch("flytekit.clis.sdk_in_container.helpers.FlyteRemote")
def test_saving_remote(mock_remote):
Expand Down Expand Up @@ -69,6 +78,25 @@ def test_register_with_no_output_dir_passed(mock_client, mock_remote):
shutil.rmtree("core1")


@mock.patch("flytekit.clis.sdk_in_container.helpers.FlyteRemote", spec=FlyteRemote)
@mock.patch("flytekit.clients.friendly.SynchronousFlyteClient", spec=SynchronousFlyteClient)
def test_register_with_no_output_dir_passed(mock_client, mock_remote):
mock_remote._client = mock_client
mock_remote.return_value._version_from_hash.return_value = "dummy_version_from_hash"
mock_remote.return_value.fast_package.return_value = "dummy_md5_bytes", "dummy_native_url"
runner = CliRunner()
context_manager.FlyteEntities.entities.clear()
with runner.isolated_filesystem():
out = subprocess.run(["git", "init"], capture_output=True)
assert out.returncode == 0
os.makedirs("core2", exist_ok=True)
with open(os.path.join("core2", "shell_task.py"), "w") as f:
f.write(shell_task)
f.close()
result = runner.invoke(pyflyte.main, ["register", "core2"])
assert "Successfully registered 2 entities" in result.output
shutil.rmtree("core2")

@mock.patch("flytekit.clis.sdk_in_container.helpers.FlyteRemote", spec=FlyteRemote)
@mock.patch("flytekit.clients.friendly.SynchronousFlyteClient", spec=SynchronousFlyteClient)
def test_non_fast_register(mock_client, mock_remote):
Expand Down
Loading