Blob Blame History Raw
# This module works with Python 2 and 3
%if 0%{?fedora} || 0%{?rhel} > 6
%global with_python3 1
%endif

Name:       pygrib
Version:    2.0.2
Release:    5%{?dist}
Summary:    Python module for reading and writing GRIB (editions 1 and 2) files

License:    MIT
Group:      Applications/Engineering
URL:        https://github.com/jswhit/pygrib
Source0:    https://files.pythonhosted.org/packages/source/p/pygrib/%{name}-%{version}.tar.gz

# Adapt setup.py to not use packaged g2clib source code
Patch0: %{name}-%{version}-2-build.patch

BuildRequires: python2-devel
BuildRequires: grib_api-devel
BuildRequires: g2clib-static
BuildRequires: numpy
BuildRequires: Cython
BuildRequires: pyproj
BuildRequires: openjpeg-devel
%if 0%{?with_python3}
BuildRequires:  python3-devel
BuildRequires:  python3-numpy
BuildRequires:  python3-pyproj
%endif # if with_python3

# a note on the build requirements:
# pygrib installation instructions mention these requirements:
#    $GRIBAPI_DIR, $JASPER_DIR, $OPENJPEG_DIR, $PNG_DIR and $ZLIB_DIR 
# (see https://jswhit.github.io/pygrib/docs/index.html)
#
# grib_api-devel is mentioned above.
# g2clib-devel is included in the pygrib sources, but has been removed
# to comply to Fedora policy, so has been added as requirement
# jasper-devel is BR by grib_api-devel
# libpng-devel and jasper-devel are BR for g2clib-devel
# jasper-devel BRs libjpeg-devel and others
# libpng-devel BRs zlib-devel
# However, pygrib does not need header files from these packages
# during the build, therefore no explicit BuildRequires is needed
# for jasper, openjpeg, png or zlib
#
# in addition pyproj has been added as BR since it is needed
# to run the test.py script in the check stage 

# this requirement is not automatically resolved and needs to be
# inserted manually (see bug #996834)
Requires:  grib_api

Requires:  pyproj

# specifying this is not needed. rpmbuild figures it out without help
# Requires: jasper-libs openjpeg-libs libpng zlib

# avoid providing the private libs:
%{?filter_setup:
%filter_provides_in %{python2_sitearch}.*\.so$
%filter_setup
}

%if 0%{?with_python3}
%{?filter_setup:
%filter_provides_in %{python3_sitearch}.*\.so$
%filter_setup
}
%endif # if with_python3

%description
Cython wrapper to provide python interfaces to the grib library.

GRIB is the the World Meteorological Organization (WMO) standard for
distributing gridded data. This module contains python interfaces for reading
and writing GRIB data using the ECMWF GRIB API C library, and the NCEP GRIB2 
C library, as well as command-line utilities for listing and re-packing GRIB 
files. 

# provide python2.pygrib as well
%python_provide python2-%{name}

# this should evaluate to Provides: python2-pygrib
%{?python_provide:%python_provide python-%{name}}

%if 0%{?with_python3}
%package -n python3-%{name}
Summary:    Python3 module for reading and writing GRIB (editions 1 and 2) files

# ensure python provides are provided when python3 becomes the default runtime
%{?python_provide:%python_provide python3-%{name}}
 
# it seems this requires must be specified before the description section
# or it will be ignored ...
Requires:  python3-pyproj

%description -n python3-%{name}
Cython wrapper to provide python3 interfaces to the grib library.

GRIB is the the World Meteorological Organization (WMO) standard for
distributing gridded data. This module contains python interfaces for reading
and writing GRIB data using the ECMWF GRIB API C library, and the NCEP GRIB2 
C library, as well as command-line utilities for listing and re-packing GRIB 
files.

%endif # if with_python3

%prep
%setup -q
%patch0 -p0 -b .orig

# Delete g2clib sources
rm -rf g2clib_src

# Delete precooked cython *.c files
rm  g2clib.c
rm  pygrib.c
rm  redtoreg.c

# copy sources to py3dir to not interfere with py2 build
# and if needed modify #! lines of *.py files
%if 0%{?with_python3}
rm -rf %{py3dir}
cp -a . %{py3dir}
find %{py3dir} -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python3}|'
%endif # if with_python3

# Generate Cython C code
cython g2clib.pyx
cython redtoreg.pyx
cython pygrib.pyx

%if 0%{?with_python3}
pushd %{py3dir}
cython -3 g2clib.pyx
cython -3 redtoreg.pyx
cython -3 pygrib.pyx
%endif # if with_python3

%build

export JASPER_DIR="%{_usr}/"
export PNG_DIR="%{_usr}/"
%{__python2} setup.py build

%if 0%{?with_python3}
pushd %{py3dir}
%{__python3} setup.py build
%endif # if with_python3

%install

# this setting triggers installation of man pages by the setup.py file
export MAN_DIR=/usr/share/man/

%{__python2} setup.py install --skip-build --root %{buildroot}

