|
2 | 2 | from pathlib import Path |
3 | 3 | from typing import BinaryIO, Optional |
4 | 4 |
|
| 5 | +from ignore import WalkBuilder |
5 | 6 | from typing_extensions import Literal |
6 | 7 |
|
7 | 8 | from dstack._internal.core.models.repos.base import BaseRepoInfo, Repo |
8 | 9 | from dstack._internal.utils.common import sizeof_fmt |
9 | 10 | from dstack._internal.utils.hash import get_sha256, slugify |
10 | | -from dstack._internal.utils.ignore import GitIgnore |
11 | 11 | from dstack._internal.utils.logging import get_logger |
12 | 12 | from dstack._internal.utils.path import PathLike |
13 | 13 |
|
@@ -74,22 +74,18 @@ def __init__( |
74 | 74 |
|
75 | 75 | def write_code_file(self, fp: BinaryIO) -> str: |
76 | 76 | 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="") |
82 | 85 | logger.debug(f"Code file size: {sizeof_fmt(fp.tell())}") |
83 | 86 | return get_sha256(fp) |
84 | 87 |
|
85 | 88 | def get_repo_info(self) -> LocalRepoInfo: |
86 | 89 | return LocalRepoInfo( |
87 | 90 | repo_dir=self.run_repo_data.repo_dir, |
88 | 91 | ) |
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