Skip to content

Commit

Permalink
Last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LysandreJik committed Apr 18, 2022
1 parent 3b52996 commit 7fe58a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/huggingface_hub/repository.py
Expand Up @@ -220,7 +220,7 @@ def files_to_be_staged(pattern: str, folder: Union[str, Path]) -> List[str]:
`List[str]`: List of files that are to be staged.
"""
try:
p = run_subprocess(f"git ls-files -mo {pattern}".split(), folder)
p = run_subprocess("git ls-files -mo".split() + [pattern], folder)
if len(p.stdout.strip()):
files = p.stdout.strip().split("\n")
else:
Expand Down Expand Up @@ -641,6 +641,7 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non
run_subprocess(
f"{'git clone' if self.skip_lfs_files else 'git lfs clone'} {repo_url} .".split(),
self.local_dir,
env=env,
)
else:
# Check if the folder is the root of a git repository
Expand Down
12 changes: 9 additions & 3 deletions src/huggingface_hub/utils/__init__.py
Expand Up @@ -15,27 +15,32 @@
# limitations under the License

import subprocess
from typing import List

from .logging import get_logger


logger = get_logger(__name__)


def run_subprocess(command, folder, check=True) -> subprocess.CompletedProcess:
def run_subprocess(
command: List[str], folder: str, check=True, **kwargs
) -> subprocess.CompletedProcess:
"""
Method to run subprocesses. Calling this will capture the `stderr` and `stdout`,
please call `subprocess.run` manually in case you would like for them not to
be captured.
Args:
command (`str`):
The command to execute
command (`List[str]`):
The command to execute as a list of strings.
folder (`str`):
The folder in which to run the command.
check (`bool`, *optional*, defaults to `True`):
Setting `check` to `True` will raise a `subprocess.CalledProcessError`
when the subprocess has a non-zero exit code.
kwargs (`Dict[str]`):
Keyword arguments to be passed to the `subprocess.run` underlying command.
Returns:
`subprocess.CompletedProcess`: The completed process.
Expand All @@ -50,4 +55,5 @@ def run_subprocess(command, folder, check=True) -> subprocess.CompletedProcess:
check=check,
encoding="utf-8",
cwd=folder,
**kwargs
)

0 comments on commit 7fe58a8

Please sign in to comment.