Skip to content
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"psutil",
"gpuhunt==0.1.6",
"argcomplete>=3.5.0",
"ignore-python>=0.2.0",
]

[project.urls]
Expand Down
32 changes: 19 additions & 13 deletions src/dstack/_internal/core/models/repos/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
from pathlib import Path
from typing import BinaryIO, Optional

import ignore
import ignore.overrides
from typing_extensions import Literal

from dstack._internal.core.models.repos.base import BaseRepoInfo, Repo
from dstack._internal.utils.common import sizeof_fmt
from dstack._internal.utils.hash import get_sha256, slugify
from dstack._internal.utils.ignore import GitIgnore
from dstack._internal.utils.logging import get_logger
from dstack._internal.utils.path import PathLike

logger = get_logger(__name__)


class LocalRepoInfo(BaseRepoInfo):
repo_type: Literal["local"] = "local"
Expand Down Expand Up @@ -69,22 +74,23 @@ def __init__(
self.run_repo_data = repo_data

def write_code_file(self, fp: BinaryIO) -> str:
repo_path = Path(self.run_repo_data.repo_dir)
with tarfile.TarFile(mode="w", fileobj=fp) as t:
t.add(
self.run_repo_data.repo_dir,
arcname="",
filter=TarIgnore(self.run_repo_data.repo_dir, globs=[".git"]),
)
for entry in (
ignore.WalkBuilder(repo_path)
.overrides(ignore.overrides.OverrideBuilder(repo_path).add("!/.git/").build())
.hidden(False) # do not ignore files that start with a dot
.require_git(False) # respect git ignore rules even if not a git repo
.add_custom_ignore_filename(".dstackignore")
.build()
):
path = entry.path().relative_to(repo_path.absolute())
if path != Path("."):
t.add(path, recursive=False)
logger.debug("Code file size: %s", sizeof_fmt(fp.tell()))
return get_sha256(fp)

def get_repo_info(self) -> LocalRepoInfo:
return LocalRepoInfo(
repo_dir=self.run_repo_data.repo_dir,
)


class TarIgnore(GitIgnore):
def __call__(self, tarinfo: tarfile.TarInfo) -> Optional[tarfile.TarInfo]:
if self.ignore(tarinfo.path):
return None
return tarinfo
92 changes: 0 additions & 92 deletions src/dstack/_internal/utils/ignore.py

This file was deleted.