# correct wrong write permission for group
chmod 755  %{buildroot}/%{python2_sitearch}/*.so

%if 0%{?with_python3}
pushd %{py3dir}
%{__python3} setup.py install --skip-build --root %{buildroot}

# correct wrong write permission for group
chmod 755  %{buildroot}/%{python3_sitearch}/*.so
%endif # if with_python3

%check
export PYTHONPATH=%{buildroot}/%{python2_sitearch}
%{__python2} test.py

%if 0%{?with_python3}
pushd %{py3dir}
export PYTHONPATH=%{buildroot}/%{python3_sitearch}
%{__python3} test.py
%endif # if with_python3

%files
%doc COPYING PKG-INFO README.md
%doc docs ncepgrib2_docs

# For arch-specific packages: sitearch
%{python2_sitearch}/*.so
%{python2_sitearch}/ncep*.py*
%{python2_sitearch}/%{name}-*-py*.egg-info
# these are only provided for python3
# as required by the python3=default choice for Fedora
#%%{_bindir}/cnv*
#%%{_bindir}/grib_*
#%%{_mandir}/man1/cnv*
#%%{_mandir}/man1/grib_*

%if 0%{?with_python3}
%files -n python3-%{name}
%doc COPYING PKG-INFO README.md
%doc docs ncepgrib2_docs
%{python3_sitearch}/*.so
%{python3_sitearch}/ncep*.py*
%{python3_sitearch}/__pycache__/ncep*.py*
%{python3_sitearch}/%{name}-*-py*.egg-info
%{_bindir}/cnv*
%{_bindir}/grib_*
%{_mandir}/man1/cnv*
%{_mandir}/man1/grib_*

%endif # with_python3

%changelog
* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 2.0.2-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Mon Dec 19 2016 Miro HronĨok <mhroncok@redhat.com> - 2.0.2-4
- Rebuild for Python 3.6


* Sat Dec 3 2016 Jos de Kloe <josdekloe@gmail.com> 2.0.2-3
- force a rebuild, needed due to libjasper so version bump

* Sat Nov 26 2016 Jos de Kloe <josdekloe@gmail.com> 2.0.2-2
- fix mistake in patch for setup.py file that caused python3 package
  to provide python2 version tools

* Sun Nov 20 2016 Jos de Kloe <josdekloe@gmail.com> 2.0.2-1
- update to new upstream version
- provide tools below /usr/bin for python3 in stead of python2
- move to new predictable pypi source location
- add python_provide macros

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

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

* Thu Jan 21 2016 Jos de Kloe <josdekloe@gmail.com> 2.0.1-1
- update to new upstream version

* Sun Nov 15 2015 Jos de Kloe <josdekloe@gmail.com> 2.0.0-5
- update patch pygrib-2.0.0-g2clib.pyx.patch and add a new
  pygrib-2.0.0-pygrib.pyx.patch to adapt to stricter
  variable type checking of cython
  
* Tue Nov 10 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0.0-4
- Rebuilt for https://fedoraproject.org/wiki/Changes/python3.5

* Wed Jul 15 2015 Orion Poplawski <orion@cora.nwra.com> - 2.0.0-3
- Rebuild for grib_api 1.14.0 soname bump

* Thu Jun 18 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Thu Feb 19 2015 Jos de Kloe <josdekloe@gmail.com> 2.0.0-1
- update to upstream version 2.0.0

* Sun Aug 17 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.9.9-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Wed Jul 09 2014 Jos de Kloe <josdekloe@gmail.com> 1.9.9-2
- move requires for python3-pyproj above description section

* Sat Jul 05 2014 Jos de Kloe <josdekloe@gmail.com> 1.9.9-1
- update to upstream version 1.9.9
- replace python_sitearch macro with python2_sitearch
- activate installation of the newly added man pages
- fix requires problem for python3-pyproj
- update url for Source0

* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.9.7-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Mon May 19 2014 Bohuslav Kabrda <bkabrda@redhat.com> - 1.9.7-2
- Rebuilt for https://fedoraproject.org/wiki/Changes/Python_3.4

* Sat Oct 26 2013 Jos de Kloe <josdekloe@gmail.com> 1.9.7-1
- update to upstream version 1.9.7

* Fri Aug 23 2013 Jos de Kloe <josdekloe@gmail.com> 1.9.6-1
- update to upstream version 1.9.6
  and move to use grib_api-devel as BR as suggested by Orion Poplawski
  on devel mailinglist on 23-Aug-2013

* Wed Aug 14 2013 Jos de Kloe <josdekloe@gmail.com> 1.9.5-4
- add an explicit requirement on grib_api

* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.9.5-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Thu Nov 22 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.5-2
- adapt to build with python3 as well
- fix typo in weekdays in dates of changelog entries 1.9.2-1 and 1.9.4-1

* Thu Nov 08 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.5-1
- update to upstream version 1.9.5
- add the doc files to the files list
- activate the check section

* Sat Sep 08 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.4-3
- remove BR of grib_api-devel and g2clib-devel and some textual 
  changes in the comments

* Wed Aug 29 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.4-2
- address comments 3 and 4 in bugzilla review request 806037

* Thu Aug 23 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.4-1
- move to version 1.9.4 and fix a bunch of rpmlint warnings

* Sun Mar 18 2012 Jos de Kloe <josdekloe@gmail.com> 1.9.2-1
- initial version