# Contributor: lauren n. liberda <lauren@selfisekai.rocks>
# Maintainer:
pkgname=octoprint
pkgver=1.10.3
pkgrel=0
pkgdesc="Snappy web interface for your 3D printer"
url="https://octoprint.org/"
arch="noarch"
license="AGPL-3.0-only"
depends="
	py3-argon2-cffi
	py3-babel
	py3-blinker
	py3-cachelib
	py3-class-doc
	py3-click
	py3-colorlog
	py3-emoji
	py3-feedparser
	py3-filetype
	py3-flask
	py3-flask-assets
	py3-flask-babel
	py3-flask-limiter
	py3-flask-login
	py3-frozendict
	py3-future
	py3-markdown
	py3-netaddr
	py3-netifaces
	py3-passlib
	py3-pathvalidate
	py3-pkginfo
	py3-psutil
	py3-pydantic
	py3-pylru
	py3-pyserial
	py3-regex
	py3-requests
	py3-sarge
	py3-semantic-version
	py3-sentry-sdk
	py3-setuptools
	py3-tornado
	py3-unidecode
	py3-watchdog
	py3-websocket-client
	py3-werkzeug
	py3-wrapt
	py3-yaml
	py3-zeroconf
	py3-zipstream-ng
"
makedepends="
	py3-gpep517
	py3-wheel
	"
checkdepends="
	py3-ddt
	py3-pytest
	"
pkgusers="octoprint"
pkggroups="octoprint"
install="$pkgname.pre-install"
subpackages="
	$pkgname-openrc
	$pkgname-pyc
	"
source="
	https://github.com/OctoPrint/OctoPrint/releases/download/$pkgver/OctoPrint-$pkgver.source.tar.gz

	config.yaml
	octoprint.initd

	fix-tests.patch
	netaddr-0.10.patch
	pydantic-2.0.patch
	"
builddir="$srcdir/OctoPrint-$pkgver"

# secfixes:
#   1.10.3-r0:
#     - CVE-2024-49377
#     - CVE-2024-51493

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages testenv
	testenv/bin/python3 -m installer .dist/*.whl
	testenv/bin/python3 -m pytest -k 'not pip'
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	install -Dm640 -o octoprint -g octoprint "$srcdir"/config.yaml "$pkgdir"/etc/octoprint/config.yaml
	install -Dm755 "$srcdir"/octoprint.initd "$pkgdir"/etc/init.d/octoprint
	install -d -o octoprint -g octoprint "$pkgdir"/var/log/octoprint/ "$pkgdir"/var/lib/octoprint/
}

sha512sums="
d11e0e4be97c0b5ec87e7b3388d3fc13eee951e85041774a9d616e365869fdbf5b49e4b76fd0afa9c7251b034b87cc88dafc66ef04d6f71bb431203df3a372c4  OctoPrint-1.10.3.source.tar.gz
b56a37d1225d37caff1288b9c943ee86ed1f36653bbb311c835031e53e5f68e95be3ad9b53d333aad65508ba2a3ba786f80601bd74fef8efb1c3364a8fd85010  config.yaml
3edd9971cc59fb66126f063ecac50a77792c5a3f5b718e03b7cbff74ff9f842c7784e7de2a56fb2e847a2bcb8e1c4fcfc52f8d236cdf3ecd511b230eea001162  octoprint.initd
d678b87aaee4529b4d96f496862e5bec86df98491330328848ac06fec8d1f4571cfac995b2e9de26dcd2efc43b9dc24578d7f50cae1893fefc76470aee074f14  fix-tests.patch
f99c752dccdee4821a88ac6e7ea98ac906002d734d2672bbd513b30d596b0c54b699071679581cdc46bfcd0eb98d6d032243a6d940f64620a69623a65db229bf  netaddr-0.10.patch
ed0bebc3632519b0adab58f6ef4666e0192ab72021f2c127146eec9c566551f04c49f05ace5a4056177f21605064146ac6259a88db15faaf88853fd3750abe88  pydantic-2.0.patch
"
