Skip to content

Commit

Permalink
xtest: use tmp_path_factory fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kokos committed Mar 9, 2023
1 parent b589d65 commit a3540e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/poetry/vcs/git/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import os
import subprocess

from pathlib import Path
from typing import TYPE_CHECKING

from dulwich.client import find_git_command


if TYPE_CHECKING:
from pathlib import Path
from typing import Any

# Windows API for path expansion doesn't like paths over 260 characters.
# This prefix tells windows to use the path as is.
# https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
WINDOWS_LONG_PATH_PREFIX = "\\\\?\\"


class SystemGit:
@classmethod
Expand All @@ -25,6 +30,9 @@ def checkout(cls, rev: str, target: Path | None = None) -> str:
args = []

if target:
target = (
WINDOWS_LONG_PATH_PREFIX / target
) # work with hitting the path length limit on Windows
args += [
"--git-dir",
(target / ".git").as_posix(),
Expand All @@ -42,6 +50,9 @@ def checkout(cls, rev: str, target: Path | None = None) -> str:
def run(*args: Any, **kwargs: Any) -> str:
folder = kwargs.pop("folder", None)
if folder:
folder = WINDOWS_LONG_PATH_PREFIX / Path(
folder
) # work with hitting the path length limit on Windows
args = (
"--git-dir",
(folder / ".git").as_posix(),
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_utils_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


if TYPE_CHECKING:
from _pytest.tmpdir import TempdirFactory
from _pytest.tmpdir import TempPathFactory
from dulwich.client import FetchPackResult
from dulwich.client import GitClient
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -79,9 +79,9 @@ def source_directory_name(source_url: str) -> str:


@pytest.fixture(scope="module")
def local_repo(tmpdir_factory: TempdirFactory, source_directory_name: str) -> Repo:
def local_repo(tmp_path_factory: TempPathFactory, source_directory_name: str) -> Repo:
with Repo.init(
tmpdir_factory.mktemp("src") / source_directory_name, mkdir=True
tmp_path_factory.mktemp("src") / source_directory_name, mkdir=True
) as repo:
yield repo

Expand Down

0 comments on commit a3540e4

Please sign in to comment.