# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=hatchling
PYTHON_COMPAT=( python3_{11..14} )
RUST_MIN_VER="1.94.0"

CRATES="
	addr2line@0.25.1
	adler2@2.0.1
	aes@0.8.4
	ahash@0.8.12
	aho-corasick@1.1.3
	aligned-vec@0.6.4
	alloc-no-stdlib@2.0.4
	alloc-stdlib@0.2.2
	allocator-api2@0.2.21
	android_system_properties@0.1.5
	anes@0.1.6
	anstream@0.6.20
	anstyle-parse@0.2.7
	anstyle-query@1.1.4
	anstyle-wincon@3.0.10
	anstyle@1.0.11
	anyhow@1.0.104
	arrayvec@0.7.6
	arrow-arith@56.2.0
	arrow-array@56.2.0
	arrow-buffer@56.2.0
	arrow-cast@56.2.0
	arrow-csv@56.2.0
	arrow-data@56.2.0
	arrow-ipc@56.2.0
	arrow-json@56.2.0
	arrow-ord@56.2.0
	arrow-row@56.2.0
	arrow-schema@56.2.0
	arrow-select@56.2.0
	arrow-string@56.2.0
	arrow@56.2.0
	asn1-rs-derive@0.5.1
	asn1-rs-impl@0.2.0
	asn1-rs@0.6.2
	assert-json-diff@2.0.2
	async-compression@0.4.33
	async-trait@0.1.89
	atoi@2.0.0
	atomic-waker@1.1.2
	autocfg@1.5.0
	aws-config@1.8.12
	aws-credential-types@1.2.11
	aws-lc-fips-sys@0.13.17
	aws-lc-rs@1.16.1
	aws-lc-sys@0.38.0
	aws-runtime@1.5.18
	aws-sdk-s3@1.106.0
	aws-sdk-sts@1.96.0
	aws-sigv4@1.3.7
	aws-smithy-async@1.2.14
	aws-smithy-checksums@0.63.8
	aws-smithy-eventstream@0.60.14
	aws-smithy-http@0.62.6
	aws-smithy-json@0.61.9
	aws-smithy-observability@0.2.0
	aws-smithy-query@0.60.9
	aws-smithy-runtime-api@1.10.0
	aws-smithy-runtime@1.9.8
	aws-smithy-types@1.3.6
	aws-smithy-xml@0.60.15
	aws-types@1.3.11
	axum-core@0.5.6
	axum@0.8.9
	backtrace@0.3.76
	base64-simd@0.8.0
	base64@0.22.1
	base64ct@1.8.0
	bindgen@0.72.1
	bitflags@1.3.2
	bitflags@2.9.4
	block-buffer@0.10.4
	block-padding@0.3.3
	block2@0.6.2
	brotli-decompressor@5.0.0
	brotli@8.0.2
	bumpalo@3.19.0
	bytemuck@1.25.0
	byteorder@1.5.0
	bytes-utils@0.1.4
	bytes@1.11.1
	bzip2@0.6.0
	cast@0.3.0
	cbc@0.1.2
	cc@1.2.39
	cexpr@0.6.0
	cfb@0.7.3
	cfg-if@1.0.3
	cfg_aliases@0.2.1
	chrono@0.4.45
	ciborium-io@0.2.2
	ciborium-ll@0.2.2
	ciborium@0.2.2
	cipher@0.4.4
	clang-sys@1.8.1
	clap@4.5.48
	clap_builder@4.5.48
	clap_derive@4.5.47
	clap_lex@0.7.5
	cmake@0.1.54
	colorchoice@1.0.4
	combine@4.6.7
	compression-codecs@0.4.32
	compression-core@0.4.31
	const-oid@0.9.6
	const-random-macro@0.1.16
	const-random@0.1.18
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	core-foundation@0.9.4
	cpp_demangle@0.5.1
	cpufeatures@0.2.17
	crc-catalog@2.4.0
	crc-fast@1.3.0
	crc32fast@1.5.0
	crc@3.3.0
	criterion-plot@0.5.0
	criterion@0.5.1
	crossbeam-channel@0.5.15
	crossbeam-deque@0.8.6
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crunchy@0.2.4
	crypto-common@0.1.6
	csv-core@0.1.12
	csv@1.3.1
	ctor@1.0.13
	data-encoding@2.9.0
	deadpool-runtime@0.1.4
	deadpool@0.12.3
	debugid@0.8.0
	der-parser@9.0.0
	der@0.7.10
	der_derive@0.7.3
	deranged@0.5.8
	des@0.8.1
	digest@0.10.7
	dirs-sys@0.4.1
	dirs@5.0.1
	dispatch2@0.3.1
	displaydoc@0.2.5
	dlv-list@0.5.2
	doc-comment@0.3.3
	dunce@1.0.5
	either@1.17.0
	encoding_rs@0.8.35
	env_filter@0.1.3
	env_logger@0.11.8
	equator-macro@0.4.2
	equator@0.4.2
	equivalent@1.0.2
	errno@0.3.14
	fastrand@2.3.0
	faststr@0.2.34
	find-msvc-tools@0.1.2
	findshlibs@0.10.2
	fixedbitset@0.5.7
	flagset@0.4.7
	flatbuffers@25.9.23
	flate2@1.1.2
	fnv@1.0.7
	foldhash@0.1.5
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	form_urlencoded@1.2.2
	fs2@0.4.3
	fs_extra@1.3.0
	futures-channel@0.3.31
	futures-core@0.3.31
	futures-executor@0.3.31
	futures-io@0.3.31
	futures-macro@0.3.31
	futures-sink@0.3.31
	futures-task@0.3.31
	futures-util@0.3.31
	futures@0.3.31
	generic-array@0.14.7
	getrandom@0.2.16
	getrandom@0.3.3
	gimli@0.32.3
	glob@0.3.3
	h2@0.4.18
	half@2.6.0
	hashbrown@0.14.5
	hashbrown@0.15.5
	hashbrown@0.16.0
	hashbrown@0.17.1
	heck@0.4.1
	heck@0.5.0
	hermit-abi@0.5.2
	hex@0.4.3
	hmac@0.12.1
	html-escape@0.2.13
	http-body-util@0.1.3
	http-body@0.4.6
	http-body@1.0.1
	http@0.2.12
	http@1.3.1
	httparse@1.10.1
	httpdate@1.0.3
	hyper-rustls@0.27.7
	hyper-util@0.1.17
	hyper@1.7.0
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.64
	icu_collections@2.0.0
	icu_locale_core@2.0.0
	icu_normalizer@2.0.0
	icu_normalizer_data@2.0.0
	icu_properties@2.0.1
	icu_properties_data@2.0.1
	icu_provider@2.0.0
	idna@1.1.0
	idna_adapter@1.2.1
	indexmap@2.14.0
	infer@0.19.0
	inferno@0.11.21
	inout@0.1.4
	ipnet@2.11.0
	iri-string@0.7.8
	is-terminal@0.4.17
	is_terminal_polyfill@1.70.1
	itertools@0.10.5
	itertools@0.14.0
	itoa@1.0.18
	jiff-static@0.2.15
	jiff@0.2.15
	jni-macros@0.22.4
	jni-sys-macros@0.4.1
	jni-sys@0.4.1
	jni@0.22.4
	jobserver@0.1.34
	js-sys@0.3.81
	keyring@3.6.3
	lazy_static@1.5.0
	lexical-core@1.0.6
	lexical-parse-float@1.0.6
	lexical-parse-integer@1.0.6
	lexical-util@1.0.7
	lexical-write-float@1.0.6
	lexical-write-integer@1.0.6
	libbz2-rs-sys@0.2.2
	libc@0.2.176
	libloading@0.8.8
	libm@0.2.15
	libredox@0.1.10
	link-section@0.19.3
	linktime-proc-macro@0.2.3
	linux-keyutils@0.2.4
	linux-raw-sys@0.11.0
	litemap@0.8.0
	lock_api@0.4.14
	log@0.4.33
	lru@0.12.5
	matchers@0.2.0
	matchit@0.8.4
	md-5@0.10.6
	memchr@2.7.6
	memmap2@0.9.10
	mime@0.3.17
	minimal-lexical@0.2.1
	miniz_oxide@0.8.9
	mio@1.0.4
	multimap@0.10.1
	munge@0.4.7
	munge_macro@0.4.7
	ndk-context@0.1.1
	nix@0.26.4
	nix@0.30.1
	nom@7.1.3
	nu-ansi-term@0.50.1
	num-bigint@0.4.6
	num-complex@0.4.6
	num-conv@0.2.2
	num-format@0.4.4
	num-integer@0.1.46
	num-iter@0.1.45
	num-rational@0.4.2
	num-traits@0.2.19
	num@0.4.3
	num_cpus@1.17.0
	oauth2@5.0.0
	objc2-cloud-kit@0.3.2
	objc2-core-data@0.3.2
	objc2-core-foundation@0.3.2
	objc2-core-graphics@0.3.2
	objc2-core-image@0.3.2
	objc2-core-location@0.3.2
	objc2-core-text@0.3.2
	objc2-encode@4.1.0
	objc2-foundation@0.3.2
	objc2-io-surface@0.3.2
	objc2-quartz-core@0.3.2
	objc2-ui-kit@0.3.2
	objc2-user-notifications@0.3.2
	objc2@0.6.4
	object@0.37.3
	oid-registry@0.7.1
	once_cell@1.21.3
	once_cell_polyfill@1.70.1
	oorandom@11.1.5
	openssl-macros@0.1.1
	openssl-probe@0.1.6
	openssl-sys@0.9.109
	openssl@0.10.73
	opentelemetry-http@0.30.0
	opentelemetry-otlp@0.30.0
	opentelemetry-proto@0.30.0
	opentelemetry-semantic-conventions@0.30.0
	opentelemetry@0.30.0
	opentelemetry_sdk@0.30.0
	option-ext@0.2.0
	ordered-multimap@0.7.3
	os_info@3.14.0
	outref@0.5.2
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	pbkdf2@0.12.2
	pem-rfc7468@0.7.0
	pem@3.0.6
	percent-encoding@2.3.2
	petgraph@0.7.1
	pin-project-internal@1.1.10
	pin-project-lite@0.2.16
	pin-project@1.1.10
	pin-utils@0.1.0
	pkcs5@0.7.1
	pkcs8@0.10.2
	pkg-config@0.3.32
	plotters-backend@0.3.7
	plotters-svg@0.3.7
	plotters@0.3.7
	portable-atomic-util@0.2.4
	portable-atomic@1.11.1
	potential_utf@0.1.3
	powerfmt@0.2.0
	pprof@0.14.1
	ppv-lite86@0.2.21
	prettyplease@0.2.37
	proc-macro2@1.0.106
	prost-build@0.14.1
	prost-derive@0.12.6
	prost-derive@0.13.5
	prost-derive@0.14.1
	prost-types@0.14.1
	prost@0.12.6
	prost@0.13.5
	prost@0.14.1
	ptr_meta@0.3.1
	ptr_meta_derive@0.3.1
	pyo3-async-runtimes@0.29.0
	pyo3-build-config@0.29.0
	pyo3-ffi@0.29.0
	pyo3-macros-backend@0.29.0
	pyo3-macros@0.29.0
	pyo3@0.29.0
	quick-xml@0.26.0
	quote@1.0.45
	r-efi@5.3.0
	rancor@0.1.1
	rand@0.8.6
	rand@0.9.2
	rand_chacha@0.3.1
	rand_chacha@0.9.0
	rand_core@0.6.4
	rand_core@0.9.3
	rayon-core@1.13.0
	rayon@1.11.0
	rcgen@0.13.2
	redox_syscall@0.5.18
	redox_users@0.4.6
	ref-cast-impl@1.0.25
	ref-cast@1.0.25
	regex-automata@0.4.11
	regex-lite@0.1.7
	regex-syntax@0.8.6
	regex@1.11.3
	rend@0.5.3
	reqwest@0.12.23
	rgb@0.8.53
	ring@0.17.14
	rkyv@0.8.15
	rkyv_derive@0.8.15
	rust-ini@0.21.3
	rustc-demangle@0.1.27
	rustc-hash@2.1.1
	rustc_version@0.4.1
	rusticata-macros@4.1.0
	rustix@1.1.2
	rustls-native-certs@0.8.1
	rustls-pemfile@2.2.0
	rustls-pki-types@1.12.0
	rustls@0.23.32
	rustversion@1.0.22
	ryu@1.0.23
	salsa20@0.10.2
	same-file@1.0.6
	schannel@0.1.28
	scopeguard@1.2.0
	scrypt@0.11.0
	security-framework-sys@2.15.0
	security-framework@2.11.1
	security-framework@3.5.0
	semver@1.0.27
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.145
	serde_path_to_error@0.1.20
	serde_spanned@0.6.9
	serde_urlencoded@0.7.1
	sha1@0.10.6
	sha2@0.10.9
	sharded-slab@0.1.7
	shlex@1.3.0
	signal-hook-registry@1.4.6
	signature@2.2.0
	simd_cesu8@1.1.1
	simdutf8@0.1.5
	slab@0.4.11
	smallvec@1.15.1
	snafu-derive@0.7.5
	snafu-derive@0.8.9
	snafu@0.7.5
	snafu@0.8.9
	socket2@0.6.0
	sonic-number@0.1.2
	sonic-rs@0.5.8
	sonic-simd@0.1.4
	spin@0.10.0
	spki@0.7.3
	stable_deref_trait@1.2.0
	str_stack@0.1.0
	strsim@0.11.1
	subtle@2.6.1
	symbolic-common@12.17.3
	symbolic-demangle@12.17.3
	symlink@0.1.0
	syn@1.0.109
	syn@2.0.117
	sync_wrapper@1.0.2
	synstructure@0.13.2
	system-configuration-sys@0.6.0
	system-configuration@0.6.1
	target-lexicon@0.13.5
	temp-env@0.3.6
	tempfile@3.23.0
	test-case-core@3.3.1
	test-case-macros@3.3.1
	test-case@3.3.1
	thiserror-impl@1.0.69
	thiserror-impl@2.0.16
	thiserror@1.0.69
	thiserror@2.0.16
	thread_local@1.1.9
	time-core@0.1.9
	time-macros@0.2.32
	time@0.3.54
	tiny-keccak@2.0.2
	tinystr@0.8.1
	tinytemplate@1.2.1
	tinyvec@1.10.0
	tinyvec_macros@0.1.1
	tls_codec@0.4.2
	tls_codec_derive@0.4.2
	tokio-macros@2.6.1
	tokio-rustls@0.26.3
	tokio-stream@0.1.17
	tokio-util@0.7.18
	tokio@1.50.0
	toml@0.8.23
	toml_datetime@0.6.11
	toml_edit@0.22.27
	toml_write@0.1.2
	tonic@0.13.1
	tower-http@0.6.6
	tower-layer@0.3.3
	tower-service@0.3.3
	tower@0.5.2
	tracing-appender@0.2.5
	tracing-attributes@0.1.31
	tracing-core@0.1.36
	tracing-log@0.2.0
	tracing-opentelemetry@0.31.0
	tracing-subscriber@0.3.20
	tracing-test-macro@0.2.6
	tracing-test@0.2.6
	tracing@0.1.44
	try-lock@0.2.5
	typenum@1.20.1
	unicode-ident@1.0.19
	untrusted@0.7.1
	untrusted@0.9.0
	url@2.5.7
	urlencoding@2.1.3
	utf8-width@0.1.8
	utf8_iter@1.0.4
	utf8parse@0.2.2
	uuid@1.18.1
	valuable@0.1.1
	vcpkg@0.2.15
	version_check@0.9.5
	vsimd@0.8.0
	walkdir@2.5.0
	want@0.3.1
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.14.7+wasi-0.2.4
	wasip2@1.0.1+wasi-0.2.4
	wasm-bindgen-backend@0.2.104
	wasm-bindgen-futures@0.4.54
	wasm-bindgen-macro-support@0.2.104
	wasm-bindgen-macro@0.2.104
	wasm-bindgen-shared@0.2.104
	wasm-bindgen@0.2.104
	wasm-streams@0.4.2
	web-sys@0.3.81
	web-time@1.1.0
	webbrowser@1.2.1
	webpki-roots@1.0.10
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.11
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-core@0.62.1
	windows-implement@0.60.1
	windows-interface@0.59.2
	windows-link@0.1.3
	windows-link@0.2.0
	windows-registry@0.5.3
	windows-result@0.3.4
	windows-result@0.4.0
	windows-strings@0.4.2
	windows-strings@0.5.0
	windows-sys@0.48.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.1
	windows-targets@0.48.5
	windows-targets@0.52.6
	windows-targets@0.53.4
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.0
	windows_aarch64_msvc@0.48.5
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.0
	windows_i686_gnu@0.48.5
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.0
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.0
	windows_i686_msvc@0.48.5
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.0
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.0
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.0
	windows_x86_64_msvc@0.48.5
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.0
	winnow@0.7.13
	wiremock@0.6.5
	wit-bindgen@0.46.0
	writeable@0.6.1
	x509-cert@0.2.5
	x509-parser@0.16.0
	xmlparser@0.13.6
	yasna@0.5.2
	yoke-derive@0.8.0
	yoke@0.8.0
	zerocopy-derive@0.8.27
	zerocopy@0.8.27
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zeroize@1.8.1
	zeroize_derive@1.4.2
	zerotrie@0.2.2
	zerovec-derive@0.11.1
	zerovec@0.11.4
	zmij@1.0.21
	zstd-safe@7.2.4
	zstd-sys@2.0.16+zstd.1.5.7
	zstd@0.13.3
