Skip to content

Commit

Permalink
simplified glob code & PATH only on Win
Browse files Browse the repository at this point in the history
  • Loading branch information
Keim, Stefan committed Jun 12, 2021
1 parent 36c0889 commit 2a3afee
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ exclude_lines =
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
if not IsWin:
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
===========

Expand Down
56 changes: 35 additions & 21 deletions src/kubi/kubi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -266,10 +278,12 @@ def parse_args(args):
""")
parser.add_argument('-f', '--facenames', metavar="<str>", 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='<NAME=VALUE>*', 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:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_kubi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2a3afee

Please sign in to comment.