hfutils 0.2.2__tar.gz → 0.2.4__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 (53) hide show
  1. {hfutils-0.2.2/hfutils.egg-info → hfutils-0.2.4}/PKG-INFO +1 -1
  2. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/config/meta.py +1 -1
  3. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/cli.py +2 -0
  4. hfutils-0.2.4/hfutils/entry/whoami.py +50 -0
  5. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/operate/download.py +5 -4
  6. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/__init__.py +1 -0
  7. hfutils-0.2.4/hfutils/utils/path.py +5 -0
  8. {hfutils-0.2.2 → hfutils-0.2.4/hfutils.egg-info}/PKG-INFO +1 -1
  9. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils.egg-info/SOURCES.txt +2 -0
  10. {hfutils-0.2.2 → hfutils-0.2.4}/LICENSE +0 -0
  11. {hfutils-0.2.2 → hfutils-0.2.4}/MANIFEST.in +0 -0
  12. {hfutils-0.2.2 → hfutils-0.2.4}/README.md +0 -0
  13. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/__init__.py +0 -0
  14. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/__init__.py +0 -0
  15. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/base.py +0 -0
  16. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/rar.py +0 -0
  17. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/sevenz.py +0 -0
  18. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/tar.py +0 -0
  19. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/archive/zip.py +0 -0
  20. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/config/__init__.py +0 -0
  21. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/__init__.py +0 -0
  22. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/base.py +0 -0
  23. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/dispatch.py +0 -0
  24. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/download.py +0 -0
  25. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/ls.py +0 -0
  26. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/entry/upload.py +0 -0
  27. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/index/__init__.py +0 -0
  28. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/index/fetch.py +0 -0
  29. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/index/hash.py +0 -0
  30. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/index/make.py +0 -0
  31. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/index/validate.py +0 -0
  32. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/operate/__init__.py +0 -0
  33. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/operate/base.py +0 -0
  34. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/operate/upload.py +0 -0
  35. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/operate/validate.py +0 -0
  36. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/binary.py +0 -0
  37. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/download.py +0 -0
  38. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/temp.py +0 -0
  39. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/tqdm_.py +0 -0
  40. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils/utils/walk.py +0 -0
  41. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils.egg-info/dependency_links.txt +0 -0
  42. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils.egg-info/entry_points.txt +0 -0
  43. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils.egg-info/requires.txt +0 -0
  44. {hfutils-0.2.2 → hfutils-0.2.4}/hfutils.egg-info/top_level.txt +0 -0
  45. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-7z.txt +0 -0
  46. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-build.txt +0 -0
  47. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-doc.txt +0 -0
  48. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-rar.txt +0 -0
  49. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-test.txt +0 -0
  50. {hfutils-0.2.2 → hfutils-0.2.4}/requirements-transfer.txt +0 -0
  51. {hfutils-0.2.2 → hfutils-0.2.4}/requirements.txt +0 -0
  52. {hfutils-0.2.2 → hfutils-0.2.4}/setup.cfg +0 -0
  53. {hfutils-0.2.2 → hfutils-0.2.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.2
3
+ Version: 0.2.4
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.2'
10
+ __VERSION__ = '0.2.4'
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
@@ -9,7 +9,7 @@ import requests.exceptions
9
9
  from .base import RepoTypeTyping, list_files_in_repository, _IGNORE_PATTERN_UNSET, get_hf_client
10
10
  from .validate import is_local_file_ready
11
11
  from ..archive import archive_unpack
12
- from ..utils import tqdm, TemporaryDirectory
12
+ from ..utils import tqdm, TemporaryDirectory, hf_normpath
13
13
 
14
14
 
15
15
  def download_file_to_file(local_file: str, repo_id: str, file_in_repo: str,
@@ -41,7 +41,7 @@ def download_file_to_file(local_file: str, repo_id: str, file_in_repo: str,
41
41
  hf_client.hf_hub_download(
42
42
  repo_id=repo_id,
43
43
  repo_type=repo_type,
44
- filename=file_in_repo,
44
+ filename=hf_normpath(file_in_repo),
45
45
  revision=revision,
46
46
  local_dir=td,
47
47
  force_download=True,
@@ -120,11 +120,12 @@ def download_directory_as_directory(local_directory: str, repo_id: str, dir_in_r
120
120
  current_resume_download = resume_download
121
121
  try:
122
122
  dst_file = os.path.join(local_directory, rel_file)
123
+ file_in_repo = hf_normpath(f'{dir_in_repo}/{rel_file}')
123
124
  if os.path.exists(dst_file) and is_local_file_ready(
124
125
  repo_id=repo_id,
125
126
  repo_type=repo_type,
126
127
  local_file=dst_file,
127
- file_in_repo=f'{dir_in_repo}/{rel_file}',
128
+ file_in_repo=file_in_repo,
128
129
  revision=revision,
129
130
  hf_token=hf_token,
130
131
  ):
@@ -136,7 +137,7 @@ def download_directory_as_directory(local_directory: str, repo_id: str, dir_in_r
136
137
  download_file_to_file(
137
138
  local_file=dst_file,
138
139
  repo_id=repo_id,
139
- file_in_repo=f'{dir_in_repo}/{rel_file}',
140
+ file_in_repo=file_in_repo,
140
141
  repo_type=repo_type,
141
142
  revision=revision,
142
143
  resume_download=current_resume_download,
@@ -1,5 +1,6 @@
1
1
  from .binary import is_binary_file
2
2
  from .download import download_file
3
+ from .path import hf_normpath
3
4
  from .temp import TemporaryDirectory
4
5
  from .tqdm_ import tqdm
5
6
  from .walk import walk_files
@@ -0,0 +1,5 @@
1
+ import os
2
+
3
+
4
+ def hf_normpath(path):
5
+ return os.path.normpath(path).replace('\\', '/')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.2
3
+ Version: 0.2.4
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
@@ -44,6 +45,7 @@ hfutils/operate/validate.py
44
45
  hfutils/utils/__init__.py
45
46
  hfutils/utils/binary.py
46
47
  hfutils/utils/download.py
48
+ hfutils/utils/path.py
47
49
  hfutils/utils/temp.py
48
50
  hfutils/utils/tqdm_.py
49
51
  hfutils/utils/walk.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
File without changes