"

inherit cargo distutils-r1 flag-o-matic pypi rust-toolchain toolchain-funcs

DESCRIPTION="Snowflake database connector for Python"
HOMEPAGE="https://pypi.org/project/snowflake-connector-python/"

# The sdist leaves out the Python tests.
SRC_URI+="
	${CARGO_CRATE_URIS}
	test? (
		https://github.com/Tatsh/tatsh-overlay/releases/download/__distfiles__/${P}-tests.tar.xz
	)
"

LICENSE="Apache-2.0"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD CC0-1.0 CDDL
	CDLA-Permissive-2.0 ISC MIT MPL-2.0 openssl Unicode-3.0 ZLIB BZIP2
"
SLOT="0"
KEYWORDS="~amd64"
IUSE="debug pandas"

RDEPEND="
	>=dev-python/cryptography-46.0.5[${PYTHON_USEDEP}]
	>=dev-python/protobuf-6.32.1[${PYTHON_USEDEP}]
	<dev-python/protobuf-7[${PYTHON_USEDEP}]
	dev-python/pytz[${PYTHON_USEDEP}]
	>=dev-python/tomlkit-0.13[${PYTHON_USEDEP}]
	pandas? (
		>=dev-python/pandas-2.1.2[${PYTHON_USEDEP}]
		>=dev-python/pyarrow-14.0.1[${PYTHON_USEDEP}]
	)
