hfutils 0.2.1__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {hfutils-0.2.1/hfutils.egg-info → hfutils-0.2.3}/PKG-INFO +1 -1
  2. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/config/meta.py +1 -1
  3. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/cli.py +2 -0
  4. hfutils-0.2.3/hfutils/entry/whoami.py +50 -0
  5. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/index/fetch.py +11 -9
  6. {hfutils-0.2.1 → hfutils-0.2.3/hfutils.egg-info}/PKG-INFO +1 -1
  7. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils.egg-info/SOURCES.txt +1 -0
  8. {hfutils-0.2.1 → hfutils-0.2.3}/LICENSE +0 -0
  9. {hfutils-0.2.1 → hfutils-0.2.3}/MANIFEST.in +0 -0
  10. {hfutils-0.2.1 → hfutils-0.2.3}/README.md +0 -0
  11. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/__init__.py +0 -0
  12. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/__init__.py +0 -0
  13. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/base.py +0 -0
  14. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/rar.py +0 -0
  15. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/sevenz.py +0 -0
  16. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/tar.py +0 -0
  17. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/archive/zip.py +0 -0
  18. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/config/__init__.py +0 -0
  19. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/__init__.py +0 -0
  20. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/base.py +0 -0
  21. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/dispatch.py +0 -0
  22. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/download.py +0 -0
  23. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/ls.py +0 -0
  24. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/entry/upload.py +0 -0
  25. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/index/__init__.py +0 -0
  26. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/index/hash.py +0 -0
  27. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/index/make.py +0 -0
  28. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/index/validate.py +0 -0
  29. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/operate/__init__.py +0 -0
  30. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/operate/base.py +0 -0
  31. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/operate/download.py +0 -0
  32. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/operate/upload.py +0 -0
  33. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/operate/validate.py +0 -0
  34. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/__init__.py +0 -0
  35. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/binary.py +0 -0
  36. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/download.py +0 -0
  37. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/temp.py +0 -0
  38. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/tqdm_.py +0 -0
  39. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils/utils/walk.py +0 -0
  40. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils.egg-info/dependency_links.txt +0 -0
  41. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils.egg-info/entry_points.txt +0 -0
  42. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils.egg-info/requires.txt +0 -0
  43. {hfutils-0.2.1 → hfutils-0.2.3}/hfutils.egg-info/top_level.txt +0 -0
  44. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-7z.txt +0 -0
  45. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-build.txt +0 -0
  46. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-doc.txt +0 -0
  47. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-rar.txt +0 -0
  48. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-test.txt +0 -0
  49. {hfutils-0.2.1 → hfutils-0.2.3}/requirements-transfer.txt +0 -0
  50. {hfutils-0.2.1 → hfutils-0.2.3}/requirements.txt +0 -0
  51. {hfutils-0.2.1 → hfutils-0.2.3}/setup.cfg +0 -0
  52. {hfutils-0.2.1 → hfutils-0.2.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
@@ -7,7 +7,7 @@ Overview:
7
7
  __TITLE__ = 'hfutils'
8
8
 
9
9
  #: Version of this project.
10
- __VERSION__ = '0.2.1'
10
+ __VERSION__ = '0.2.3'
11
11
 
12
12
  #: Short description of the project, will be included in ``setup.py``.
13
13
  __DESCRIPTION__ = 'Useful utilities for huggingface'
@@ -2,11 +2,13 @@ from .dispatch import hfutilcli
2
2
  from .download import _add_download_subcommand
3
3
  from .ls import _add_ls_subcommand
4
4
  from .upload import _add_upload_subcommand
5
+ from .whoami import _add_whoami_subcommand
5
6
 
6
7
  _DECORATORS = [
7
8
  _add_download_subcommand,
8
9
  _add_upload_subcommand,
9
10
  _add_ls_subcommand,
11
+ _add_whoami_subcommand,
10
12
  ]
11
13
 
12
14
  cli = hfutilcli
@@ -0,0 +1,50 @@
1
+ import click
2
+ from hbutils.string import plural_word
3
+ from huggingface_hub.utils import LocalTokenNotFoundError
4
+
5
+ from .base import CONTEXT_SETTINGS
6
+ from ..operate.base import get_hf_client
7
+
8
+
9
+ def _add_whoami_subcommand(cli: click.Group) -> click.Group:
10
+ """
11
+ Add the 'whoami' subcommand to the CLI.
12
+
13
+ This command displays the current identification.
14
+
15
+ :param cli: The Click CLI application.
16
+ :type cli: click.Group
17
+ :return: The modified Click CLI application.
18
+ :rtype: click.Group
19
+ """
20
+
21
+ @cli.command('whoami', help='See the current identification.\n\n'
22
+ 'Set environment $HF_TOKEN to use your own access token.',
23
+ context_settings=CONTEXT_SETTINGS)
24
+ def whoami():
25
+ """
26
+ Display the current identification.
27
+
28
+ This function retrieves the current user's identification from the Hugging Face Hub API and displays it.
29
+
30
+ """
31
+ hf_client = get_hf_client()
32
+ try:
33
+ info = hf_client.whoami()
34
+ username = info['name']
35
+ click.echo(f'Hi, {click.style(f"@{username}", fg="green", bold=True)} '
36
+ f'(full name: {click.style(info["fullname"], underline=True)}'
37
+ f'{", PRO" if info["isPro"] else ""}).')
38
+ click.echo(f'You can access all resources with this identification.')
39
+ if info['orgs']:
40
+ click.echo(f'You have entered {plural_word(len(info["orgs"]), "organizations")}:')
41
+ for i, org_item in enumerate(info['orgs'], start=1):
42
+ click.echo(f'{i}. {click.style("@" + org_item["name"], fg="blue", bold=True)} '
43
+ f'(full name: {click.style(org_item["fullname"], underline=True)})')
44
+ except LocalTokenNotFoundError:
45
+ click.echo(f'Hi, {click.style("Guest", fg="yellow", bold=True)} (not authenticated).')
46
+ click.echo(click.style(f'No token for huggingface authentication found.', underline=True))
47
+ click.echo(f'If you need to access more, just set `HF_TOKEN` environment variable, '
48
+ f'or use `huggingface-cli login`.')
49
+
50
+ return cli
@@ -240,6 +240,7 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
240
240
  f'in {repo_type}s/{repo_id}@{revision}/{archive_in_repo}.')
