From 4a289a60e1bf59ae6af510d8e421081a2e520ca8 Mon Sep 17 00:00:00 2001 From: Lysandre Debut Date: Mon, 25 Apr 2022 17:47:10 -0400 Subject: [PATCH] Move from init --- src/huggingface_hub/utils/__init__.py | 45 +----------------- src/huggingface_hub/utils/_subprocess.py | 59 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 src/huggingface_hub/utils/_subprocess.py diff --git a/src/huggingface_hub/utils/__init__.py b/src/huggingface_hub/utils/__init__.py index 00c5bf8df1..108414a314 100644 --- a/src/huggingface_hub/utils/__init__.py +++ b/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. @@ -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 diff --git a/src/huggingface_hub/utils/_subprocess.py b/src/huggingface_hub/utils/_subprocess.py new file mode 100644 index 0000000000..00c5bf8df1 --- /dev/null +++ b/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 + )