Blob Blame History Raw
%global  checkout   d5ab9a0544cd2b15b0e8ae4f0b143b9047d1a54b
%global  date       20150919

%if 0%{?fedora}
%global with_python3 1
%global python3_pkgversion 3

## Make python?_shortver macros
%{!?python2_shortver: %global python2_shortver %(%{__python2} -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')}
%{!?python3_shortver: %global python3_shortver %(%{__python3} -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')}
%endif

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

%if 0%{?rhel} && 0%{?rhel} > 6
%global with_python3 0
%{!?python2_shortver: %global python2_shortver %(%{__python2} -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')}
%{!?python3_shortver: %global python3_shortver %(%{__python3} -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')}
%endif

Name: preprocess
Summary: A portable multi-language file Python2 preprocessor
Version: 1.2.2
Release: 6.%{date}git%(echo %{checkout} | cut -c-6)%{?dist}
License: MIT
Group: Applications/Engineering
URL: https://github.com/hplgit/preprocess
Source0: https://github.com/hplgit/preprocess/archive/%{checkout}.zip#/preprocess-%{checkout}.zip
BuildArch: noarch

BuildRequires: python2-devel, future

%if 0%{?rhel}
BuildRequires:  python-setuptools
%endif

%description
There are millions of templating systems out there
(most of them developed for the web).
This isn't one of those, though it does share some basics:
a markup syntax for templates that are processed to give resultant text output.
The main difference with preprocess.py is that its syntax is hidden in comments
(whatever the syntax for comments may be in the target file type)
so that the file can still have valid syntax.
A comparison with the C preprocessor is more apt.

preprocess.py is targeted at build systems that deal with many types of files.
Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript,
CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#.
Preprocess is usable both as a command line app and as a Python module.

%package -n python2-%{name}
Summary: A portable multi-language file Python2 preprocessor
%{?python_provide:%python_provide python2-%{name}}
Provides:  preprocess = 0:%{version}-%{release}
Obsoletes: preprocess < 0:1.2.2-6
%description -n python2-%{name}
There are millions of templating systems out there
(most of them developed for the web).
This isn't one of those, though it does share some basics:
a markup syntax for templates that are processed to give resultant text output.
The main difference with preprocess.py is that its syntax is hidden in comments
(whatever the syntax for comments may be in the target file type)
so that the file can still have valid syntax.
A comparison with the C preprocessor is more apt.

preprocess.py is targeted at build systems that deal with many types of files.
Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript,
CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#.
Preprocess is usable both as a command line app and as a Python module.

%if 0%{?with_python3}
%package -n python3-%{name}
Summary: A portable multi-language file Python3 preprocessor
BuildRequires: python3-devel, python3-future
%{?python_provide:%python_provide python3-%{name}}
%description -n python3-%{name}
There are millions of templating systems out there
(most of them developed for the web).
This isn't one of those, though it does share some basics:
a markup syntax for templates that are processed to give resultant text output.
The main difference with preprocess.py is that its syntax is hidden in comments
(whatever the syntax for comments may be in the target file type)
so that the file can still have valid syntax.
A comparison with the C preprocessor is more apt.

preprocess.py is targeted at build systems that deal with many types of files.
Languages for which it works include: C++, Python, Perl, Tcl, XML, JavaScript,
CSS, IDL, TeX, Fortran, PHP, Java, Shell scripts (Bash, CSH, etc.) and C#.
Preprocess is usable both as a command line app and as a Python module.
%endif # with_python3

%prep
%setup -qc

mv preprocess-%{checkout} python2
pushd python2
find . -name '*.py' | xargs sed -i '1s|^#!/usr/bin/env python|#!%{__python2}|'
popd

%if 0%{?with_python3}
cp -a python2 python3
find python3 -name '*.py' | xargs sed -i '1s|^#!/usr/bin/env python|#!%{__python3}|'
%endif # with_python3

%build
%if 0%{?with_python3}
pushd python3
CFLAGS="%{optflags}" %{__python3} setup.py build --executable="%{__python3} -s"
popd
%endif # with_python3

pushd python2
CFLAGS="%{optflags}" %{__python2} setup.py build --executable="%{__python2} -s"
popd

%install
%if 0%{?with_python3}
pushd python3
CFLAGS="%{optflags}" %{__python3} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
mv $RPM_BUILD_ROOT%{_bindir}/preprocess $RPM_BUILD_ROOT%{_bindir}/python%{python3_version}-preprocess

for i in preprocess-3 preprocess-%{?python3_shortver}; do
  touch -r $RPM_BUILD_ROOT%{_bindir}/python%{python3_version}-preprocess $i
  install -p $i $RPM_BUILD_ROOT%{_bindir}
  ln -sf %{_bindir}/python%{python3_version}-preprocess $RPM_BUILD_ROOT%{_bindir}/$i
done
popd

##Fix non-executable script errors
find $RPM_BUILD_ROOT%{python3_sitelib} -name '*.py' | xargs chmod a+x
%endif

pushd python2
CFLAGS="%{optflags}" %{__python2} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
mv $RPM_BUILD_ROOT%{_bindir}/preprocess $RPM_BUILD_ROOT%{_bindir}/python%{python2_version}-preprocess

for i in preprocess preprocess-2 preprocess-%{python2_version}; do
  touch -r $RPM_BUILD_ROOT%{_bindir}/python%{python2_version}-preprocess $i
  install -p $i $RPM_BUILD_ROOT%{_bindir}
  ln -sf %{_bindir}/python%{python2_version}-preprocess $RPM_BUILD_ROOT%{_bindir}/$i
done
popd

##Fix non-executable script errors
find $RPM_BUILD_ROOT%{python2_sitelib} -name '*.py' | xargs chmod a+x

%check
%if 0%{?with_python3}
pushd python3/test
find . -name '*.pyc' -delete
%{__python3} test.py test python cpln -v
popd
%endif

pushd python2
find . -name '*.pyc' -delete
cd test
%{__python2} test.py test python cpln -v
popd

%files -n python2-%{name}
%{!?_licensedir:%global license %doc}
%doc python2/README.md python2/CONTRIBUTORS.txt python2/BUGS.txt python2/TODO.txt
%license python2/LICENSE.txt
%{_bindir}/preprocess
%{_bindir}/preprocess-2
%{_bindir}/preprocess-%{python2_version}
%{_bindir}/python%{python2_version}-preprocess
%{python2_sitelib}/preprocess.py*
%{python2_sitelib}/*.egg-info

%if 0%{?with_python3}
%files -n python3-%{name}
%{!?_licensedir:%global license %doc}
%doc python3/README.md python3/CONTRIBUTORS.txt python3/BUGS.txt python3/TODO.txt
%license python3/LICENSE.txt
%{_bindir}/preprocess-3
%{_bindir}/preprocess-%{?python3_shortver}
%{_bindir}/python%{python3_version}-preprocess
%{python3_sitelib}/preprocess.py*
%{python3_sitelib}/__pycache__/*.py*
%{python3_sitelib}/*.egg-info
%endif

%changelog
* Fri Jan 29 2016 Antonio Trande <sagitterATfedoraproject.org> - 1.2.2-6.20150919gitd5ab9a
- Renamed Python2 package

* Thu Dec 10 2015 Antonio Trande <sagitterATfedoraproject.org> - 1.2.2-5.20150919gitd5ab9a
- SPEC file adapted to recent guidelines for Python

* Sun Nov 15 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.2-4.20150919gitd5ab9a
- Rebuild again for Python3.5

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

* Tue Oct 06 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.2-2.20150919gitd5ab9a
- Added python-setuptools as BR on EPEL

* Tue Sep 29 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.2-1.20150919gitd5ab9a
- Update to 1.2.2

* Thu Sep 24 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.1-3.20150914gitb23422
- Added python_provide macro

* Tue Sep 15 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.1-2.20150914gitb23422
- Fixed 'non-executable script' errors

* Mon Sep 14 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2.1-1.20150914gitb23422
- Update to 1.2.1 (commit #b234225fff4e79a66bdd8e2341ac9d67be1b3066)
- Some cleanups

* Tue Jul 28 2015 Antonio Trande <sagitter@fedoraproject.org> 1.2-1.20150629git30078c
- Initial build