"
BDEPEND="
	dev-libs/protobuf
	>=dev-python/cython-3.1[${PYTHON_USEDEP}]
	dev-python/setuptools[${PYTHON_USEDEP}]
	test? (
		dev-python/mypy[${PYTHON_USEDEP}]
		dev-python/numpy[${PYTHON_USEDEP}]
		dev-python/requests[${PYTHON_USEDEP}]
		dev-python/tzdata[${PYTHON_USEDEP}]
	)
"

python_prepare_all() {
	# Protobuf modules are already generated in the sdist.
	sed -i 's/, "mypy-protobuf~=5.0"//' pyproject.toml || die
	if use test; then
		# The sdist ships only tests/README.md.
		rm -r tests || die
		mv "${WORKDIR}/${P}-tests/tests" . || die
	fi
	distutils-r1_python_prepare_all
}

python_compile() {
	# The sdist ships generated protobuf modules; avoid rebuilding type stubs.
	export SKIP_PROTO_GENERATION=true
	export PROTOC="${BROOT}/usr/bin/protoc"
	export CORE_CARGO_TARGET_DIR
	CORE_CARGO_TARGET_DIR="$(cargo_target_dir)"
	filter-lto
	tc-export AR CC CXX PKG_CONFIG
	local triple
	triple="$(rust_abi)" || die
	triple=${triple//-/_}
	local -x RUSTFLAGS
	RUSTFLAGS="$(cargo_env printenv "CARGO_TARGET_${triple^^}_RUSTFLAGS")" || die
	distutils-r1_python_compile
}

src_test() {
	local EPYTEST_IGNORE=(
		# Need a Snowflake account or a WireMock server.
		tests/e2e
		tests/integ
		# Builds and installs the sdist.
		tests/packaging
	)
	# Upstream addopts load a junit plugin from outside the sdist.
	local EPYTEST_FLAGS="-o addopts="
	# Keep upstream's marker filter; pytest shell-splits this variable.
	local -x PYTEST_ADDOPTS="-m 'not flaky and not requires_no_mfa'"
	distutils-r1_src_test
}

EPYTEST_PLUGINS=()
# conftest.py implements an xdist hook.
EPYTEST_XDIST=1
distutils_enable_tests pytest