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

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

License:    MIT
Group:      Applications/Engineering
URL:        http://code.google.com/p/pygrib/
Source0:    http://pygrib.googlecode.com/files/%{name}-%{version}.tar.gz

# Adapt setup.py to not use packaged g2clib source code
# and fix a small python3 problem
Patch0: %{name}-%{version}-build.patch
# Adapt g2clib.pyx to the python3 coding standard
Patch1: %{name}-%{version}-g2clib.pyx.patch
# both issues have been reported upstream here:
# http://code.google.com/p/pygrib/issues/detail?id=64

BuildRequires: python2-devel
BuildRequires: grib_api-devel
BuildRequires: g2clib-static
BuildRequires: numpy
BuildRequires: Cython
BuildRequires: pyproj
%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 http://pygrib.googlecode.com/svn/trunk/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
%if 0%{?with_python3}
Requires:  python3-pyproj
%endif # if with_python3

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

# avoid providing the private libs:
%{?filter_setup:
%filter_provides_in %{python_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. 

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

%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
# option -q will suppress unneccessary output
%patch0 -p0 -b .orig
%patch1 -p0 -b .orig
# option -b creates backup files to preserve a copy of the original file
# option -p0 ensures the filenames as mentioned in the patch are used
# without removing leading slashes (see man patch for details)

# 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
%{__python2} setup.py install --skip-build --root %{buildroot}

# correct wrong write permission for group
chmod 755  %{buildroot}/%{python_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}/%{python_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
%doc docs ncepgrib2_docs

# For arch-specific packages: sitearch
%{python_sitearch}/*.so
%{python_sitearch}/ncep*.py*
%{python_sitearch}/%{name}-*-py*.egg-info
%{_bindir}/cnv*
%{_bindir}/grib_*

%if 0%{?with_python3}
%files -n python3-%{name}
%doc COPYING PKG-INFO README
%doc docs ncepgrib2_docs
%{python3_sitearch}/*.so
%{python3_sitearch}/ncep*.py*
%{python3_sitearch}/__pycache__/ncep*.py*
%{python3_sitearch}/%{name}-*-py*.egg-info
# these are only provided for python2 for now
#%%{_bindir}/cnv*
#%%{_bindir}/grib_*
%endif # with_python3

%changelog
* 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