Skip to content

Commit 108bd86

Browse files
committed
Switch to faster ignore library
1 parent f3cf818 commit 108bd86

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"psutil",
3535
"gpuhunt==0.1.6",
3636
"argcomplete>=3.5.0",
37-
"gitignore-parser>=0.1.12",
37+
"ignore-python>=0.2.0",
3838
]
3939

4040
[project.urls]

src/dstack/_internal/core/models/repos/local.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from pathlib import Path
33
from typing import BinaryIO, Optional
44

5+
from ignore import WalkBuilder
56
from typing_extensions import Literal
67

78
from dstack._internal.core.models.repos.base import BaseRepoInfo, Repo
89
from dstack._internal.utils.common import sizeof_fmt
910
from dstack._internal.utils.hash import get_sha256, slugify
10-
from dstack._internal.utils.ignore import GitIgnore
1111
from dstack._internal.utils.logging import get_logger
1212
from dstack._internal.utils.path import PathLike
1313

@@ -74,22 +74,18 @@ def __init__(
7474

7575
def write_code_file(self, fp: BinaryIO) -> str:
7676
with tarfile.TarFile(mode="w", fileobj=fp) as t:
77-
t.add(
78-
self.run_repo_data.repo_dir,
79-
arcname="",
80-
filter=TarIgnore(self.run_repo_data.repo_dir, globs=[".git"]),
81-
)
77+
for entry in (
78+
WalkBuilder(self.run_repo_data.repo_dir)
79+
.add_custom_ignore_filename(".dstackignore")
80+
.build()
81+
):
82+
path = entry.path()
83+
if path.is_file():
84+
t.add(path, arcname="")
8285
logger.debug(f"Code file size: {sizeof_fmt(fp.tell())}")
8386
return get_sha256(fp)
8487

8588
def get_repo_info(self) -> LocalRepoInfo:
8689
return LocalRepoInfo(
8790
repo_dir=self.run_repo_data.repo_dir,
8891
)
89-
90-
91-
class TarIgnore(GitIgnore):
92-
def __call__(self, tarinfo: tarfile.TarInfo) -> Optional[tarfile.TarInfo]:
93-
if self.ignore(tarinfo.path):
94-
return None
95-
return tarinfo

0 commit comments

Comments
 (0)