mirror of
https://github.com/gentoo-mirror/guru.git
synced 2026-07-18 03:23:20 -04:00
dev-python/openai: add 2.44.0
Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
This commit is contained in:
167
dev-python/openai/openai-2.44.0.ebuild
Normal file
167
dev-python/openai/openai-2.44.0.ebuild
Normal file
@@ -0,0 +1,167 @@
|
||||
# Copyright 2026 Gentoo Authors
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
EAPI=8
|
||||
|
||||
DISTUTILS_USE_PEP517=hatchling
|
||||
PYTHON_COMPAT=( python3_{12..14} )
|
||||
|
||||
inherit distutils-r1 pypi
|
||||
|
||||
# See https://github.com/openai/openai-python/blob/main/.stats.yml
|
||||
API_SPEC_BASE="https://storage.googleapis.com/stainless-sdk-openapi-specs/openai"
|
||||
API_SPEC="openai-openapi-spec-${PV}.yml"
|
||||
MY_PN="openai-python"
|
||||
MY_P="${MY_PN}-${PV}"
|
||||
# See https://github.com/openai/openai-python/blob/main/scripts/mock
|
||||
STDY_PV=0.22.1
|
||||
DESCRIPTION="The official Python library for the openai API"
|
||||
HOMEPAGE="
|
||||
https://github.com/openai/openai-python
|
||||
https://pypi.org/project/openai/
|
||||
"
|
||||
SRC_URI="
|
||||
https://github.com/openai/${MY_PN}/archive/refs/tags/v${PV}.tar.gz
|
||||
-> ${MY_P}.gh.tar.gz
|
||||
|
||||
test? (
|
||||
${API_SPEC_BASE}/openai-b5b621065906a2579dc180db1236ee3b08a4fca9539accc2fbbf88da0ca3923f.yml
|
||||
-> ${API_SPEC}
|
||||
|
||||
https://registry.npmjs.org/@stdy/cli/-/cli-${STDY_PV}.tgz
|
||||
-> npm-@stdy-cli-cli-${STDY_PV}.tgz
|
||||
|
||||
amd64? (
|
||||
https://registry.npmjs.org/@stdy/cli-linux-x64/-/cli-linux-x64-${STDY_PV}.tgz
|
||||
-> npm-@stdy-cli-linux-x64-cli-linux-x64-${STDY_PV}.tgz
|
||||
)
|
||||
|
||||
arm64? (
|
||||
https://registry.npmjs.org/@stdy/cli-linux-arm64/-/cli-linux-arm64-${STDY_PV}.tgz
|
||||
-> npm-@stdy-cli-linux-arm64-cli-linux-arm64-${STDY_PV}.tgz
|
||||
)
|
||||
)
|
||||
"
|
||||
S="${WORKDIR}/${MY_P}"
|
||||
|
||||
LICENSE="Apache-2.0"
|
||||
SLOT="0"
|
||||
KEYWORDS="~amd64 ~arm64"
|
||||
|
||||
RDEPEND="
|
||||
>=dev-python/anyio-3.5.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/distro-1.7.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/httpx-0.23.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/jiter-0.10.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/pydantic-1.9.0[${PYTHON_USEDEP}]
|
||||
dev-python/sniffio[${PYTHON_USEDEP}]
|
||||
>=dev-python/tqdm-4.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/typing-extensions-4.14[${PYTHON_USEDEP}]
|
||||
"
|
||||
|
||||
BDEPEND="
|
||||
dev-python/hatch-fancy-pypi-readme[${PYTHON_USEDEP}]
|
||||
test? (
|
||||
>=dev-python/botocore-1.42.97[${PYTHON_USEDEP}]
|
||||
dev-python/dirty-equals[${PYTHON_USEDEP}]
|
||||
dev-python/distro[${PYTHON_USEDEP}]
|
||||
dev-python/httpx-aiohttp[${PYTHON_USEDEP}]
|
||||
>=dev-python/importlib-metadata-6.7.0[${PYTHON_USEDEP}]
|
||||
>=dev-python/jsonschema-4.23.0[${PYTHON_USEDEP}]
|
||||
net-libs/nodejs[npm]
|
||||
net-misc/curl
|
||||
)
|
||||
"
|
||||
|
||||
EPYTEST_PLUGINS=(
|
||||
inline-snapshot
|
||||
nest-asyncio
|
||||
pytest-{asyncio,xdist}
|
||||
respx
|
||||
time-machine
|
||||
)
|
||||
distutils_enable_tests pytest
|
||||
|
||||
src_unpack() {
|
||||
unpack "${MY_P}.gh.tar.gz"
|
||||
}
|
||||
|
||||
src_test() {
|
||||
einfo "Assembling npm cache..."
|
||||
|
||||
local -x npm_config_cache="${WORKDIR}/npm-cache"
|
||||
mkdir -p "${npm_config_cache}" || die
|
||||
|
||||
for distfile in ${A}; do
|
||||
if [[ "${distfile}" == npm-* ]]; then
|
||||
npm cache add "${DISTDIR}/${distfile}" &>/dev/null || die
|
||||
fi
|
||||
done
|
||||
|
||||
einfo "Installing mock server..."
|
||||
|
||||
local mock_dir="${WORKDIR}/mock-server"
|
||||
mkdir -p "${mock_dir}" || die
|
||||
|
||||
cp "${FILESDIR}/${PN}-2.44.0-mock-server-package.json" \
|
||||
"${mock_dir}/package.json" || die
|
||||
cp "${FILESDIR}/${PN}-2.44.0-mock-server-package-lock.json" \
|
||||
"${mock_dir}/package-lock.json" || die
|
||||
|
||||
local mock_dir="${WORKDIR}/mock-server"
|
||||
local mock="${mock_dir}/node_modules/.bin/steady"
|
||||
|
||||
pushd "${mock_dir}" >/dev/null || die
|
||||
|
||||
npm ci &>/dev/null || die
|
||||
|
||||
einfo "Starting mock server..."
|
||||
|
||||
# Replicate the logic from scripts/mock --daemon
|
||||
"${mock}" --host 127.0.0.1 -p 4010 \
|
||||
--validator-form-array-format=brackets \
|
||||
--validator-query-array-format=brackets \
|
||||
--validator-form-object-format=brackets \
|
||||
--validator-query-object-format=brackets \
|
||||
"${DISTDIR}/${API_SPEC}" &> .stdy.log &
|
||||
local mock_pid=$!
|
||||
|
||||
is_mock_running() {
|
||||
local -a args
|
||||
readarray -d '' args < "/proc/${mock_pid}/cmdline" 2>/dev/null || return 1
|
||||
[[ "${args[1]}" == "${mock}" ]]
|
||||
}
|
||||
|
||||
local attempts=0
|
||||
while ! curl -sf "http://127.0.0.1:4010/_x-steady/health" &>/dev/null; do
|
||||
if ! is_mock_running; then
|
||||
cat .stdy.log
|
||||
die "Mock server failed to start"
|
||||
fi
|
||||
attempts=$((attempts + 1))
|
||||
if (( attempts >= 300 )); then
|
||||
cat .stdy.log
|
||||
die "Timed out waiting for mock server to start"
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
# Oops; connected to another Steady instance running on 4010
|
||||
is_mock_running || die
|
||||
|
||||
popd >/dev/null || die
|
||||
|
||||
nonfatal distutils-r1_src_test
|
||||
local ret=${?}
|
||||
|
||||
if is_mock_running; then
|
||||
einfo "Stopping mock server..."
|
||||
kill "${mock_pid}" || die
|
||||
fi
|
||||
|
||||
[[ ${ret} -ne 0 ]] && die
|
||||
}
|
||||
|
||||
python_test() {
|
||||
epytest -o asyncio_mode=auto
|
||||
}
|
||||
Reference in New Issue
Block a user