Skip to content

Commit

Permalink
FIX style issues by pinning black version
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Jul 21, 2023
1 parent 4f1e4bb commit c632723
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 90 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_version() -> str:
]

extras["quality"] = [
"black~=23.1",
"black==23.7",
"ruff>=0.0.241",
"mypy==0.982",
]
Expand Down
12 changes: 4 additions & 8 deletions src/huggingface_hub/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,8 @@ def cached_download(
"""
if not legacy_cache_layout:
warnings.warn(
(
"'cached_download' is the legacy way to download files from the HF hub, please consider upgrading to"
" 'hf_hub_download'"
),
"'cached_download' is the legacy way to download files from the HF hub, please consider upgrading to"
" 'hf_hub_download'",
FutureWarning,
)

Expand Down Expand Up @@ -1102,10 +1100,8 @@ def hf_hub_download(
"""
if force_filename is not None:
warnings.warn(
(
"The `force_filename` parameter is deprecated as a new caching system, "
"which keeps the filenames as they are on the Hub, is now in place."
),
"The `force_filename` parameter is deprecated as a new caching system, "
"which keeps the filenames as they are on the Hub, is now in place.",
FutureWarning,
)
legacy_cache_layout = True
Expand Down
16 changes: 6 additions & 10 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4780,11 +4780,9 @@ def request_space_hardware(
"""
if sleep_time is not None and hardware == SpaceHardware.CPU_BASIC:
warnings.warn(
(
"If your Space runs on the default 'cpu-basic' hardware, it will go to sleep if inactive for more"
" than 48 hours. This value is not configurable. If you don't want your Space to deactivate or if"
" you want to set a custom sleep time, you need to upgrade to a paid Hardware."
),
"If your Space runs on the default 'cpu-basic' hardware, it will go to sleep if inactive for more"
" than 48 hours. This value is not configurable. If you don't want your Space to deactivate or if"
" you want to set a custom sleep time, you need to upgrade to a paid Hardware.",
UserWarning,
)
payload: Dict[str, Any] = {"flavor": hardware}
Expand Down Expand Up @@ -4837,11 +4835,9 @@ def set_space_sleep_time(self, repo_id: str, sleep_time: int, *, token: Optional
hardware = runtime.requested_hardware or runtime.hardware
if hardware == SpaceHardware.CPU_BASIC:
warnings.warn(
(
"If your Space runs on the default 'cpu-basic' hardware, it will go to sleep if inactive for more"
" than 48 hours. This value is not configurable. If you don't want your Space to deactivate or if"
" you want to set a custom sleep time, you need to upgrade to a paid Hardware."
),
"If your Space runs on the default 'cpu-basic' hardware, it will go to sleep if inactive for more"
" than 48 hours. This value is not configurable. If you don't want your Space to deactivate or if"
" you want to set a custom sleep time, you need to upgrade to a paid Hardware.",
UserWarning,
)
return runtime
Expand Down
12 changes: 4 additions & 8 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,18 +1068,14 @@ def text_generation(
del payload["parameters"][key]
if len(ignored_parameters) > 0:
warnings.warn(
(
"API endpoint/model for text-generation is not served via TGI. Ignoring parameters"
f" {ignored_parameters}."
),
"API endpoint/model for text-generation is not served via TGI. Ignoring parameters"
f" {ignored_parameters}.",
UserWarning,
)
if details:
warnings.warn(
(
"API endpoint/model for text-generation is not served via TGI. Parameter `details=True` will"
" be ignored meaning only the generated text will be returned."
),
"API endpoint/model for text-generation is not served via TGI. Parameter `details=True` will"
" be ignored meaning only the generated text will be returned.",
UserWarning,
)
details = False
Expand Down
12 changes: 4 additions & 8 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,18 +1076,14 @@ async def text_generation(
del payload["parameters"][key]
if len(ignored_parameters) > 0:
warnings.warn(
(
"API endpoint/model for text-generation is not served via TGI. Ignoring parameters"
f" {ignored_parameters}."
),
"API endpoint/model for text-generation is not served via TGI. Ignoring parameters"
f" {ignored_parameters}.",
UserWarning,
)
if details:
warnings.warn(
(
"API endpoint/model for text-generation is not served via TGI. Parameter `details=True` will"
" be ignored meaning only the generated text will be returned."
),
"API endpoint/model for text-generation is not served via TGI. Parameter `details=True` will"
" be ignored meaning only the generated text will be returned.",
UserWarning,
)
details = False
Expand Down
6 changes: 2 additions & 4 deletions src/huggingface_hub/utils/_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,8 @@ def scan_cache_dir(cache_dir: Optional[Union[str, Path]] = None) -> HFCacheInfo:
cache_dir = Path(cache_dir).expanduser().resolve()
if not cache_dir.exists():
raise CacheNotFound(
(
f"Cache directory not found: {cache_dir}. Please use `cache_dir`"
" argument or set `HUGGINGFACE_HUB_CACHE` environment variable."
),
f"Cache directory not found: {cache_dir}. Please use `cache_dir`"
" argument or set `HUGGINGFACE_HUB_CACHE` environment variable.",
cache_dir=cache_dir,
)

Expand Down
8 changes: 3 additions & 5 deletions src/huggingface_hub/utils/_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ def inner_f(*args, **kwargs):
]
args_msg = ", ".join(args_msg)
warnings.warn(
(
f"Deprecated positional argument(s) used in '{f.__name__}': pass"
f" {args_msg} as keyword args. From version {version} passing these"
" as positional arguments will result in an error,"
),
f"Deprecated positional argument(s) used in '{f.__name__}': pass"
f" {args_msg} as keyword args. From version {version} passing these"
" as positional arguments will result in an error,",
FutureWarning,
)
kwargs.update(zip(sig.parameters, args))
Expand Down
8 changes: 3 additions & 5 deletions src/huggingface_hub/utils/_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ def experimental(fn: Callable) -> Callable:
def _inner_fn(*args, **kwargs):
if not constants.HF_HUB_DISABLE_EXPERIMENTAL_WARNING:
warnings.warn(
(
f"'{name}' is experimental and might be subject to breaking changes in the future."
" You can disable this warning by setting `HF_HUB_DISABLE_EXPERIMENTAL_WARNING=1` as environment"
" variable."
),
f"'{name}' is experimental and might be subject to breaking changes in the future."
" You can disable this warning by setting `HF_HUB_DISABLE_EXPERIMENTAL_WARNING=1` as environment"
" variable.",
UserWarning,
)
return fn(*args, **kwargs)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2750,10 +2750,8 @@ def test_repo_url_class(self):
# __repr__ is modified for debugging purposes
self.assertEqual(
repr(url),
(
"RepoUrl('https://huggingface.co/gpt2',"
" endpoint='https://huggingface.co', repo_type='model', repo_id='gpt2')"
),
"RepoUrl('https://huggingface.co/gpt2',"
" endpoint='https://huggingface.co', repo_type='model', repo_id='gpt2')",
)

def test_repo_url_endpoint(self):
Expand Down
8 changes: 3 additions & 5 deletions tests/test_inference_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ def test_summarization(self) -> None:
)
self.assertEqual(
summary,
(
"The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building. Its base is"
" square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower"
" surpassed the Washington Monument to become the tallest man-made structure in the world."
),
"The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building. Its base is"
" square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower"
" surpassed the Washington Monument to become the tallest man-made structure in the world.",
)

def test_text_generation(self) -> None:
Expand Down
12 changes: 5 additions & 7 deletions tests/test_utils_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ def test_tabulate_utility(self) -> None:
headers = ["Header 1", "something else", "a third column"]
self.assertEqual(
tabulate(rows=rows, headers=headers),
(
"Header 1 something else a third column \n"
"----------------- -------------- -------------- \n"
" 1 2 3 \n"
"a very long value foo bar \n"
" 123 456 "
),
"Header 1 something else a third column \n"
"----------------- -------------- -------------- \n"
" 1 2 3 \n"
"a very long value foo bar \n"
" 123 456 ",
)

def test_tabulate_utility_with_too_short_row(self) -> None:
Expand Down
30 changes: 11 additions & 19 deletions tests/test_utils_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ def dummy_deprecated_default_message(a: str = "a") -> None:
self.assertEqual(len(record), 1)
self.assertEqual(
record[0].message.args[0],
(
"Deprecated argument(s) used in 'dummy_deprecated_default_message': a."
" Will not be supported from version 'xxx'."
),
"Deprecated argument(s) used in 'dummy_deprecated_default_message': a."
" Will not be supported from version 'xxx'.",
)

def test_deprecate_arguments_with_custom_warning_message(self) -> None:
Expand All @@ -110,11 +108,9 @@ def dummy_deprecated_custom_message(a: str = "a") -> None:
self.assertEqual(len(record), 1)
self.assertEqual(
record[0].message.args[0],
(
"Deprecated argument(s) used in 'dummy_deprecated_custom_message': a."
" Will not be supported from version 'xxx'.\n\nThis is a custom"
" message."
),
"Deprecated argument(s) used in 'dummy_deprecated_custom_message': a."
" Will not be supported from version 'xxx'.\n\nThis is a custom"
" message.",
)

def test_deprecated_method(self) -> None:
Expand All @@ -130,10 +126,8 @@ def dummy_deprecated() -> None:
self.assertEqual(len(record), 1)
self.assertEqual(
record[0].message.args[0],
(
"'dummy_deprecated' (from 'tests.test_utils_deprecation') is deprecated"
" and will be removed from version 'xxx'. This is a custom message."
),
"'dummy_deprecated' (from 'tests.test_utils_deprecation') is deprecated"
" and will be removed from version 'xxx'. This is a custom message.",
)

def test_deprecate_list_output(self) -> None:
Expand All @@ -155,12 +149,10 @@ def dummy_deprecated() -> None:
# (check real message once)
self.assertEqual(
record[0].message.args[0],
(
"'dummy_deprecated' currently returns a list of objects but is planned to be a generator starting from"
" version xxx in order to implement pagination. Please avoid to use"
" `dummy_deprecated(...).__getitem__` or explicitly convert the output to a list first with `[item for"
" item in dummy_deprecated(...)]`."
),
"'dummy_deprecated' currently returns a list of objects but is planned to be a generator starting from"
" version xxx in order to implement pagination. Please avoid to use"
" `dummy_deprecated(...).__getitem__` or explicitly convert the output to a list first with `[item for"
" item in dummy_deprecated(...)]`.",
)

# __setitem__
Expand Down
10 changes: 4 additions & 6 deletions tests/test_utils_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ def test_default_user_agent(
mock_is_torch_available.return_value = True
self.assertEqual(
self._get_user_agent(),
(
f"unknown/None; hf_hub/{get_hf_hub_version()};"
f" python/{get_python_version()}; torch/torch_version;"
" tensorflow/tf_version; fastai/fastai_version;"
" fastcore/fastcore_version"
),
f"unknown/None; hf_hub/{get_hf_hub_version()};"
f" python/{get_python_version()}; torch/torch_version;"
" tensorflow/tf_version; fastai/fastai_version;"
" fastcore/fastcore_version",
)

@patch("huggingface_hub.utils._headers.is_torch_available")
Expand Down

0 comments on commit c632723

Please sign in to comment.