%global commit      b1c17d88408698c9a141b8989d0d77303588500b
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%global shortname uranium-lulzbot

Name:		python-%{shortname}
Version:	20231219
Release:	%autorelease
Summary:	A Python framework for building desktop applications (Lulzbot fork)
# UM/SortedList.py is Apache-2.0.
# Everything else is AGPL-3.0-or-later.
License:	AGPL-3.0-or-later and Apache-2.0
URL:		https://gitlab.com/lulzbot3d
Source0:	https://gitlab.com/lulzbot3d/cura-le/uranium/-/archive/%{commit}/uranium-%{commit}.tar.bz2

Conflicts:      python-uranium

BuildRequires:	python3-devel
BuildRequires:	/usr/bin/doxygen
BuildRequires:	/usr/bin/msgmerge
BuildRequires:	cmake
BuildRequires:	git

# Requirements for tests.
BuildRequires:	python3-arcus-lulzbot
BuildRequires:	python3-numpy
BuildRequires:	python3-scipy
BuildRequires:	python3-qt5
BuildRequires:	python3-pytest

BuildArch:	noarch

# There are Python plugins in /usr/lib/uranium, which we need to byte-compile
# with Python 3.
%global __python %{__python3}

%description
Uranium is a Python framework for building 3D printing related applications.

%package -n python3-%{shortname}
Summary:	%{summary}
%{?python_provide:%python_provide python3-%{shortname}}
Requires:	python3-arcus-lulzbot
Requires:	python3-cryptography
Requires:	python3-numpy
Requires:	python3-pyclipper
Requires:	python3-qt5
Requires:	python3-scipy

Recommends:	python3-numpy-stl

%description -n python3-%{shortname}
Uranium is a Python framework for building 3D printing related applications.
This is the Lulzbot fork.

%package doc
Summary: Documentation for %{name} package

%description doc
Documentation for Uranium, a Python framework for building 3D printing
related applications. This is for the Lulzbot fork.

%prep
%setup -q -n uranium-%{commit}
%autopatch -p1

# Upstream installs to lib/python3/dist-packages, but we want to install to
# %%{python3_sitelib}.
sed -i 's|lib/python${PYTHON_VERSION_MAJOR}/dist-packages|%(echo %{python3_sitelib} | sed -e s@%{_prefix}/@@)|g' CMakeLists.txt

%build
%cmake
%cmake_build
%cmake_build -- doc

%install
%cmake_install

mv %{buildroot}%{_datadir}/cmake* %{buildroot}%{_datadir}/cmake

# Sanitize the location of locale files.
pushd %{buildroot}%{_datadir}
mv uranium/resources/i18n locale
ln -s ../../locale uranium/resources/i18n
rm locale/uranium.pot
rm locale/*/uranium.po
rm uranium/resources/bundled_packages/uranium.json
for i in locale/*/LC_MESSAGES; do
	pushd $i
	mv uranium.mo %{shortname}.mo
	popd
done
popd

# Bytecompile the plugins.
%py_byte_compile %{__python3} %{buildroot}%{_prefix}/lib/%{shortname}

%find_lang %{shortname}

%check
# Test code tries to load cura, which would cause a dependency loop.
%if 0
pip3 freeze

# The failing tests are reported at:
# https://github.com/Ultimaker/Uranium/issues/225
# Skipping.
%{__python3} -m pytest -v -k "not getMimeTypeForFile"
%endif

%files -n python3-%{shortname} -f %{shortname}.lang
%license LICENSE
%doc README.md
%dir %{python3_sitelib}/UM
%{python3_sitelib}/UM
%{_datadir}/uranium
# Own the dir not to depend on cmake:
%{_datadir}/cmake
%{_libdir}/uranium
%{_datadir}/uranium/resources/shaders/*

%files doc
%license LICENSE
%doc html

%changelog
%autochangelog