Skip to content

MRG: refactor modules into netCDF4 package #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
build/
*.pyc
dist/
*.egg-info/
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
Not installed by setup.py (contributed by Ross Gammon, issue #383).
* replace tabs with spaces by running reindent.py on all *.py and *.pyx files
(issue #378).
* refactor netCDF4_utils and netCDF4 module into netCDF4 package.
Refactoring effectively removes netCDF4 utils private attributes from
netCDF4 namespace, so has the potential to break code using private
attributes (issue #409).

version 1.1.7 (tag v1.1.7rel)
=============================
Expand Down
7 changes: 1 addition & 6 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
recursive-include docs *
recursive-include man *
recursive-include include *
include MANIFEST.in
include README.md
include COPYING
include Changelog
include setup.cfg
include setup.cfg.template
include netCDF4.pyx
include netCDF4_utils.py
include netCDF4.pxi
include netCDF4.c
include utils.pyx
include constants.pyx
include examples/*py
include examples/*ipynb
include examples/README.md
Expand Down
2 changes: 1 addition & 1 deletion create_docs.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# svn propset svn:mime-type text/html docs/*html
epydoc -v --no-frames --no-private --introspect-only -o docs netCDF4
epydoc -v --no-frames --no-private --introspect-only --name netcdf4-python -o docs netCDF4._netCDF4
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions netCDF4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# init for netCDF4 package
# Docstring comes from extension module _netCDF4
from ._netCDF4 import *
# Need explicit imports for names beginning with underscores
from ._netCDF4 import __doc__
from ._netCDF4 import (__version__, __netcdf4libversion__, __hdf5libversion__,
__has_rename_grp__, __has_nc_inq_path__,
__has_nc_inq_format_extended__)
9,616 changes: 4,808 additions & 4,808 deletions netCDF4.c → netCDF4/_netCDF4.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions netCDF4.pyx → netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ del __test__ # hack so epydoc doesn't show __test__
# Make changes to this file, not the c-wrappers that Pyrex generates.

# pure python utilities
from netCDF4_utils import _StartCountStride, _quantize, _find_dim, _walk_grps, \
_out_array_shape, _sortbylist, _tostr
from .utils import (_StartCountStride, _quantize, _find_dim, _walk_grps,
_out_array_shape, _sortbylist, _tostr)
# try to use built-in ordered dict in python >= 2.7
try:
from collections import OrderedDict
Expand Down
File renamed without changes.
18 changes: 13 additions & 5 deletions netcdftime/_datetime.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 25 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os, sys, subprocess, shutil
import os, sys, subprocess
import os.path as osp

try:
from setuptools import setup, Extension
setuptools_extra_kwargs = {
"install_requires": ["numpy>=1.7"],
"entry_points": {
'console_scripts': [
'ncinfo = netCDF4_utils:ncinfo',
'nc4tonc3 = netCDF4_utils:nc4tonc3',
'nc3tonc4 = netCDF4_utils:nc3tonc4',
'ncinfo = netCDF4.utils:ncinfo',
'nc4tonc3 = netCDF4.utils:nc4tonc3',
'nc3tonc4 = netCDF4.utils:nc3tonc4',
]
},
}
Expand Down Expand Up @@ -349,22 +351,25 @@ def getnetcdfvers(libdirs):
sys.stdout.write('using netcdf library version %s\n' % netcdf_lib_version)

cmdclass = {}
netcdf4_src_root = osp.join('netCDF4', '_netCDF4')
netcdf4_src_c = netcdf4_src_root + '.c'
if has_cython and 'sdist' not in sys.argv[1:]:
sys.stdout.write('using Cython to compile netCDF4.pyx...\n')
extensions = [Extension("netCDF4",["netCDF4.pyx"],
libraries=libs,
library_dirs=lib_dirs,
include_dirs=inc_dirs,
runtime_library_dirs=lib_dirs),
extensions = [Extension("netCDF4._netCDF4",
[netcdf4_src_root + '.pyx'],
libraries=libs,
library_dirs=lib_dirs,
include_dirs=inc_dirs,
runtime_library_dirs=lib_dirs),
Extension('netcdftime._datetime', ['netcdftime/_datetime.pyx'])]
# remove netCDF4.c file if it exists, so cython will recompile netCDF4.pyx.
# run for build *and* install (issue #263). Otherwise 'pip install' will
# not regenerate netCDF4.c, even if the C lib supports the new features.
if len(sys.argv) >= 2 and os.path.exists('netCDF4.c'):
os.remove('netCDF4.c')
if len(sys.argv) >= 2 and os.path.exists(netcdf4_src_c):
os.remove(netcdf4_src_c)
# this determines whether renameGroup and filepath methods will work.
has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended = check_api(inc_dirs)
f = open('constants.pyx','w')
f = open(osp.join('include', 'constants.pyx'),'w')
if has_rename_grp:
sys.stdout.write('netcdf lib has group rename capability\n')
f.write('DEF HAS_RENAME_GRP = 1\n')
Expand All @@ -384,13 +389,14 @@ def getnetcdfvers(libdirs):
sys.stdout.write('netcdf lib does not have nc_inq_format_extended function\n')
f.write('DEF HAS_NC_INQ_FORMAT_EXTENDED = 0\n')
f.close()
ext_modules = cythonize(extensions)
ext_modules = cythonize(extensions, include_path=['include'])
else:
extensions = [Extension("netCDF4",["netCDF4.c"],
libraries=libs,
library_dirs=lib_dirs,
include_dirs=inc_dirs,
runtime_library_dirs=lib_dirs),
extensions = [Extension("netCDF4._netCDF4",
[netcdf4_src_c],
libraries=libs,
library_dirs=lib_dirs,
include_dirs=inc_dirs,
runtime_library_dirs=lib_dirs),
Extension('netcdftime._datetime', ['netcdftime/_datetime.c'])]
ext_modules = extensions

Expand All @@ -412,7 +418,6 @@ def getnetcdfvers(libdirs):
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Archiving :: Compression",
"Operating System :: OS Independent"],
py_modules = ["netCDF4_utils"],
packages = ['netcdftime'],
packages = ['netcdftime', 'netCDF4'],
ext_modules = ext_modules,
**setuptools_extra_kwargs)
3 changes: 2 additions & 1 deletion test/tst_compression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from numpy.random.mtrand import uniform
from netCDF4 import Dataset, _quantize
from netCDF4 import Dataset
from netCDF4.utils import _quantize
from numpy.testing import assert_almost_equal
import os, tempfile, unittest

Expand Down
Loading