summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 50aebfed578346143c6013709e1f0cfcc112f5fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Maintainer: Lumaku <lumaku@mailbox.org>
# shellcheck shell=bash disable=SC2034,SC2154,SC2164  # var unused / var not assigned / cd without || exit
pkgname=python-huggingface-hub-git
pkgver=1.21.0.r2538.g1e41293
pkgrel=1
_repo=huggingface/huggingface_hub
pkgdesc='Client library to download and publish models on the huggingface.co hub'
arch=('any')
url="https://github.com/${_repo}"
license=('Apache-2.0')
groups=('huggingface')
depends=(
    'python'
    'python-click'
    'python-filelock'
    'python-fsspec'
    'python-httpx'
    'python-packaging'
    'python-tqdm'
    'python-typer'
    'python-typing_extensions'
    'python-yaml'
)
makedepends=(
    'git'
    'python-build'
    'python-installer'
    'python-setuptools'
    'python-wheel'
)
checkdepends=(
    'git-lfs'
    'python-authlib'
    'python-duckdb'
    'python-fastapi'
    'python-itsdangerous'
    'python-jedi'
    'python-jinja'
    'python-numpy'
    'python-pillow'
    'python-pydantic'
    'python-pytest'
    'python-pytest-asyncio'
    'python-pytest-env'
    'python-pytest-mock'
    'python-pytest-timeout'
    'python-pytest-vcr'
    'python-pytest-xdist'
    'python-urllib3'
)
optdepends=(
    'python-torch: PyTorch-related features'
    'python-gradio: Gradio-related features'
    'python-authlib: OAuth support'
    'python-duckdb: hf datasets SQL support'
    'python-fastapi: OAuth support'
    'python-graphviz: graph rendering support'
    'python-hf-xet: Xet storage backend'
    'python-itsdangerous: OAuth support'
    'python-jinja: Model/dataset cards templating'
    'python-numpy: embeddings and inference array outputs'
    'python-pillow: Inference image features'
    'python-pydantic: webhook payload models'
    'python-pydot: graph rendering support'
    'python-safetensors: safetensors serialization support'
    'python-toml: fastai utilities'
)
provides=("python-huggingface-hub=${pkgver}")
conflicts=("python-huggingface-hub")
source=("${pkgname}::git+${url}")
b2sums=('SKIP')


pkgver() {
    cd "${pkgname}"
    local _ver _rev _sha
    _ver="$(git tag --list 'v*' --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 | sed 's/^v//')"
    _rev="$(git rev-list --count HEAD)"
    _sha="$(git rev-parse --short=7 HEAD)"
    printf "%s.r%s.g%s" "${_ver}" "${_rev}" "${_sha}"
}


prepare() {
    cd "${pkgname}"
    git clean -dfx
}


build() {
    cd "${pkgname}"
    # Silence the very verbose "copying ..." messages, but still see warnings:
    python -m build --wheel --no-isolation > /dev/null

    # Generate shell completions via Typer
    local _completions_dir="${srcdir}/completions"
    mkdir -p "${_completions_dir}"
    # venv also used by check()
    python -m venv --clear --system-site-packages "${srcdir}/test-env"
    "${srcdir}/test-env/bin/python" -m installer dist/*.whl

    local _tool _shell _completion_file _completion_fn
    for _tool in hf tiny-agents; do
        for _shell in bash zsh; do
            _completion_file="${_completions_dir}/${_tool}.${_shell}"
            _TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION=1 \
                "${srcdir}/test-env/bin/${_tool}" --show-completion="${_shell}" \
                > "${_completion_file}"
            if [[ "${_shell}" == zsh ]]; then
                _completion_fn="_${_tool}"
                # zsh autoloads completion files by filename, so _hf must define _hf, not _hf_completion.
                sed -i "s/${_completion_fn//-/_}_completion/${_completion_fn}/g" "${_completion_file}"
            fi
        done
    done
}


check() {
    local pytest_options=(
        -vv
        --override-ini="addopts="
        -W ignore::DeprecationWarning
        -n auto
        --timeout=300
        --timeout-method signal
        --deselect tests/test_buckets.py
        --deselect tests/test_buckets_cli.py
        --deselect tests/test_buckets_hf_file_system.py
        --deselect tests/test_cache_layout.py
        --deselect tests/test_cache_no_symlinks.py
        --deselect tests/test_commit_scheduler.py
        --deselect tests/test_file_download.py
        --deselect tests/test_hf_api.py
        --deselect tests/test_hf_file_system.py
        --deselect tests/test_inference_client.py
        --deselect tests/test_kernels.py
        --deselect tests/test_oauth.py::test_oauth_workflow
        --deselect tests/test_repocard.py
        --deselect tests/test_repository.py
        --deselect tests/test_snapshot_download.py
        --deselect tests/test_utils_cache.py
        --deselect tests/test_webhooks_server.py::test_deserialize_payload_example_with_comment
        --deselect tests/test_webhooks_server.py::test_deserialize_payload_example_without_comment
        --deselect tests/test_webhooks_server.py::test_deserialize_payload_example_with_updated_refs
        --deselect tests/test_utils_strict_dataclass.py::test_autocompletion_init_with_kwargs
        --deselect tests/test_utils_strict_dataclass.py::test_autocompletion_init_without_kwargs
        --deselect tests/test_utils_strict_dataclass.py::test_autocompletion_attribute_with_kwargs
        --deselect tests/test_utils_strict_dataclass.py::test_autocompletion_attribute_without_kwargs
        --deselect tests/test_login_utils.py::TestSetGlobalStore::test_set_store_as_git_credential_helper_globally
        --deselect tests/test_xet_upload.py::TestXetLargeUpload::test_upload_large_folder_batch_size_greater_than_one
        --deselect tests/test_cli.py::TestDownloadCommand::test_download_with_all_options
        --deselect tests/test_cli_output.py
        --deselect tests/test_cli.py
        --deselect tests/test_cli_discussions.py
        --deselect tests/test_copy_files.py
    )

    cd "${pkgname}"
    "${srcdir}/test-env/bin/python" -P -m pytest "${pytest_options[@]}" tests
}


package() {
    cd "${pkgname}"
    python -m installer --destdir="$pkgdir" dist/*.whl

    # Shell completions (generated at build time)
    local _completions_dir="${srcdir}/completions"
    local _tool
    for _tool in hf tiny-agents; do
        install -Dm644 "${_completions_dir}/${_tool}.bash" "${pkgdir}/usr/share/bash-completion/completions/${_tool}"
        install -Dm644 "${_completions_dir}/${_tool}.zsh" "${pkgdir}/usr/share/zsh/site-functions/_${_tool}"
    done
}

# vim:set ts=2 sw=2 et ft=PKGBUILD: