Skip to content

Commit

Permalink
Replacing TemporaryDirectory with already implemented make_tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrey12cali committed Mar 20, 2024
1 parent da86676 commit 28ceb06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
16 changes: 6 additions & 10 deletions weasel/tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import time
from pathlib import Path
from tempfile import TemporaryDirectory

import pytest
import srsly
Expand Down Expand Up @@ -170,27 +168,25 @@ def test_local_remote_storage_pull_missing():


def test_project_git_dir_asset():
with TemporaryDirectory() as d:
p = Path(d)
with make_tempdir() as d:
# Use a very small repo.
git_checkout(
"https://github.com/explosion/os-signpost.git",
"os_signpost",
p / "signpost",
d / "signpost",
branch="v0.0.3",
)
assert os.path.isdir(p / "signpost")
assert os.path.isdir(d / "signpost")


@pytest.mark.issue(66)
def test_project_git_file_asset():
with TemporaryDirectory() as d:
p = Path(d)
with make_tempdir() as d:
# Use a very small repo.
git_checkout(
"https://github.com/explosion/os-signpost.git",
"README.md",
p / "readme.md",
d / "readme.md",
branch="v0.0.3",
)
assert os.path.isfile(p / "readme.md")
assert os.path.isfile(d / "readme.md")
10 changes: 4 additions & 6 deletions weasel/util/git.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Tuple

from wasabi import msg
Expand Down Expand Up @@ -34,14 +33,13 @@ def git_checkout(
f"temporarily. To only download the files needed, make sure "
f"you're using Git v2.22 or above."
)
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
cmd = f"git -C {tmp_path} clone {repo} . -b {branch}"
with make_tempdir() as tmp_dir:
cmd = f"git -C {tmp_dir} clone {repo} . -b {branch}"
run_command(cmd, capture=True)
# We need Path(name) to make sure we also support subdirectories
try:
source_path = tmp_path / Path(subpath)
if not is_subpath_of(tmp_path, source_path):
source_path = tmp_dir / Path(subpath)
if not is_subpath_of(tmp_dir, source_path):
err = f"'{subpath}' is a path outside of the cloned repository."
msg.fail(err, repo, exits=1)
if os.path.isdir(source_path):
Expand Down

0 comments on commit 28ceb06

Please sign in to comment.