Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ A tutorial to introduce users to Flyte v2 features through examples

## Quick start

Prereqs: Python 3.10+.
**Prereqs**:
- Python 3.10+
- A configured Flyte cluster (see [Authentication](#authentication) below)
- OR use `--local` flag to run examples locally without a cluster

### Option A: uv (recommended)

Expand Down Expand Up @@ -32,7 +35,17 @@ Running examples:
- Use `flyte run ...` from your venv, or prefix with `uv run` if using uv.
- Ensure your Flyte CLI is configured for your project/domain. You can pass `-p <project> -d <domain>` to the command if needed.

**Note**: If you haven't configured Flyte (see [Authentication](#authentication) below), you can still test examples locally with:
```
flyte run --local <example> <task> [args...]
```

This runs without a remote cluster but won't demonstrate Flyte's distributed execution features.

## Authentication

**REQUIRED** to run examples with remote execution. Without this, you'll get "Failed to get signed url" errors.

Create a flyte config file with:
```
flyte create config \
Expand All @@ -46,6 +59,22 @@ flyte create config \

Update this command to use the orgName and projectName for your org and project.

**Don't have a cluster?** Use `--local` flag to test examples without authentication:
```
flyte run --local <example> <task> [args...]
```

## Python 3.14+ Compatibility

This repository is compatible with Python 3.14+ (tested on Fedora 43). The following fixes are automatically applied:

1. **Traversable Import**: Python 3.14 moved `Traversable` from `importlib.abc` to `collections.abc`. A compatibility patch (`_polyglot_patch.py`) is auto-loaded to handle this gracefully.

2. **Local Testing**: All examples can be tested locally without a Flyte cluster using the `--local` flag:
```bash
uv run flyte run --local <example> <task> [args...]
```

## Exercises

### 1) Hello Polyglot
Expand Down
143 changes: 143 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Fedora 43 + Python 3.14 Setup Guide

This document details the fixes applied to make the Flyte v2 tutorial work seamlessly on Fedora 43 with Python 3.14+.

## What Was Fixed

### 1. Python 3.14 Compatibility - Traversable Import Error

**Issue**: Python 3.14 moved `Traversable` from `importlib.abc` to `collections.abc`. The `polyglot-hello` package (v0.1.3) still uses the old import location, causing:
```
ImportError: cannot import name 'Traversable' from 'importlib.abc'
```

**Solution**: Created a compatibility patch that monkey-patches the import before polyglot-hello is loaded.

**Files**:
- `_polyglot_patch.py` - Patches `importlib.abc.Traversable` by importing from `collections.abc`
- `.venv/lib/python3.14/site-packages/_flyte_py314_compat.pth` - Auto-loads the patch on interpreter startup

**How it works**:
1. The `.pth` file tells Python to import `_polyglot_patch` at startup
2. `_polyglot_patch` checks if `Traversable` is missing from `importlib.abc`
3. If missing, it imports from `collections.abc` and injects it
4. All downstream imports of `Traversable` work transparently

### 2. Missing Dependencies for Report Examples

**Issue**: The `4_reports/` examples require `numpy`, `plotly`, and `requests`, which weren't listed in dependencies.

**Fix**: Added to `pyproject.toml`:
```toml
dependencies = [
"flyte>=2.0.0b14",
"polyglot-hello>=0.1.3",
"numpy",
"plotly",
"requests",
]
```

Then ran: `uv sync`

### 3. Local Testing Support

**Issue**: README didn't explain how to test without a Flyte cluster.

**Fix**: Updated README and all commands to use `--local` flag:
```bash
uv run flyte run --local <example> <task> [args...]
```

This runs tasks in the local Python environment without needing remote Flyte infrastructure.

## Quick Start

### Install Dependencies
```bash
uv sync
```

### Run Individual Examples
```bash
# Example 1: Hello Polyglot
uv run flyte run --local 1_hello_world/hello_polyglot.py main --letter e

# Example 2: Failure Handling
uv run flyte run --local 2_failure_handling/oomer.py failure_recovery

# Example 3: Agents
uv run flyte run --local 3_agents/smolagent.py main --goal "Make a peanut butter and jelly sandwich"

# Example 4: Reports
uv run flyte run --local 4_reports/run_all.py main
```

### Test All Examples
```bash
uv run python test_all_examples.py
```

This runs all 4 examples and provides a summary report.

## Environment Details

- **OS**: Fedora 43
- **Python**: 3.14.4
- **uv**: 0.10.12
- **Flyte**: 2.1.9

## Troubleshooting

### "No module named '_polyglot_patch'"
The patch wasn't copied to site-packages. Run:
```bash
cp _polyglot_patch.py .venv/lib/python3.14/site-packages/
```

### "cannot import name 'Traversable' from 'importlib.abc'"
The `.pth` file isn't being loaded. Check:
```bash
cat .venv/lib/python3.14/site-packages/_flyte_py314_compat.pth
```

Should contain: `import _polyglot_patch`

### "No module named 'numpy/plotly/requests'"
Re-run dependencies:
```bash
uv sync
```

## Fish Shell Compatibility

All commands work with fish shell. The main differences from bash:
- `&&` works the same
- Pipes `|` work the same
- String quoting with `"` works the same

No fish-specific syntax is required for these examples.

## Demo Readiness

Run before your demo:
```bash
uv run python test_all_examples.py
```

If all tests pass (4/4 ✅), you're ready to present!

## Files Changed/Created

**Modified**:
- `pyproject.toml` - Added numpy, plotly, requests
- `README.md` - Updated to use `--local` flag and added Python 3.14 docs

**Created**:
- `_polyglot_patch.py` - Python 3.14 compatibility patch
- `test_all_examples.py` - Validation script for all examples
- `SETUP.md` (this file)

**Auto-Generated**:
- `.venv/lib/python3.14/site-packages/_flyte_py314_compat.pth` - Auto-load mechanism
- `.venv/lib/python3.14/site-packages/_polyglot_patch.py` - Copied from root
20 changes: 20 additions & 0 deletions _polyglot_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Patch for polyglot-hello compatibility with Python 3.14+.
In Python 3.14, Traversable was moved from importlib.abc to collections.abc.
"""
import sys

def patch_traversable():
"""Patch importlib.abc to include Traversable for backward compatibility."""
if sys.version_info >= (3, 9):
import importlib.abc
if not hasattr(importlib.abc, 'Traversable'):
try:
from collections.abc import Traversable
importlib.abc.Traversable = Traversable
except ImportError:
# Fallback for even older versions
from importlib.resources.abc import Traversable
importlib.abc.Traversable = Traversable

patch_traversable()
14 changes: 14 additions & 0 deletions flyte_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
"""
Wrapper to run flyte examples with Python 3.14+ compatibility.
Applies the Traversable import patch before running examples.
"""
import sys
import _polyglot_patch # noqa: F401
import subprocess

# Re-run the original command without this wrapper
if __name__ == "__main__":
# Skip the first argument (the script name) and pass remaining args to flyte
exit_code = subprocess.run([sys.executable, "-m", "flyte.cli"] + sys.argv[1:]).returncode
sys.exit(exit_code)
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ requires-python = ">=3.10"
dependencies = [
"flyte>=2.0.0b14",
"polyglot-hello>=0.1.3",
"numpy",
"plotly",
"requests",
]

[tool.uv]
Expand Down
77 changes: 77 additions & 0 deletions test_all_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
"""
Test script to validate all Flyte v2 tutorial examples.
Runs on Fedora 43 with Python 3.14+ support.
"""
import subprocess
import sys
from pathlib import Path

# Auto-apply Python 3.14 compatibility patch
import _polyglot_patch # noqa: F401

def run_example(name: str, file: str, task: str, args: list = None) -> bool:
"""Run a single example and report results."""
args = args or []
cmd = ["uv", "run", "flyte", "run", "--local", file, task] + args

print(f"\n{'='*60}")
print(f"Testing: {name}")
print(f"Command: {' '.join(cmd)}")
print(f"{'='*60}")

try:
result = subprocess.run(cmd, capture_output=False, timeout=120)
success = result.returncode == 0
status = "✅ PASS" if success else "❌ FAIL"
print(f"\n{status}: {name}")
return success
except subprocess.TimeoutExpired:
print(f"\n⏱️ TIMEOUT: {name}")
return False
except Exception as e:
print(f"\n❌ ERROR: {name} - {e}")
return False


def main():
"""Run all tutorial examples."""
print("\n" + "🚀" * 30)
print("Flyte v2 Tutorial - All Examples Test")
print("🚀" * 30)

examples = [
("Hello Polyglot", "1_hello_world/hello_polyglot.py", "main", ["--letter", "e"]),
("Failure Handling", "2_failure_handling/oomer.py", "failure_recovery", []),
("Agents/Sandwich", "3_agents/smolagent.py", "main", ["--goal", "Make a peanut butter and jelly sandwich"]),
("Reports Bundle", "4_reports/run_all.py", "main", []),
]

results = {}
for name, file, task, args in examples:
results[name] = run_example(name, file, task, args)

# Summary
print(f"\n\n{'='*60}")
print("📊 TEST SUMMARY")
print(f"{'='*60}")

total = len(results)
passed = sum(1 for v in results.values() if v)

for name, success in results.items():
status = "✅" if success else "❌"
print(f"{status} {name}")

print(f"\nTotal: {passed}/{total} passed")

if passed == total:
print("\n🎉 All tests passed! Ready for demo.")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed.")
return 1


if __name__ == "__main__":
sys.exit(main())
Loading