[pygrib] Initial import (#855529).

Jos de Kloe jdekloe at fedoraproject.org
Wed Mar 6 20:31:05 UTC 2013


commit 7180476fb62def2eab167ba672289d64b65360ef
Author: Jos de Kloe <josdekloe at gmail.com>
Date:   Wed Mar 6 21:30:52 2013 +0100

    Initial import (#855529).

 .gitignore                    |    1 +
 pygrib-1.9.5-2-build.patch    |   81 +++++++++++++++
 pygrib-1.9.5-g2clib.pyx.patch |   11 ++
 pygrib.spec                   |  218 +++++++++++++++++++++++++++++++++++++++++
 sources                       |    1 +
 5 files changed, 312 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index e69de29..e383a5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/pygrib-1.9.5.tar.gz
diff --git a/pygrib-1.9.5-2-build.patch b/pygrib-1.9.5-2-build.patch
new file mode 100644
index 0000000..f1c1216
--- /dev/null
+++ b/pygrib-1.9.5-2-build.patch
@@ -0,0 +1,81 @@
+--- setup.py.orig	2012-11-22 14:52:16.394328492 +0100
++++ setup.py	2012-11-22 15:52:26.566006076 +0100
+@@ -24,7 +24,7 @@
+ setup_cfg = os.environ.get('PYGRIBSETUPCFG', 'setup.cfg')
+ # contents of setup.cfg will override env vars.
+ if os.path.exists(setup_cfg):
+-    print 'reading from setup.cfg...'
++    print('reading from setup.cfg...')
+     config = configparser.SafeConfigParser()
+     config.read(setup_cfg)
+     try: grib_api_dir = config.get("directories", "grib_api_dir")
+@@ -101,23 +101,33 @@
+ if zlib_incdir is None and zlib_dir is not None:
+     incdirs.append(os.path.join(zlib_dir,'include'))
+ 
+-g2clib_deps = glob.glob('g2clib_src/*.c')
+-g2clib_deps.append('g2clib.c')
+-incdirs.append("g2clib_src")
++#g2clib_deps = glob.glob('g2clib_src/*.c')
++#g2clib_deps.append('g2clib.c')
++g2clib_deps = ['g2clib.c',]
++g2clib_dir = '/usr/lib64'
++g2clib_incdir = '/usr/include'
++libdirs.append(g2clib_dir)
++incdirs.append(g2clib_incdir)
++libraries.append('grib2c')
++#incdirs.append("g2clib_src")
+ macros=[]
+ 
+-# if jasper or openjpeg lib not available...
+-if 'jasper' not in libraries and 'openjpeg' not in libraries:
+-    g2clib_deps.remove('g2clib_src/jpcpack.c')
+-    g2clib_deps.remove('g2clib_src/jpcunpack.c')
+-else:
+-    macros.append(('USE_JPEG2000',1))
+-# if png lib not available...
+-if 'png' not in libraries:
+-    g2clib_deps.remove('g2clib_src/pngpack.c')
+-    g2clib_deps.remove('g2clib_src/pngunpack.c')
+-else:
+-    macros.append(('USE_PNG',1))
++# the USE_JPEG2000 and USE_PNG defines are only used inside
++# g2clib_src, which is removed before doing the fedora rpm build
++# anyway, so these lines can be safely discarded:
++
++## if jasper or openjpeg lib not available...
++#if 'jasper' not in libraries and 'openjpeg' not in libraries:
++#    g2clib_deps.remove('g2clib_src/jpcpack.c')
++#    g2clib_deps.remove('g2clib_src/jpcunpack.c')
++#else:
++#    macros.append(('USE_JPEG2000',1))
++## if png lib not available...
++#if 'png' not in libraries:
++#    g2clib_deps.remove('g2clib_src/pngpack.c')
++#    g2clib_deps.remove('g2clib_src/pngunpack.c')
++#else:
++#    macros.append(('USE_PNG',1))
+ 
+ if hasattr(sys,'maxsize'):
+     if sys.maxsize > 2**31-1: macros.append(('__64BIT__',1))
+@@ -130,6 +140,11 @@
+ pygribext =\
+ Extension("pygrib",["pygrib.c"],include_dirs=incdirs,library_dirs=libdirs,libraries=libraries)
+ 
++# don't provide the scripts for the python3 version, to prevent collisions
++# in case a user installs both a python2 and a python3 version of the module
++scripts_list = []
++if sys.version_info[0] < 3:
++    scripts_list = ['utils/grib_list','utils/grib_repack','utils/cnvgrib1to2','utils/cnvgrib2to1']
+ 
+ setup(name = "pygrib",
+       version = "1.9.5",
+@@ -138,7 +153,6 @@
+       author_email      = "jeffrey.s.whitaker at noaa.gov",
+       url               = "http://code.google.com/p/pygrib",
+       download_url      = "http://code.google.com/p/pygrib/downloads/list",
+-      scripts =
+-      ['utils/grib_list','utils/grib_repack','utils/cnvgrib1to2','utils/cnvgrib2to1'],
++      scripts           = scripts_list,
+       ext_modules       = [pygribext,g2clibext,redtoregext],
+       py_modules        = ["ncepgrib2"])
diff --git a/pygrib-1.9.5-g2clib.pyx.patch b/pygrib-1.9.5-g2clib.pyx.patch
new file mode 100644
index 0000000..f53f873
--- /dev/null
+++ b/pygrib-1.9.5-g2clib.pyx.patch
@@ -0,0 +1,11 @@
+--- g2clib.pyx.orig	2012-11-22 14:17:33.519722304 +0100
++++ g2clib.pyx	2012-11-22 14:17:33.519722304 +0100
+@@ -450,7 +450,7 @@
+         format = "%."+repr(digitsofprecision+1)+"g"
+         minmaxstring = 'min/max='+format+'/'+format
+         minmaxstring = minmaxstring % (fldmin,fldmax)
+-        print minmaxstring
++        print(minmaxstring)
+ 
+     data = _toarray(fld, zeros(ngpts, 'f4', order=storageorder))
+     return data
diff --git a/pygrib.spec b/pygrib.spec
new file mode 100644
index 0000000..1d0b69b
--- /dev/null
+++ b/pygrib.spec
@@ -0,0 +1,218 @@
+# This module also works with Python 3
+%if 0%{?fedora} || 0%{?rhel} > 6
+%global with_python3 1
+%endif
+
+Name:       pygrib
+Version:    1.9.5
+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
+
+# TODO: all patches should have a comment above them in the SPEC file about
+# their upstream status.
+
+# Adapt setup.py to not use packaged g2clib source code
+# and fix a small python3 problem
+Patch0: %{name}-%{version}-2-build.patch
+# Adapt g2clib.pyx to the python3 coding standard
+Patch1: %{name}-%{version}-g2clib.pyx.patch
+
+BuildRequires: python2-devel
+BuildRequires: grib_api-static >= 1.9.0
+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 
+
+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:    grib_api 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 Meterological 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 Meterological 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}/"
+%{__python} setup.py build
+
+%if 0%{?with_python3}
+pushd %{py3dir}
+%{__python3} setup.py build
+%endif # if with_python3
+
+%install
+%{__python} 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}
+%{__python} 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
+* Thu Nov 22 2012 Jos de Kloe <josdekloe at 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 at 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 at 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 at gmail.com> 1.9.4-2
+- address comments 3 and 4 in bugzilla review request 806037
+
+* Thu Aug 23 2012 Jos de Kloe <josdekloe at 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 at gmail.com> 1.9.2-1
+- initial version
diff --git a/sources b/sources
index e69de29..1d32ece 100644
--- a/sources
+++ b/sources
@@ -0,0 +1 @@
+e14a9c7fa6bc0c8036b6f45cac6eb187  pygrib-1.9.5.tar.gz


More information about the scm-commits mailing list