Skip to content

Commit

Permalink
Relace git command calls with uses of dulwich API
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Jun 6, 2024
1 parent aac66c7 commit b4f239d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
68 changes: 67 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ twine = "^4.0.2"
docutils = "0.20.1"
typing-extensions = "^4.11.0"
filelock = "^3.14.0"
dulwich = "^0.22.1"

[tool.poetry.group.docs]
optional = true
Expand Down
58 changes: 8 additions & 50 deletions test/gerberx3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from __future__ import annotations

import fnmatch
import platform
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import (
Expand All @@ -19,6 +17,8 @@
)

import pytest
from dulwich import porcelain
from dulwich.repo import Repo
from filelock import FileLock
from PIL import Image, ImageDraw

Expand Down Expand Up @@ -186,26 +186,6 @@ def parametrize(self) -> pytest.MarkDecorator:
)


if platform.system() == "Windows":
GIT_PATH = Path(
subprocess.run(
["where", "git"], # noqa: S607, S603
capture_output=True,
text=True,
check=False,
).stdout.strip()
)
else:
GIT_PATH = Path(
subprocess.run(
["which", "git"], # noqa: S607, S603
capture_output=True,
text=True,
check=False,
).stdout.strip()
)


class ReferenceAssetsManager:
def __init__(self, sha: str) -> None:
self.sha = sha
Expand All @@ -217,35 +197,13 @@ def _prepare_repository(self) -> None:
lock = FileLock(self.repository_directory.with_suffix(".lock"))
with lock:
if not self.repository_directory.exists():
subprocess.run(
[ # noqa: S603
GIT_PATH.as_posix(),
"clone",
"https://github.com/Argmaster/pygerber-reference-assets",
self.repository_directory.as_posix(),
],
check=True,
capture_output=True,
porcelain.clone(
"https://github.com/Argmaster/pygerber-reference-assets",
self.repository_directory.as_posix(),
)
subprocess.run(
[ # noqa: S603
GIT_PATH.as_posix(),
"fetch",
],
cwd=self.repository_directory.as_posix(),
check=True,
capture_output=True,
)
subprocess.run(
[ # noqa: S603
GIT_PATH.as_posix(),
"checkout",
self.sha,
],
cwd=self.repository_directory.as_posix(),
check=True,
capture_output=True,
)
repository = Repo(self.repository_directory.as_posix())
porcelain.fetch(repository, "origin")
porcelain.checkout_branch(repository, self.sha)

def get_asset_path(self, tag: str, relative_path: Path) -> Path:
return self.repository_directory / f".reference{tag}" / relative_path
Expand Down

0 comments on commit b4f239d

Please sign in to comment.