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 issue with github storage running in non-empty directories #6693

Merged
merged 3 commits into from
Sep 6, 2022
Merged
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
10 changes: 6 additions & 4 deletions src/prefect/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,14 @@ async def get_directory(
if local_path is None:
local_path = Path(".").absolute()

if not from_path:
from_path = ""

# in this case, we clone to a temporary directory and move the subdirectory over
tmp_dir = None
if from_path:
tmp_dir = tempfile.TemporaryDirectory(suffix="prefect")
path_to_move = str(Path(tmp_dir.name).joinpath(from_path))
cmd += f" {tmp_dir.name} && cp -R {path_to_move}/."
tmp_dir = tempfile.TemporaryDirectory(suffix="prefect")
path_to_move = str(Path(tmp_dir.name).joinpath(from_path))
cmd += f" {tmp_dir.name} && cp -R {path_to_move}/."

cmd += f" {local_path}"

Expand Down
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ async def enter_client():
assert startup.call_count == shutdown.call_count
assert startup.call_count > 0

@pytest.mark.flaky(max_runs=3)
@pytest.mark.skipif(not_enough_open_files(), reason=not_enough_open_files.__doc__)
async def test_client_context_lifespan_is_robust_to_mixed_concurrency(self):
startup, shutdown = MagicMock(), MagicMock()
Expand Down
9 changes: 2 additions & 7 deletions tests/test_filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,22 @@ async def test_repository_default(self, monkeypatch):
class p:
returncode = 0

expected_path = Path(".").absolute()
mock = AsyncMock(return_value=p())
monkeypatch.setattr(prefect.filesystems, "run_process", mock)
g = GitHub(repository="prefect")
await g.get_directory()

assert mock.await_count == 1
assert mock.await_args[0][0] == f"git clone prefect {expected_path}"
assert f"git clone prefect" in mock.await_args[0][0]

async def test_reference_default(self, monkeypatch):
class p:
returncode = 0

expected_path = Path(".").absolute()
mock = AsyncMock(return_value=p())
monkeypatch.setattr(prefect.filesystems, "run_process", mock)
g = GitHub(repository="prefect", reference="2.0.0")
await g.get_directory()

assert mock.await_count == 1
assert (
mock.await_args[0][0]
== f"git clone prefect -b 2.0.0 --depth 1 {expected_path}"
)
assert f"git clone prefect -b 2.0.0 --depth 1" in mock.await_args[0][0]