Blob Blame History Raw
%if 0%{?fedora} || 0%{?rhel} >= 8
%bcond_without python3
%else  # 0#{?fedora} || 0#{?rhel} >= 8
%bcond_with python3
%endif # 0#{?fedora} || 0#{?rhel} >= 8

%global pypi_name evic
%global patch_url https://patch-diff.githubusercontent.com/raw/Ban3/python-evic/pull

# %%{_udevrulesdir} is not defined during srpm-build.  :/
%{!?_udevrulesdir:%global _udevrulesdir %{_usr}/lib/udev/rules.d}

# No tagged releases.  :/
%global commit f916017f987cac6eb90bf25e521455d17d4e3440
%{?commit:%global shortcommit %(c="%{commit}"; /bin/echo ${c:0:7})}
%{?commit:%global git_date 20160814}
%{?commit:%global git_rel .git%{git_date}.%{shortcommit}}
%{?commit:%global git_ver -git%{git_date}-%{shortcommit}}


Name:		python-%{pypi_name}
Version:	0.1
Release:	0.4%{?git_rel}%{?dist}
Summary:	USB programmer for devices based on the Joyetech Evic VTC Mini

License:	GPLv3+
URL:		https://github.com/Ban3/python-%{pypi_name}
Source0:	%{url}/archive/%{commit}.tar.gz#/%{name}-%{version}%{?git_ver}.tar.gz

# Patches from upstream.
Patch0:		%{patch_url}/23.patch#/%{name}-0.1-new_commands.patch
Patch1:		%{patch_url}/25.patch#/%{name}-0.1-wismec_reuleaux_rx75.patch
Patch2:		%{patch_url}/26.patch#/%{name}-0.1-evic_vtc_dual.patch

BuildArch:	noarch

BuildRequires:	help2man
BuildRequires:	systemd

%description
%{summary}.

%package -n python2-%{pypi_name}
Summary:	%{summary}

BuildRequires:	python-click
BuildRequires:	python2-binstruct
BuildRequires:	python2-bitarray
BuildRequires:	python2-bitstruct
BuildRequires:	python2-devel
BuildRequires:	python2-hidapi
BuildRequires:	python2-pillow
BuildRequires:	python2-setuptools
BuildRequires:	python2-pytest
BuildRequires:	python2-pytest-runner

Requires:	%{_udevrulesdir}
Requires:	python-click
Requires:	python2-binstruct
Requires:	python2-bitarray
Requires:	python2-bitstruct
Requires:	python2-hidapi
Requires:	python2-pillow

%{?python_provide:%python_provide python2-%{pypi_name}}

%description -n python2-%{pypi_name}
%{summary}.


%if %{with python3}
%package -n python3-%{pypi_name}
Summary:	%{summary}

BuildRequires:	python3-binstruct
BuildRequires:	python3-bitarray
BuildRequires:	python3-bitstruct
BuildRequires:	python3-click
BuildRequires:	python3-devel
BuildRequires:	python3-hidapi
BuildRequires:	python3-pillow
BuildRequires:	python3-setuptools
BuildRequires:	python3-pytest
BuildRequires:	python3-pytest-runner

Requires:	%{_udevrulesdir}
Requires:	python3-binstruct
Requires:	python3-bitarray
Requires:	python3-bitstruct
Requires:	python3-click
Requires:	python3-hidapi
Requires:	python3-pillow

%{?python_provide:%python_provide python3-%{pypi_name}}

%description -n python3-%{pypi_name}
%{summary}.
%endif # with python3


%prep
%autosetup -p 1 %{?commit:-n %{name}-%{commit}}


%build
%py2_build
%if %{with python3}
%py3_build
%endif # with python3


%install
%py2_install

# Rename files installed in %%{_bindir}.
files=""
for f in %{buildroot}%{_bindir}/* ; do
	/bin/ln ${f} ${f}-%{python2_version}
	files="${files##' '} ${f}"
done

%if %{with python3}
# Remove left-overs from %%py2_install.
%{__rm} -fr ${files}

%py3_install

# Rename files installed in %%{_bindir}.
for f in %{buildroot}%{_bindir}/* ; do
	/bin/ln ${f} ${f}-%{python3_version}
done

# Remove clutter in %%{_bindir}.
%{__rm} -f %{buildroot}%{_bindir}/*-%{python2_version}-%{python3_version}

# Needed for help2man.
PYTHONPATH="%{buildroot}/%{python3_sitelib}:${PYTHONPATH}"
%endif # with python3

# Needed for help2man.
PYTHONPATH="%{buildroot}/%{python2_sitelib}:${PYTHONPATH}"
export PYTHONPATH="${PYTHONPATH%%':'}"

# Generate man-pages.
%{__mkdir} -p %{buildroot}%{_mandir}/man1				\
	%{buildroot}%{_udevrulesdir}
for f in %{buildroot}%{_bindir}/* ; do
	file="$(%{_bindir}/basename ${f})"
	LC_ALL=en_US.utf-8 LANG=en_US.utf-8 %{_bindir}/help2man		\
		-o "%{buildroot}%{_mandir}/man1/${file}.1" -s 1 -N	\
		--version-string="%{version}" --no-discard-stderr ${f}
done

# Install udev-rules.
%{__mv} %{buildroot}%{_usr}/udev/*					\
	%{buildroot}%{_udevrulesdir}
%{__rm} -fr %{buildroot}%{_usr}/udev

%if %{with python3}
# Remove clutter from man-page generation.
%{__rm} -fv %{buildroot}%{python3_sitelib}/%{pypi_name}/*.py{c,o}
%{_bindir}/find %{buildroot}%{python2_sitelib}/%{pypi_name}		\
	-name '__pycache__' -print0 | %{_bindir}/xargs -0 %{__rm} -rfv
%endif # with python3


%check
%{__python2} setup.py test
%if %{with python3}
LC_ALL=en_US.utf-8 LANG=en_US.utf-8 %{__python3} setup.py test
%endif


%files -n python2-%{pypi_name}
%license LICENSE
%doc README.rst
%if %{with python3}
%{_bindir}/*-%{python2_version}
%{_mandir}/man1/*-%{python2_version}.1.*
%else  # with python3
%{_bindir}/*
%{_mandir}/man1/*.1.*
%endif # with python3
%{_udevrulesdir}/*.rules
%{python2_sitelib}/%{pypi_name}
%{python2_sitelib}/%{pypi_name}-%{version}-py%{python2_version}.egg-info

%if %{with python3}
%files -n python3-%{pypi_name}
%license LICENSE
%doc README.rst
%exclude %{_bindir}/*-%{python2_version}
%exclude %{_mandir}/man1/*-%{python2_version}.1.*
%{_bindir}/*
%{_mandir}/man1/*.1.*
%{_udevrulesdir}/*.rules
%{python3_sitelib}/%{pypi_name}
%{python3_sitelib}/%{pypi_name}-%{version}-py%{python3_version}.egg-info
%endif # with python3


%changelog
* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.4.git20160814.f916017
- %%{_udevrulesdir} is not defined during srpm-build

* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.3.git20160814.f916017
- Initial import (rhbz 1387834)

* Mon Oct 24 2016 Björn Esser <fedora@besser82.io> - 0.1-0.2.git20160814.f916017
- Changes suggested during review (rhbz 1387834)
- Add BuildRequires: systemd
- Use %%{_udevrulesdir}
- Don't mark udev-rules as %%config(noreplace)

* Fri Oct 21 2016 Björn Esser <fedora@besser82.io> - 0.1-0.1.git20160814.f916017
- Initial package (rhbz 1387834)