Blob Blame History Raw
# Set python3 as default on fedora
%if 0%{?fedora}
%global with_python3 1
%endif

# Set python2 related macros
%if 0%{?rhel} && 0%{?rhel} <= 6
%{!?__python2:  %global __python2 /usr/bin/python2}
%{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%endif

%global pkgname line_profiler

Name:           python-%{pkgname}
Version:        2.0
Release:        1%{?dist}
Summary:        Line-by-line profiler for python

License:        BSD and Python
URL:            https://github.com/rkern/%{pkgname}
Source0:        https://github.com/rkern/line_profiler/archive/%{version}.tar.gz#/%{pkgname}/%{pkgname}-%{version}.tar.gz

BuildRequires:  python2-devel
BuildRequires:  python-setuptools
BuildRequires:  Cython
Requires:       python2
Requires:       python-ipython
Provides:       python2-%{pkgname} = %{version}-%{release}

%description
line_profiler is a module for doing line-by-line profiling of functions. 
kernprof is a convenient script for running either line_profiler or 
the Python standard library's cProfile or profile modules, 
depending on what is available.

%if 0%{?with_python3}
%package -n     python3-%{pkgname}
Summary:        Line-by-line profiler for python3
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-Cython
Requires:       python3
Requires:       python3-ipython
%description -n python3-%{pkgname}
line_profiler is a module for doing line-by-line profiling of functions. 
kernprof is a convenient script for running either line_profiler or 
the Python standard library's cProfile or profile modules, 
depending on what is available.
%endif

%prep
%setup -q -c

%if 0%{?with_python3}
# Prepare python3 directory. Do not use py3dir as it is unclean.
cp -a %{pkgname}-%{version} python3
find python3 -name '*.py' | xargs sed -i '/^#!\/usr\/bin\/env\ python/d'
%endif

find %{pkgname}-%{version} -name '*.py' | xargs sed -i '/^#!\/usr\/bin\/env\ python/d'
rm -rf *.egg-info

%build
# Build with python3
%if 0%{?with_python3}
pushd python3
CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build
popd
%endif

# Build with python2
pushd %{pkgname}-%{version}
CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build
popd

%install
# Install with python3
%if 0%{?with_python3}
pushd python3
%{__python3} setup.py install --skip-build --root=%{buildroot}
mv %{buildroot}%{_bindir}/kernprof %{buildroot}%{_bindir}/kernprof-%{python3_version}
popd
%endif

# Install with python2
pushd %{pkgname}-%{version}
%{__python2} setup.py install --skip-build --root=%{buildroot}
mv %{buildroot}%{_bindir}/kernprof %{buildroot}%{_bindir}/kernprof-%{python2_version}
ln -s %{_bindir}/kernprof-%{python2_version} %{buildroot}%{_bindir}/kernprof 
popd

%check
# Run tests with python3
%if 0%{?with_python3}
pushd python3
PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} -m unittest discover -s tests -v
popd
%endif

# Run tests with python2
pushd %{pkgname}-%{version}
PYTHONPATH=%{buildroot}%{python2_sitearch} %{__python2} -m unittest discover -s tests -v
popd

%files
%doc %{pkgname}-%{version}/README.rst
# BSD License
%license %{pkgname}-%{version}/LICENSE.txt
# Python License
%license %{pkgname}-%{version}/LICENSE_Python.txt
%{python2_sitearch}/*
%{_bindir}/kernprof
%{_bindir}/kernprof-%{python2_version}

%if 0%{?with_python3}
%files -n python3-%{pkgname}
%doc %{pkgname}-%{version}/README.rst
# BSD License
%license %{pkgname}-%{version}/LICENSE.txt
# Python License
%license %{pkgname}-%{version}/LICENSE_Python.txt
%exclude %dir %{python3_sitearch}/__pycache__
%{python3_sitearch}/*
%{_bindir}/kernprof-%{python3_version}
%endif

%changelog
* Mon Oct 31 2016 Jackson <jacksonisaac2008@gmail.com> - 2.0-1
- Update line_profiler to v2.0

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0-9
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 1.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Tue Nov 10 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0-7
- Rebuilt for https://fedoraproject.org/wiki/Changes/python3.5

* Sat Jul 25 2015 Jackson Isaac <jacksonisaac2008@gmail.com> - 1.0-6
- Add Python License. Exclude __pycache__ in py3 file listing.

* Thu Jul 23 2015 Jackson Isaac <jacksonisaac2008@gmail.com> - 1.0-5
- Remove python2_sitelib definition. Remove ghost from files. 
- Add PYTHONPATH for tests. Run tests for files in tests/

* Wed Jul 22 2015 Jackson Isaac <jacksonisaac2008@gmail.com> - 1.0-4
- Rename kernprof binary instead of symlinking.

* Mon Jul 20 2015 Jackson Isaac <jacksonisaac2008@gmail.com> - 1.0-3
- Do not use py3dir as it is unclean. Use chmod instead of attr.

* Wed Jul 15 2015 Jackson Isaac <jacksonisaac2008@gmail.com> - 1.0-2
- Add compiler flags in build. Create py2 and py3 specific packages.
- Add kernprof script in buildroot for both py2 and py3 versions.

* Wed Jul  8 2015 Jackson Isaac - 1.0-1
- Initial version of line_profiler package