Skip to content

Commit

Permalink
Move from init
Browse files Browse the repository at this point in the history
  • Loading branch information
LysandreJik committed Apr 25, 2022
1 parent 99dbcb8 commit 4a289a6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 43 deletions.
45 changes: 2 additions & 43 deletions src/huggingface_hub/utils/__init__.py
@@ -1,3 +1,4 @@
# flake8: noqa
#!/usr/bin/env python
# coding=utf-8
# Copyright 2021 The HuggingFace Inc. team. All rights reserved.
Expand All @@ -14,46 +15,4 @@
# See the License for the specific language governing permissions and
# limitations under the License

import subprocess
from typing import List

from .logging import get_logger


logger = get_logger(__name__)


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 (`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.
"""
if isinstance(command, str):
raise ValueError("`run_subprocess` should be called with a list of strings.")

return subprocess.run(
command,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
check=check,
encoding="utf-8",
cwd=folder,
**kwargs
)
from ._subprocess import run_subprocess
59 changes: 59 additions & 0 deletions src/huggingface_hub/utils/_subprocess.py
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# coding=utf-8
# Copyright 2021 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

import subprocess
from typing import List

from .logging import get_logger


logger = get_logger(__name__)


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 (`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.
"""
if isinstance(command, str):
raise ValueError("`run_subprocess` should be called with a list of strings.")

return subprocess.run(
command,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
check=check,
encoding="utf-8",
cwd=folder,
**kwargs
)

0 comments on commit 4a289a6

Please sign in to comment.