Skip to content

Commit 3cbbb7c

Browse files
author
Paul K. Korir, PhD
committed
bugfix: removed use of os library for exit codes (problem on Windows)
* fixed errors in documentation (`developing.rst`) * version bump
1 parent 5e9f6d1 commit 3cbbb7c

File tree

15 files changed

+82
-93
lines changed

15 files changed

+82
-93
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
18+
python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10' ]
1919

2020
steps:
2121
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#Changes by release
22

3+
## [0.7.2] - 2022-04-26
4+
5+
add Python3.10 support
6+
7+
* removed use of `os` package for exit codes (problems on Windows)
8+
* fixed errors in `developing` documentation
9+
10+
## [0.7.1] - 2021-08-24
11+
12+
bugfix: reading from HDF5 retains some ids as `numpy.int64`
13+
14+
* tests added and pass
15+
316
## [0.7.0] - 2021-06-17
417

518
add Python3.9 support; dropped Python2.7

docs/_build/html/_sources/extending.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ In order to perform conversion using the command-line utility, we need to have t
305305
# ...
306306
sff_seg.export(args.output)
307307
308-
return os.EX_OK
308+
return 0
309309
310310
Once this is done the following should work:
311311

docs/developing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ For each segment (voxel value) in the lattice create a 3D volume object that ref
877877
# segment one
878878
segment = sff.SFFSegment()
879879
vol1_value = 1
880-
segment.volume = sff.SFFThreeDVolume(
881-
latticeId=0,
880+
segment.three_d_volume = sff.SFFThreeDVolume(
881+
lattice_id=0,
882882
value=vol1_value,
883883
)
884884
segment.colour = sff.SFFRGBA(
@@ -892,8 +892,8 @@ For each segment (voxel value) in the lattice create a 3D volume object that ref
892892
# segment two
893893
segment = sff.SFFSegment()
894894
vol2_value = 37.1
895-
segment.volume = sff.SFFThreeDVolume(
896-
latticeId=2,
895+
segment.three_d_volume = sff.SFFThreeDVolume(
896+
lattice_id=2,
897897
value=vol2_value
898898
)
899899
segment.colour = sff.SFFRGBA(

setup.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
u"Programming Language :: Python :: 3.7",
3636
u"Programming Language :: Python :: 3.8",
3737
u"Programming Language :: Python :: 3.9",
38+
u"Programming Language :: Python :: 3.10",
3839
u"Topic :: Software Development :: Libraries :: Python Modules",
3940
u"Topic :: Terminals",
4041
u"Topic :: Text Processing",
@@ -62,26 +63,3 @@
6263
]
6364
},
6465
)
65-
# if sys.version_info[0] > 2:
66-
# else:
67-
# setup(
68-
# name=SFFTKRW_NAME,
69-
# version=SFFTKRW_VERSION,
70-
# packages=find_packages(),
71-
# author=SFFTKRW_AUTHOR,
72-
# author_email=SFFTKRW_AUTHOR_EMAIL,
73-
# description=SFFTKRW_DESCRIPTION,
74-
# long_description=long_description,
75-
# long_description_content_type=SFFTKRW_DESCRIPTION_CONTENT_TYPE,
76-
# url=SFFTKRW_URL,
77-
# license=SFFTKRW_LICENSE,
78-
# keywords=SFFTKRW_KEYWORDS,
79-
# setup_requires=SFFTKRW_SETUP_REQUIRES,
80-
# install_requires=SFFTKRW_INSTALL_REQUIRES,
81-
# classifiers=SFFTKRW_CLASSIFIERS,
82-
# entry_points={
83-
# 'console_scripts': [
84-
# '{} = sfftkrw.sffrw:main'.format(SFFTKRW_ENTRY_POINT),
85-
# ]
86-
# },
87-
# )

sfftkrw/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SFFTKRW_VERSION = 'v0.7.1'
1+
SFFTKRW_VERSION = 'v0.7.2'
22
SFFTKRW_ENTRY_POINT = 'sff'

sfftkrw/core/parser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ def parse_args(_args, use_shlex=False):
234234
try:
235235
assert isinstance(_args, _basestring)
236236
except AssertionError:
237-
return os.EX_USAGE
237+
return 64
238238
import shlex
239239
_args = shlex.split(_args)
240240
# if we have no subcommands then show the available tools
241241
if len(_args) == 0:
242242
Parser.print_help()
243-
return os.EX_OK
243+
return 0
244244
# if we only have a subcommand then show that subcommand's help
245245
elif len(_args) == 1:
246246
# print(_args[0])
@@ -250,18 +250,18 @@ def parse_args(_args, use_shlex=False):
250250
if _args[0] == '-V' or _args[0] == '--version':
251251
print_date(
252252
"sfftk-rw version: {} for EMDB-SFF {}".format(SFFTKRW_VERSION, ', '.join(SUPPORTED_EMDB_SFF_VERSIONS)))
253-
return os.EX_OK
253+
return 0
254254
# anytime a new argument is added to the base parser subparsers are bumped down in index
255255
elif _args[0] in _dict_iter_keys(Parser._actions[2].choices):
256256
exec('{}_parser.print_help()'.format(_args[0]))
257-
return os.EX_OK
257+
return 0
258258
# parse arguments
259259
args = Parser.parse_args(_args)
260260

261261
# check values
262262
# view
263263
if args.subcommand == 'view':
264-
pass # no view-specific checks yet
264+
pass # no view-specific checks yet
265265
# convert
266266
elif args.subcommand == 'convert':
267267
# we only use the first file in sfftk-rw; sfftk may use more than one file
@@ -281,7 +281,7 @@ def parse_args(_args, use_shlex=False):
281281
invalid=args.format,
282282
formats=", ".join(map(lambda x: x[0], FORMAT_LIST)))
283283
)
284-
return os.EX_USAGE
284+
return 64
285285
fn = ".".join(os.path.basename(from_file).split(
286286
'.')[:-1]) + '.{}'.format(args.format)
287287
args.__setattr__('output', os.path.join(dirname, fn))
@@ -311,8 +311,8 @@ def parse_args(_args, use_shlex=False):
311311
]
312312
except AssertionError:
313313
print_date(
314-
"Invalid value for primary descriptor: {}".format(args.primary_descriptor))
315-
return os.EX_USAGE
314+
"Invalid value for primary descriptor: {}".format(args.primary_descriptor))
315+
return 64
316316
if args.verbose:
317317
print_date(
318318
"Trying to set primary descriptor to {}".format(args.primary_descriptor))
@@ -327,7 +327,7 @@ def parse_args(_args, use_shlex=False):
327327
assert args.json_indent >= 0
328328
except AssertionError:
329329
print_date("Invalid value for --json-indent: {}".format(args.json_indent))
330-
return os.EX_USAGE
330+
return 64
331331
if args.verbose:
332332
print_date("Indenting JSON with indent={}".format(args.json_indent))
333333

@@ -348,7 +348,7 @@ def parse_args(_args, use_shlex=False):
348348
print_date(
349349
"Unknown tool: {}; Available tools for test: {}".format(tool, ", ".join(tool_list))
350350
)
351-
return os.EX_USAGE
351+
return 64
352352
if args.verbosity:
353353
try:
354354
assert args.verbosity in range(4)
@@ -360,6 +360,6 @@ def parse_args(_args, use_shlex=False):
360360
args.verbosity
361361
)
362362
)
363-
return os.EX_USAGE
363+
return 64
364364

365365
return args

sfftkrw/schema/adapter_v0_7_0_dev0.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,15 +1782,15 @@ def from_file(cls, fn, args=None):
17821782
seg._local = _sff.parse(fn, silence=True)
17831783
except IOError:
17841784
print_date(_encode(u"File {} not found".format(fn), u'utf-8'))
1785-
sys.exit(os.EX_IOERR)
1785+
sys.exit(74)
17861786
elif re.match(r'.*\.(hff|h5|hdf5)$', fn, re.IGNORECASE):
17871787
with h5py.File(fn, u'r') as h:
17881788
seg._local = seg.from_hff(h, args=args)._local
17891789
elif re.match(r'.*\.json$', fn, re.IGNORECASE):
17901790
seg._local = seg.from_json(fn, args=args)._local
17911791
else:
17921792
print_date(_encode(u"Invalid EMDB-SFF file name: {}".format(fn), u'utf-8'))
1793-
sys.exit(os.EX_USAGE)
1793+
sys.exit(64)
17941794
return seg
17951795

17961796
@property
@@ -1813,7 +1813,7 @@ def as_hff(self, parent_group, name=None, args=None):
18131813
group[u'version'] = self.version
18141814
if self.primary_descriptor is None:
18151815
print_date(_encode(u"Invalid segmentation: primary_descriptor required", u'utf-8'))
1816-
return os.EX_DATAERR
1816+
return 65
18171817
group[u'primaryDescriptor'] = self.primary_descriptor
18181818
# if we are adding another group then donu't set dict style; just return the populated group
18191819
if self.software is None:
@@ -1872,7 +1872,7 @@ def from_hff(cls, hff_data, name=None, args=None):
18721872
print_date(_encode(u'Segmentation name not found. Please check that {} is a valid EMDB-SFF file'.format(
18731873
hff_data.filename
18741874
), u'utf-8'))
1875-
sys.exit(os.EX_DATAERR)
1875+
sys.exit(65)
18761876
obj.version = _decode(hff_data[u'version'][()], u'utf-8')
18771877
obj.software = SFFSoftware.from_hff(hff_data[u'software'], args=args)
18781878
obj.transforms = SFFTransformList.from_hff(hff_data[u'transforms'], args=args)
@@ -2068,7 +2068,7 @@ def merge_annotation(self, other_seg):
20682068
assert isinstance(other_seg, SFFSegmentation)
20692069
except AssertionError:
20702070
print_date(_encode(u"Invalid type for other_seg: {}".format(type(other_seg)), u'utf-8'))
2071-
sys.exit(os.EX_DATAERR)
2071+
sys.exit(65)
20722072
# global data
20732073
self.name = other_seg.name
20742074
self.software = other_seg.software

sfftkrw/schema/adapter_v0_8_0_dev1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ def from_file(cls, fn, args=None):
24932493
"""
24942494
if not os.path.exists(fn):
24952495
print_date(_encode(u"File {} not found".format(fn), u'utf-8'))
2496-
sys.exit(os.EX_IOERR)
2496+
sys.exit(74)
24972497
else:
24982498
if re.match(r'.*\.(sff|xml)$', fn, re.IGNORECASE):
24992499
seg_local = _sff.parse(fn, silence=True)
@@ -2508,7 +2508,7 @@ def from_file(cls, fn, args=None):
25082508
seg_local = seg._local
25092509
else:
25102510
print_date(_encode(u"Invalid EMDB-SFF file name: {}".format(fn), u'utf-8'))
2511-
sys.exit(os.EX_DATAERR)
2511+
sys.exit(65)
25122512
# now create the output object
25132513
obj = cls(new_obj=False)
25142514
obj._local = seg_local

sfftkrw/schema/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io
88
import json
99
import numbers
10-
import os
1110
import re
1211

1312
import h5py
@@ -210,7 +209,7 @@ def export(self, fn, args=None, *_args, **_kwargs):
210209
", ".join(VALID_EXTENSIONS),
211210
fn,
212211
), u'utf-8'))
213-
return os.EX_DATAERR
212+
return 65
214213
if re.match(r"^(sff|xml)$", fn_ext, re.IGNORECASE):
215214
with open(fn, u'w') as f:
216215
# write version and encoding
@@ -238,7 +237,7 @@ def export(self, fn, args=None, *_args, **_kwargs):
238237
# self.as_json(f, *_args, **_kwargs)
239238
elif issubclass(type(fn), io.IOBase):
240239
self._local.export(fn, 0, *_args, **_kwargs)
241-
return os.EX_OK
240+
return 0
242241
else:
243242
raise SFFValueError("export failed due to validation error")
244243

@@ -740,7 +739,7 @@ def _get_next_id(self):
740739
ids = list(self.get_ids())
741740
if len(ids) > 0:
742741
return max(ids) + 1
743-
return 1 # to be on the safe side for segments (segment ids begin at 1)
742+
return 1 # to be on the safe side for segments (segment ids begin at 1)
744743

745744
def _add_to_dict(self, v):
746745
"""Private method that adds to the convenience dictionary

sfftkrw/sffrw.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from __future__ import division, print_function
1010

1111
import importlib
12-
import os
1312
import re
1413
import sys
1514

@@ -68,7 +67,7 @@ def handle_convert(args): # @UnusedVariable
6867
# perform actual export
6968
status = seg.export(args.output, args)
7069
if args.verbose:
71-
if status == os.EX_OK:
70+
if status == 0:
7271
print_date("Done")
7372
else:
7473
print_date("Error")
@@ -120,7 +119,7 @@ def handle_view(args): # @UnusedVariable
120119
print(u"*" * 50)
121120
else:
122121
print(u"Not implemented view for files of type .{}".format(args.from_file.split('.')[-1]), file=sys.stderr)
123-
return os.EX_OK
122+
return 0
124123

125124

126125
def _module_test_runner(mod, args):
@@ -135,7 +134,7 @@ def _module_test_runner(mod, args):
135134
print_date(u"Found {} test cases in the suite...".format(suite.countTestCases()))
136135
if not args.dry_run:
137136
unittest.TextTestRunner(verbosity=args.verbosity).run(suite)
138-
return os.EX_OK
137+
return 0
139138

140139

141140
def _testcase_test_runner(tc, args):
@@ -150,7 +149,7 @@ def _testcase_test_runner(tc, args):
150149
print_date(u"Found {} test cases in the suite...".format(suite.countTestCases()))
151150
if not args.dry_run:
152151
unittest.TextTestRunner(verbosity=args.verbosity).run(suite)
153-
return os.EX_OK
152+
return 0
154153

155154

156155
def _discover_test_runner(path, args, top_level_dir=None):
@@ -165,7 +164,7 @@ def _discover_test_runner(path, args, top_level_dir=None):
165164
print_date(u"Found {} test cases in the suite...".format(suite.countTestCases()))
166165
if not args.dry_run:
167166
unittest.TextTestRunner(verbosity=args.verbosity).run(suite)
168-
return os.EX_OK
167+
return 0
169168

170169

171170
def handle_tests(args):
@@ -199,18 +198,18 @@ def handle_tests(args):
199198
)
200199
test_adapter = importlib.import_module(test_adapter_name)
201200
_module_test_runner(test_adapter, args)
202-
return os.EX_OK
201+
return 0
203202

204203

205204
def main():
206205
try:
207206
from .core.parser import parse_args
208207
args = parse_args(sys.argv[1:])
209208
# missing args
210-
if args == os.EX_USAGE:
211-
return os.EX_USAGE
212-
elif args == os.EX_OK: # e.g. show version has no error but has no handler either
213-
return os.EX_OK
209+
if args == 64:
210+
return 64
211+
elif args == 0: # e.g. show version has no error but has no handler either
212+
return 0
214213
# subcommands
215214
if args.subcommand == 'convert':
216215
return handle_convert(args)
@@ -221,8 +220,8 @@ def main():
221220

222221
except KeyboardInterrupt:
223222
### handle keyboard interrupt ###
224-
return os.EX_OK
225-
return os.EX_OK
223+
return 0
224+
return 0
226225

227226

228227
if __name__ == "__main__":

0 commit comments

Comments
 (0)