241
241
 
242
242
  info = files[_n_path(file_in_archive)]
243
+
243
244
  url_to_download = hf_hub_url(repo_id, archive_in_repo, repo_type=repo_type, revision=revision, endpoint=endpoint)
244
245
  headers = build_hf_headers(
245
246
  token=hf_token,
@@ -256,15 +257,16 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
256
257
  os.makedirs(os.path.dirname(local_file), exist_ok=True)
257
258
  try:
258
259
  with open(local_file, 'wb') as f:
259
- http_get(
260
- url_to_download,
261
- f,
262
- proxies=proxies,
263
- resume_size=0,
264
- headers=headers,
265
- expected_size=info['size'],
266
- displayed_filename=file_in_archive,
267
- )
260
+ if info['size'] > 0:
261
+ http_get(
262
+ url_to_download,
263
+ f,
264
+ proxies=proxies,
265
+ resume_size=0,
266
+ headers=headers,
267
+ expected_size=info['size'],
268
+ displayed_filename=file_in_archive,
269
+ )
268
270
 
269
271
  if os.path.getsize(local_file) != info['size']:
270
272
  raise ArchiveStandaloneFileIncompleteDownload(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
@@ -31,6 +31,7 @@ hfutils/entry/dispatch.py
31
31
  hfutils/entry/download.py
32
32
  hfutils/entry/ls.py
33
33
  hfutils/entry/upload.py
34
+ hfutils/entry/whoami.py
34
35
  hfutils/index/__init__.py
35
36
  hfutils/index/fetch.py
36
37
  hfutils/index/hash.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes