Skip to content

Commit

Permalink
Convert to Python package with entry_points (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Nov 27, 2019
1 parent 4ae0486 commit 0a77081
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 201 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: python

python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
# command to install dependencies

install:
- pip install h5py numpy docopt
- pip install .
- export PATH="${PWD}"/bin:"${PATH}"
# command to run tests
- python -m pip install .

script:
- python test/bin/G5check.py
- python test/bin/G5compare.py
Expand Down
53 changes: 0 additions & 53 deletions CMakeLists.txt

This file was deleted.

10 changes: 7 additions & 3 deletions GooseHDF5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import warnings
warnings.filterwarnings("ignore")

import os, re, h5py
import os
import re
import h5py

# ==================================================================================================

Expand Down Expand Up @@ -343,8 +345,10 @@ def verify(data, datasets, error=False):
try:
tmp = data[path][...]
except:
if error: raise IOError('Error reading "{path:s}"'.format(path=path))
else : continue
if error:
raise IOError('Error reading "{path:s}"'.format(path=path))
else:
continue

# - add to output
out += [path]
Expand Down
38 changes: 24 additions & 14 deletions bin/G5check → GooseHDF5/cli/G5check.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
warnings.filterwarnings("ignore")

import numpy as np
import sys, os, re, h5py, docopt, GooseHDF5
import sys
import os
import re
import h5py
import docopt

from .. import *

# ==================================================================================================

Expand All @@ -38,28 +44,32 @@ def check_isfile(fname):

# ==================================================================================================

def read(filename, verify):
def read(filename, check):
r'''
Read (and verify) all datasets
Read (and check) all datasets
'''

with h5py.File(filename, 'r') as source:

paths = list(GooseHDF5.getdatasets(source))
paths = getdatasets(source)

if verify:
GooseHDF5.verify(source, paths, error=True)
if check:
verify(source, paths, error=True)

# ==================================================================================================

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.2')
def main():

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.2')

# check that file exists
check_isfile(args['<source>'])
# check that file exists
check_isfile(args['<source>'])

# read datasets
try:
read(args['<source>'], not args['--basic'])
except:
print(args['<source>'])

# read datasets
try:
read(args['<source>'], not args['--basic'])
except:
print(args['<source>'])
46 changes: 26 additions & 20 deletions bin/G5compare → GooseHDF5/cli/G5compare.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
warnings.filterwarnings("ignore")

import numpy as np
import sys, os, re, h5py, docopt, GooseHDF5
import sys
import os
import re
import h5py
import docopt

from .. import *

# ==================================================================================================

Expand Down Expand Up @@ -90,17 +96,17 @@ def check_plain(source_name, other_name):
with h5py.File(other_name, 'r') as other:

# check missing dataset
for path in GooseHDF5.getpaths(source):
for path in getpaths(source):
if path not in other:
print('-> {0:s}'.format(path))

# check missing dataset
for path in GooseHDF5.getpaths(other):
for path in getpaths(other):
if path not in source:
print('<- {0:s}'.format(path))

# check values
for path in GooseHDF5.getpaths(source):
for path in getpaths(source):
if path in other:
check_dataset(path, source[path][...], other[path][...])

Expand All @@ -118,8 +124,8 @@ def check_renamed(source, other, renamed):
with h5py.File(other, 'r') as other:

# get list of all datasets
s2o = {i:i for i in list(GooseHDF5.getpaths(source))}
o2s = {i:i for i in list(GooseHDF5.getpaths(other))}
s2o = {i:i for i in list(getpaths(source))}
o2s = {i:i for i in list(getpaths(other))}

# rename
for s, o in renamed:
Expand All @@ -143,22 +149,22 @@ def check_renamed(source, other, renamed):

# ==================================================================================================

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.1')

# check that file exists
check_isfile(args['<source>'])
check_isfile(args['<other>'])
def main():

# check without accounting for renamed field
if len(args['--renamed']) == 0:
check_plain(args['<source>'], args['<other>'])
sys.exit(0)
# parse command-line options
args = docopt.docopt(__doc__,version='0.0.1')

# unpack renaming
renamed = [i.split(args['--ifs']) for i in args['--renamed']]
# check that file exists
check_isfile(args['<source>'])
check_isfile(args['<other>'])

# check with accounting for renamed field
check_renamed(args['<source>'], args['<other>'], renamed)
# check without accounting for renamed field
if len(args['--renamed']) == 0:
check_plain(args['<source>'], args['<other>'])
sys.exit(0)

# unpack renaming
renamed = [i.split(args['--ifs']) for i in args['--renamed']]

# check with accounting for renamed field
check_renamed(args['<source>'], args['<other>'], renamed)
43 changes: 25 additions & 18 deletions bin/G5list → GooseHDF5/cli/G5list.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@

# ==================================================================================================

# temporary fix: suppress warning from h5py
import warnings
warnings.filterwarnings("ignore")

import numpy as np
import sys, os, re, h5py, docopt, GooseHDF5
import sys
import os
import re
import h5py
import docopt

from .. import *

# ==================================================================================================

Expand Down Expand Up @@ -90,23 +95,25 @@ def print_info(source, paths):

# ==================================================================================================

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.3')
def main():

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.3')

# check that file exists
check_isfile(args['<source>'])
# check that file exists
check_isfile(args['<source>'])

# open file and read
with h5py.File(args['<source>'], 'r') as source:
# open file and read
with h5py.File(args['<source>'], 'r') as source:

# get iterator to data-sets
paths = GooseHDF5.getpaths(source,
root = args['--root'],
max_depth = args['--max-depth'],
fold = args['--fold'])
# get iterator to data-sets
paths = getpaths(source,
root = args['--root'],
max_depth = args['--max-depth'],
fold = args['--fold'])

# print
if args['--info']:
print_info(source, paths)
else:
print_plain(source, paths)
# print
if args['--info']:
print_info(source, paths)
else:
print_plain(source, paths)
41 changes: 24 additions & 17 deletions bin/G5repair → GooseHDF5/cli/G5repair.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@

# ==================================================================================================

# temporary fix: suppress warning from h5py
import warnings
warnings.filterwarnings("ignore")

import numpy as np
import sys, os, re, h5py, docopt, GooseHDF5
import sys
import os
import re
import h5py
import docopt

from .. import *

# ==================================================================================================

Expand All @@ -38,23 +43,25 @@ def check_isfile(fname):

# ==================================================================================================

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.2')
def main():

# parse command-line options
args = docopt.docopt(__doc__,version='0.0.2')

# check that file exists
check_isfile(args['<source>'])
# check that file exists
check_isfile(args['<source>'])

# check to overwrite
if os.path.isfile(args['<destination>']) and not args['--force']:
if not click.confirm('File "{0:s}" already exists, continue [y/n]? '.format(args['<destination>'])):
sys.exit(1)
# check to overwrite
if os.path.isfile(args['<destination>']) and not args['--force']:
if not click.confirm('File "{0:s}" already exists, continue [y/n]? '.format(args['<destination>'])):
sys.exit(1)

# read the 'damaged' file
with h5py.File(args['<source>'], 'r') as source:
# read the 'damaged' file
with h5py.File(args['<source>'], 'r') as source:

# get paths that can be read
paths = GooseHDF5.verify(source, GooseHDF5.getdatasets(source))
# get paths that can be read
paths = verify(source, getdatasets(source))

# copy datasets
with h5py.File(args['<destination>'], 'w') as dest:
GooseHDF5.copydatasets(source, dest, paths)
# copy datasets
with h5py.File(args['<destination>'], 'w') as dest:
copydatasets(source, dest, paths)
Empty file added GooseHDF5/cli/__init__.py
Empty file.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Travis](https://travis-ci.com/tdegeus/GooseHDF5.svg?branch=master)](https://travis-ci.com/tdegeus/GooseHDF5)

[![Documentation Status](https://readthedocs.org/projects/goosehdf5/badge/?version=latest)](http://goosehdf5.readthedocs.io/en/latest/?badge=latest)

# GooseHDF5
Expand Down

0 comments on commit 0a77081

Please sign in to comment.