diff --git a/.coveragerc b/.coveragerc index 0fa1a54..2456287 100644 --- a/.coveragerc +++ b/.coveragerc @@ -26,3 +26,4 @@ exclude_lines = # Don't complain if non-runnable code isn't run: if 0: if __name__ == .__main__.: + if not IsWin: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7f98a3c..65e2ca8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,13 @@ Changelog ========= +Version 0.1.1 +=========== + +- Simplified glob code +- PATH settings are limited to Windows +- Basic tests passed (97% coverage | 189run | 0 missing | 4 excluded | 8 partial) + Version 0.1 "Bowman" =========== diff --git a/src/kubi/kubi.py b/src/kubi/kubi.py index a834062..5ab58c2 100644 --- a/src/kubi/kubi.py +++ b/src/kubi/kubi.py @@ -7,10 +7,15 @@ import logging import sys import os +import platform import glob import numpy as np from numpy import pi +IsWin = platform.system() == 'Windows' +if not IsWin: + import pyvips + from kubi import __version__ __author__ = "Keim, Stefan" @@ -28,28 +33,29 @@ def kubi(args): - os.environ['PATH'] = 'C:/Program Files/vips-dev-8.10/bin' + ';' + os.environ['PATH'] - if args.vips: - os.environ['PATH'] = args.vips + ';' + os.environ['PATH'] - - import pyvips + if IsWin: + if args.vips: + os.environ['PATH'] = args.vips + ';' + os.environ['PATH'] + import pyvips src_names = None + if args.src: + src_names = glob.glob(args.src,recursive=True) + src_count = len(src_names) + src_multi = src_count > 1 + + if src_count == 0: + print(f'{args.src}: No such file or directory') + return + if args.ii == None: _logger.info('Generating index') size = -1 if args.size: size = args.size - elif args.src: - src_names = glob.glob(args.src,recursive=True) - src_count = len(src_names) - src_multi = src_count > 1 - - if src_count == 0: - print(f'{args.src}: No such file or directory') - return + elif src_names is not None: for name in src_names: image = pyvips.Image.new_from_file(name) size = max(size, int(image.width / 4)) @@ -100,7 +106,8 @@ def kubi(args): index = None idxA = idx else: - index = pyvips.Image.arrayjoin(idx, across=6 if args.layout == "row" else 1) + across = 6 if args.layout == "row" else 1 + index = pyvips.Image.arrayjoin(idx, across = across) else: s0 = 0 s1 = size @@ -155,11 +162,17 @@ def kubi(args): idx = None - if args.src: - if src_names is None: - src_names = glob.glob(args.src, recursive=True) - src_count = len(src_names) - src_multi = src_count > 1 + + if src_names is not None: + +# # # # has no effect on performance +# +# if src_multi: +# if index is None: +# for f in range(6): +# idxA[f] = idxA[f].copy_memory() +# else: +# index = index.copy_memory() dst_suffix = '_'+ args.transform dst_folder = dst_name = dst_ext = None @@ -196,7 +209,6 @@ def kubi(args): dst = f'{dst_folder}/{dst_name}{dst_suffix}' fac = img.width/4 - if index is None: for f in range(6): @@ -266,10 +278,12 @@ def parse_args(args): """) parser.add_argument('-f', '--facenames', metavar="", nargs=6 ,help='suffixes for +X, -X, +Y, -Y, +Z, -Z (e.g. -n r l u d f b)') parser.add_argument('-co', dest='co', metavar='*', action='append', help='create options (more info in the epilog)') - parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH; e.g. on Windows)') parser.add_argument('--io', dest='io', help='index file output', metavar='dstindex') parser.add_argument('--ii', dest='ii', help='index file input', metavar='srcindex') + if IsWin: + parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH)') + args = parser.parse_args(args) if args.src is None: diff --git a/tests/test_kubi.py b/tests/test_kubi.py index 5090d85..c0de45e 100644 --- a/tests/test_kubi.py +++ b/tests/test_kubi.py @@ -64,15 +64,15 @@ def test_main_none_io(capsys): assert dst0.bands == 3 def test_main_none_ii(capsys): - args = ['--ii', path_out + 'idx_none', path_in+'baseoverlay.tif', path_out+'baseoverlay_none.png'] + args = ['--ii', path_out + 'idx_none', path_in+'base*.tif', path_out+'multi.png'] print('\nargs: '+' '.join(args)) main(args) - dst_names = glob.glob(path_out+"*overlay_none*.png") - assert len(dst_names) == 6 + dst_names = glob.glob(path_out+"*multi*.png") + assert len(dst_names) == 12 dst0 = pyvips.Image.new_from_file(dst_names[0]) assert dst0.width == dst0.height == 1024 - assert dst0.bands == 4 + assert dst0.bands == 3 def test_main_none_inplace(capsys): @@ -87,7 +87,7 @@ def test_main_none_inplace(capsys): assert dst0.width == dst0.height == 256 def test_main_none_sub(capsys): - args = ['-s', '256', '-t', 'optan', path_out+'bm.tif', path_out+'sub/warped.png'] + args = ['-s', '256', '-t', 'otc', path_out+'bm.tif', path_out+'sub/warped.png'] print('\nargs: '+' '.join(args)) main(args) @@ -137,7 +137,7 @@ def test_main_crossL(capsys): assert dst0.width == 1024 * 4 and dst0.height == 1024 * 3 def test_main_crossR(capsys): - args = ['-l','crossR','-t','optan', path_in+'basemap.tif', path_out+'basemap_crossR.png'] + args = ['-l','crossR','-t','otc', path_in+'basemap.tif', path_out+'basemap_crossR.png'] print('\nargs: '+' '.join(args)) main(args)