Skip to content

Commit

Permalink
some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Feb 24, 2023
1 parent 32c438f commit a7f7702
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 63 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dmypy.json
.DS_Store

# Ruff
.ruff_cache
.ruff_cache

# Spell checker config
cspell.json
2 changes: 1 addition & 1 deletion docs/source/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- local: guides/inference
title: Inference
- local: guides/community
title: Community
title: Community Tab
- local: guides/manage-cache
title: Cache
- local: guides/model-cards
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def last_edited_at(self) -> datetime:

@property
def last_edited_by(self) -> str:
"""The last edit tiem, as a `datetime` object."""
"""The last edit time, as a `datetime` object."""
return self._event["data"]["latest"].get("author", {}).get("name", "deleted")

@property
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class DatasetInfo:
repo sha at this particular revision
lastModified (`str`, *optional*):
date of last commit to repo
tags (`Listr[str]`, *optional*):
tags (`List[str]`, *optional*):
List of tags.
siblings (`List[RepoFile]`, *optional*):
list of [`huggingface_hub.hf_api.RepoFile`] objects that constitute the dataset.
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/keras_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _flatten_dict(dictionary, parent_key=""):
dictionary (`dict`):
The nested dictionary to be flattened.
parent_key (`str`):
The parent key to be prefixed to the childer keys.
The parent key to be prefixed to the children keys.
Necessary for recursing over the nested dictionary.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/repocard.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class SpaceCard(RepoCard):
def _detect_line_ending(content: str) -> Literal["\r", "\n", "\r\n", None]: # noqa: F722
"""Detect the line ending of a string. Used by RepoCard to avoid making huge diff on newlines.
Uses same implem as in Hub server, keep it in sync.
Uses same implementation as in Hub server, keep it in sync.
Returns:
str: The detected line ending of the string.
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/utils/_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def filter_repo_objects(
items (`Iterable`):
List of items to filter.
allow_patterns (`str` or `List[str]`, *optional*):
Patterns constituing the allowlist. If provided, item paths must match at
Patterns constituting the allowlist. If provided, item paths must match at
least one pattern from the allowlist.
ignore_patterns (`str` or `List[str]`, *optional*):
Patterns constituing the denylist. If provided, item paths must not match
Patterns constituting the denylist. If provided, item paths must not match
any patterns from the denylist.
key (`Callable[[T], str]`, *optional*):
Single-argument function to extract a path from each item. If not provided,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endpoint_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_removing_item(self):

def test_dir(self):
# Since we subclass dict, dir should have everything
# from dict and the atttributes
# from dict and the attributes
_dict_keys = dir(dict) + [
"__dict__",
"__getattr__",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_create_update_and_delete_space_repo(self):
with pytest.raises(ValueError, match=r"No space_sdk provided.*"):
self._api.create_repo(repo_id=SPACE_REPO_NAME, repo_type=REPO_TYPE_SPACE, space_sdk=None)
with pytest.raises(ValueError, match=r"Invalid space_sdk.*"):
self._api.create_repo(repo_id=SPACE_REPO_NAME, repo_type=REPO_TYPE_SPACE, space_sdk="asdfasdf")
self._api.create_repo(repo_id=SPACE_REPO_NAME, repo_type=REPO_TYPE_SPACE, space_sdk="something")

for sdk in SPACES_SDK_TYPES:
SPACE_REPO_NAME = space_repo_name(sdk)
Expand Down Expand Up @@ -2086,12 +2086,12 @@ def test_rename_discussion(self):
rename_event = self._api.rename_discussion(
repo_id=self.repo_name,
discussion_num=self.discussion.num,
new_title="New titlee",
new_title="New title2",
)
retrieved = self._api.get_discussion_details(repo_id=self.repo_name, discussion_num=self.discussion.num)
self.assertIn(rename_event.id, (event.id for event in retrieved.events))
self.assertEqual(rename_event.old_title, self.discussion.title)
self.assertEqual(rename_event.new_title, "New titlee")
self.assertEqual(rename_event.new_title, "New title2")

def test_change_discussion_status(self):
status_change_event = self._api.change_discussion_status(
Expand Down
34 changes: 17 additions & 17 deletions tests/test_keras_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,28 +234,28 @@ def test_save_model_card_history_removal(self):
REPO_NAME = repo_name("save")
model = self.model_init()
model = self.model_fit(model)
with SoftTemporaryDirectory() as tmpdirname:
os.makedirs(f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}")
with open(f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}/history.json", "w+") as fp:
with SoftTemporaryDirectory() as tmpdir:
os.makedirs(f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}")
with open(f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}/history.json", "w+") as fp:
fp.write("Keras FTW")

with pytest.warns(UserWarning, match="`history.json` file already exists, *"):
save_pretrained_keras(
model,
f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}",
f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}",
)
# assert that it's not the same as old history file and it's overridden
with open(f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}/history.json", "r") as f:
with open(f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}/history.json", "r") as f:
history_content = f.read()
self.assertNotEqual("Keras FTW", history_content)

# Check the history is saved as a json in the repository.
files = os.listdir(f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}")
files = os.listdir(f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}")
self.assertIn("history.json", files)

# Check that there is no "Training Metrics" section in the model card.
# This was done in an older version.
with open(f"{tmpdirname}/{WORKING_REPO_DIR}/{REPO_NAME}/README.md", "r") as file:
with open(f"{tmpdir}/{WORKING_REPO_DIR}/{REPO_NAME}/README.md", "r") as file:
data = file.read()
self.assertNotIn(data, "Training Metrics")

Expand Down Expand Up @@ -385,27 +385,27 @@ def test_push_to_hub_keras_via_http_override_tensorboard(self):
"""Test log directory is overwritten when pushing a keras model a 2nd time."""
REPO_NAME = repo_name("PUSH_TO_HUB_KERAS_via_http_override_tensorboard")
repo_id = f"{USER}/{REPO_NAME}"
with SoftTemporaryDirectory() as tmpdirname:
os.makedirs(f"{tmpdirname}/tb_log_dir")
with open(f"{tmpdirname}/tb_log_dir/tensorboard.txt", "w") as fp:
with SoftTemporaryDirectory() as tmpdir:
os.makedirs(f"{tmpdir}/tb_log_dir")
with open(f"{tmpdir}/tb_log_dir/tensorboard.txt", "w") as fp:
fp.write("Keras FTW")
model = self.model_init()
model.build((None, 2))
push_to_hub_keras(
model,
repo_id=repo_id,
log_dir=f"{tmpdirname}/tb_log_dir",
log_dir=f"{tmpdir}/tb_log_dir",
api_endpoint=ENDPOINT_STAGING,
token=self._token,
)

os.makedirs(f"{tmpdirname}/tb_log_dir2")
with open(f"{tmpdirname}/tb_log_dir2/override.txt", "w") as fp:
os.makedirs(f"{tmpdir}/tb_log_dir2")
with open(f"{tmpdir}/tb_log_dir2/override.txt", "w") as fp:
fp.write("Keras FTW")
push_to_hub_keras(
model,
repo_id=repo_id,
log_dir=f"{tmpdirname}/tb_log_dir2",
log_dir=f"{tmpdir}/tb_log_dir2",
api_endpoint=ENDPOINT_STAGING,
token=self._token,
)
Expand Down Expand Up @@ -435,9 +435,9 @@ def test_push_to_hub_keras_via_http_with_model_kwargs(self):
model_info = HfApi(endpoint=ENDPOINT_STAGING).model_info(repo_id)
self.assertEqual(model_info.modelId, repo_id)

with SoftTemporaryDirectory() as tmpdirname:
Repository(local_dir=tmpdirname, clone_from=ENDPOINT_STAGING + "/" + repo_id)
from_pretrained_keras(tmpdirname)
with SoftTemporaryDirectory() as tmpdir:
Repository(local_dir=tmpdir, clone_from=ENDPOINT_STAGING + "/" + repo_id)
from_pretrained_keras(tmpdir)

self._api.delete_repo(repo_id=f"{REPO_NAME}")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ def test_arbitrary_incoming_card_data(self):
metric_value=0.9,
),
],
some_abitrary_kwarg="some_value",
some_arbitrary_kwarg="some_value",
)

self.assertEqual(data.some_abitrary_kwarg, "some_value")
self.assertEqual(data.some_arbitrary_kwarg, "some_value")

data_dict = data.to_dict()
self.assertEqual(data_dict["some_abitrary_kwarg"], "some_value")
self.assertEqual(data_dict["some_arbitrary_kwarg"], "some_value")


class DatasetCardDataTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def test_auto_track_updates_removed_gitattributes(self):
self.repo.auto_track_large_files()
self.assertFalse(is_tracked_with_lfs(txt_large_file))

def test_checkout_non_existant_branch(self):
def test_checkout_non_existing_branch(self):
self.assertRaises(EnvironmentError, self.repo.git_checkout, "brand-new-branch")

def test_checkout_new_branch(self):
Expand Down
56 changes: 28 additions & 28 deletions tests/test_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def tearDownClass(cls) -> None:

def test_download_model(self):
# Test `main` branch
with SoftTemporaryDirectory() as tmpdirname:
storage_folder = snapshot_download(f"{USER}/{REPO_NAME}", revision="main", cache_dir=tmpdirname)
with SoftTemporaryDirectory() as tmpdir:
storage_folder = snapshot_download(f"{USER}/{REPO_NAME}", revision="main", cache_dir=tmpdir)

# folder contains the two files contributed and the .gitattributes
folder_contents = os.listdir(storage_folder)
Expand All @@ -101,11 +101,11 @@ def test_download_model(self):
self.assertTrue(self.second_commit_hash in storage_folder)

# Test with specific revision
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision=self.first_commit_hash,
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# folder contains the two files contributed and the .gitattributes
Expand All @@ -125,17 +125,17 @@ def test_download_private_model(self):
self._api.update_repo_visibility(repo_id=REPO_NAME, private=True)

# Test download fails without token
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
with self.assertRaisesRegex(requests.exceptions.HTTPError, "401 Client Error"):
_ = snapshot_download(f"{USER}/{REPO_NAME}", revision="main", cache_dir=tmpdirname)
_ = snapshot_download(f"{USER}/{REPO_NAME}", revision="main", cache_dir=tmpdir)

# Test we can download with token from cache
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
HfFolder.save_token(self._token)
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision="main",
cache_dir=tmpdirname,
cache_dir=tmpdir,
use_auth_token=True,
)

Expand All @@ -154,11 +154,11 @@ def test_download_private_model(self):
self.assertTrue(self.second_commit_hash in storage_folder)

# Test we can download with explicit token
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision="main",
cache_dir=tmpdirname,
cache_dir=tmpdir,
use_auth_token=self._token,
)

Expand All @@ -180,14 +180,14 @@ def test_download_private_model(self):

def test_download_model_local_only(self):
# Test no branch specified
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
# first download folder to cache it
snapshot_download(f"{USER}/{REPO_NAME}", cache_dir=tmpdirname)
snapshot_download(f"{USER}/{REPO_NAME}", cache_dir=tmpdir)

# now load from cache
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
cache_dir=tmpdirname,
cache_dir=tmpdir,
local_files_only=True,
)

Expand All @@ -206,19 +206,19 @@ def test_download_model_local_only(self):
self.assertTrue(self.second_commit_hash in storage_folder)

# Test with specific revision branch
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
# first download folder to cache it
snapshot_download(
f"{USER}/{REPO_NAME}",
revision="other",
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# now load from cache
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision="other",
cache_dir=tmpdirname,
cache_dir=tmpdir,
local_files_only=True,
)

Expand All @@ -236,19 +236,19 @@ def test_download_model_local_only(self):
self.assertTrue(self.third_commit_hash in storage_folder)

# Test with specific revision hash
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
# first download folder to cache it
snapshot_download(
f"{USER}/{REPO_NAME}",
revision=self.first_commit_hash,
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# now load from cache
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision=self.first_commit_hash,
cache_dir=tmpdirname,
cache_dir=tmpdir,
local_files_only=True,
)

Expand All @@ -267,38 +267,38 @@ def test_download_model_local_only(self):

def test_download_model_local_only_multiple(self):
# Test `main` branch
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
# download both from branch and from commit
snapshot_download(
f"{USER}/{REPO_NAME}",
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

snapshot_download(
f"{USER}/{REPO_NAME}",
revision=self.first_commit_hash,
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# cache multiple commits and make sure correct commit is taken
with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
# first download folder to cache it
snapshot_download(
f"{USER}/{REPO_NAME}",
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# now load folder from another branch
snapshot_download(
f"{USER}/{REPO_NAME}",
revision="other",
cache_dir=tmpdirname,
cache_dir=tmpdir,
)

# now make sure that loading "main" branch gives correct branch
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
cache_dir=tmpdirname,
cache_dir=tmpdir,
local_files_only=True,
)

Expand All @@ -320,11 +320,11 @@ def check_download_model_with_pattern(self, pattern, allow=True):
allow_patterns = pattern if allow else None
ignore_patterns = pattern if not allow else None

with SoftTemporaryDirectory() as tmpdirname:
with SoftTemporaryDirectory() as tmpdir:
storage_folder = snapshot_download(
f"{USER}/{REPO_NAME}",
revision="main",
cache_dir=tmpdirname,
cache_dir=tmpdir,
allow_patterns=allow_patterns,
ignore_patterns=ignore_patterns,
)
Expand Down
Loading

0 comments on commit a7f7702

Please sign in to comment.