Skip to content

Commit c97edfd

Browse files
committed
RF: move modules into netCDF4 package
* Make netCDF4 a package; * Move netCDF4, netCDF4_utils into package; * Make compatibility wrapper module for netCDF4_utils; * Rebuild c files from moved pyx files.
1 parent 4363fdb commit c97edfd

File tree

16 files changed

+4902
-4881
lines changed

16 files changed

+4902
-4881
lines changed

Changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
Not installed by setup.py (contributed by Ross Gammon, issue #383).
2828
* replace tabs with spaces by running reindent.py on all *.py and *.pyx files
2929
(issue #378).
30+
* refactor netCDF4_utils and netCDF4 module into netCDF4 package.
31+
Refactoring effectively removes netCDF4 utils private attributes from
32+
netCDF4 namespace, so has the potential to break code using private
33+
attributes (issue #409).
3034

3135
version 1.1.7 (tag v1.1.7rel)
3236
=============================

MANIFEST.in

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
recursive-include docs *
22
recursive-include man *
3+
recursive-include src *
34
include MANIFEST.in
45
include README.md
56
include COPYING
67
include Changelog
78
include setup.cfg
89
include setup.cfg.template
9-
include netCDF4.pyx
10-
include netCDF4_utils.py
11-
include netCDF4.pxi
12-
include netCDF4.c
13-
include utils.pyx
14-
include constants.pyx
1510
include examples/*py
1611
include examples/*ipynb
1712
include examples/README.md

netCDF4/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# init for netCDF4 package
2+
# Docstring comes from extension module _netCDF4
3+
from ._netCDF4 import *
4+
# Need explicit imports for names beginning with underscores
5+
from ._netCDF4 import __doc__
6+
from ._netCDF4 import (__version__, __netcdf4libversion__, __hdf5libversion__,
7+
__has_rename_grp__, __has_nc_inq_path__,
8+
__has_nc_inq_format_extended__)

netCDF4.c renamed to netCDF4/_netCDF4.c

Lines changed: 4808 additions & 4808 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netCDF4.pyx renamed to netCDF4/_netCDF4.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ del __test__ # hack so epydoc doesn't show __test__
768768
# Make changes to this file, not the c-wrappers that Pyrex generates.
769769

770770
# pure python utilities
771-
from netCDF4_utils import _StartCountStride, _quantize, _find_dim, _walk_grps, \
772-
_out_array_shape, _sortbylist, _tostr
771+
from .utils import (_StartCountStride, _quantize, _find_dim, _walk_grps,
772+
_out_array_shape, _sortbylist, _tostr)
773773
# try to use built-in ordered dict in python >= 2.7
774774
try:
775775
from collections import OrderedDict
File renamed without changes.

netcdftime/_datetime.c

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import os, sys, subprocess, shutil
1+
import os, sys, subprocess
2+
import os.path as osp
3+
24
try:
35
from setuptools import setup, Extension
46
setuptools_extra_kwargs = {
57
"install_requires": ["numpy>=1.7"],
68
"entry_points": {
79
'console_scripts': [
8-
'ncinfo = netCDF4_utils:ncinfo',
9-
'nc4tonc3 = netCDF4_utils:nc4tonc3',
10-
'nc3tonc4 = netCDF4_utils:nc3tonc4',
10+
'ncinfo = netCDF4.utils:ncinfo',
11+
'nc4tonc3 = netCDF4.utils:nc4tonc3',
12+
'nc3tonc4 = netCDF4.utils:nc3tonc4',
1113
]
1214
},
1315
}
@@ -349,22 +351,25 @@ def getnetcdfvers(libdirs):
349351
sys.stdout.write('using netcdf library version %s\n' % netcdf_lib_version)
350352

351353
cmdclass = {}
354+
netcdf4_src_root = osp.join('netCDF4', '_netCDF4')
355+
netcdf4_src_c = netcdf4_src_root + '.c'
352356
if has_cython and 'sdist' not in sys.argv[1:]:
353357
sys.stdout.write('using Cython to compile netCDF4.pyx...\n')
354-
extensions = [Extension("netCDF4",["netCDF4.pyx"],
355-
libraries=libs,
356-
library_dirs=lib_dirs,
357-
include_dirs=inc_dirs,
358-
runtime_library_dirs=lib_dirs),
358+
extensions = [Extension("netCDF4._netCDF4",
359+
[netcdf4_src_root + '.pyx'],
360+
libraries=libs,
361+
library_dirs=lib_dirs,
362+
include_dirs=inc_dirs,
363+
runtime_library_dirs=lib_dirs),
359364
Extension('netcdftime._datetime', ['netcdftime/_datetime.pyx'])]
360365
# remove netCDF4.c file if it exists, so cython will recompile netCDF4.pyx.
361366
# run for build *and* install (issue #263). Otherwise 'pip install' will
362367
# not regenerate netCDF4.c, even if the C lib supports the new features.
363-
if len(sys.argv) >= 2 and os.path.exists('netCDF4.c'):
364-
os.remove('netCDF4.c')
368+
if len(sys.argv) >= 2 and os.path.exists(netcdf4_src_c):
369+
os.remove(netcdf4_src_c)
365370
# this determines whether renameGroup and filepath methods will work.
366371
has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended = check_api(inc_dirs)
367-
f = open('constants.pyx','w')
372+
f = open(osp.join('src', 'constants.pyx'),'w')
368373
if has_rename_grp:
369374
sys.stdout.write('netcdf lib has group rename capability\n')
370375
f.write('DEF HAS_RENAME_GRP = 1\n')
@@ -384,13 +389,14 @@ def getnetcdfvers(libdirs):
384389
sys.stdout.write('netcdf lib does not have nc_inq_format_extended function\n')
385390
f.write('DEF HAS_NC_INQ_FORMAT_EXTENDED = 0\n')
386391
f.close()
387-
ext_modules = cythonize(extensions)
392+
ext_modules = cythonize(extensions, include_path=['src'])
388393
else:
389-
extensions = [Extension("netCDF4",["netCDF4.c"],
390-
libraries=libs,
391-
library_dirs=lib_dirs,
392-
include_dirs=inc_dirs,
393-
runtime_library_dirs=lib_dirs),
394+
extensions = [Extension("netCDF4._netCDF4",
395+
[netcdf4_src_c],
396+
libraries=libs,
397+
library_dirs=lib_dirs,
398+
include_dirs=inc_dirs,
399+
runtime_library_dirs=lib_dirs),
394400
Extension('netcdftime._datetime', ['netcdftime/_datetime.c'])]
395401
ext_modules = extensions
396402

@@ -412,7 +418,6 @@ def getnetcdfvers(libdirs):
412418
"Topic :: Software Development :: Libraries :: Python Modules",
413419
"Topic :: System :: Archiving :: Compression",
414420
"Operating System :: OS Independent"],
415-
py_modules = ["netCDF4_utils"],
416-
packages = ['netcdftime'],
421+
packages = ['netcdftime', 'netCDF4'],
417422
ext_modules = ext_modules,
418423
**setuptools_extra_kwargs)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)