-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle UNC paths for windows (#16005)
- Loading branch information
Showing
3 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Test Windows UNC Paths | ||
|
||
on: | ||
workflow_dispatch: # Allow manual triggering | ||
pull_request: | ||
paths: | ||
- "src/prefect/utilities/filesystem.py" | ||
- "scripts/test_unc_paths.py" | ||
- ".github/workflows/test-windows-unc.yaml" | ||
- "requirements.txt" | ||
- "requirements-client.txt" | ||
|
||
jobs: | ||
test-unc-paths: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install -U pip | ||
pip install -e . | ||
- name: Create test UNC path and run flow | ||
shell: pwsh | ||
run: | | ||
# Create a test directory | ||
New-Item -ItemType Directory -Path "C:\ShareTest" -Force | ||
# Create network share | ||
New-SmbShare -Name "PrefectTest" -Path "C:\ShareTest" -FullAccess "Everyone" | ||
# Run the test script from the current directory | ||
# This will create and test flows in the UNC path | ||
python scripts/test_unc_paths.py | ||
env: | ||
PYTHONPATH: ${{ github.workspace }} | ||
|
||
- name: Cleanup | ||
if: always() | ||
shell: pwsh | ||
run: | | ||
Remove-SmbShare -Name "PrefectTest" -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
from prefect import flow | ||
from prefect.flows import Flow | ||
|
||
|
||
def setup_unc_share(base_path: Path) -> Path: | ||
""" | ||
Creates a test UNC path and returns it. | ||
Requires admin privileges on Windows. | ||
""" | ||
if os.name != "nt": | ||
print("This script only works on Windows") | ||
sys.exit(1) | ||
|
||
# Create a test directory structure in the share | ||
unc_path = Path(r"\\localhost\PrefectTest") | ||
|
||
# Create a src directory in the share for our test flow | ||
src_dir = unc_path / "src" | ||
src_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
return unc_path | ||
|
||
|
||
def create_test_flow_file(path: Path): | ||
"""Create a test flow file in the given path""" | ||
flow_code = """ | ||
from prefect import flow | ||
@flow | ||
def remote_test_flow(name: str = "remote"): | ||
print(f"Hello from {name} in remote flow!") | ||
return "Remote Success!" | ||
""" | ||
# Create the flow file in src/app.py | ||
flow_file = path / "src" / "app.py" | ||
flow_file.write_text(flow_code) | ||
return flow_file | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
# Setup UNC share | ||
unc_path = setup_unc_share(Path.cwd()) | ||
print(f"Created UNC path structure at: {unc_path}") | ||
|
||
# Create a test flow file in the share | ||
flow_file = create_test_flow_file(unc_path) | ||
print(f"Created test flow file at: {flow_file}") | ||
|
||
# Try to load and run flow from UNC path | ||
print("Attempting to load flow from UNC path...") | ||
remote_flow = flow.from_source( | ||
source=unc_path, entrypoint="src/app.py:remote_test_flow" | ||
) | ||
|
||
print("Testing if flow was loaded correctly...") | ||
assert isinstance(remote_flow, Flow), "Flow was not loaded correctly" | ||
print("Flow loaded successfully!") | ||
|
||
except Exception as e: | ||
print(f"Error: {type(e).__name__}: {e}") | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters