Skip to content

Commit 2a3afee

Browse files
author
Keim, Stefan
committed
simplified glob code & PATH only on Win
1 parent 36c0889 commit 2a3afee

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ exclude_lines =
2626
# Don't complain if non-runnable code isn't run:
2727
if 0:
2828
if __name__ == .__main__.:
29+
if not IsWin:

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Changelog
33
=========
44

5+
Version 0.1.1
6+
===========
7+
8+
- Simplified glob code
9+
- PATH settings are limited to Windows
10+
- Basic tests passed (97% coverage | 189run | 0 missing | 4 excluded | 8 partial)
11+
512
Version 0.1 "Bowman"
613
===========
714

src/kubi/kubi.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import logging
88
import sys
99
import os
10+
import platform
1011
import glob
1112
import numpy as np
1213
from numpy import pi
1314

15+
IsWin = platform.system() == 'Windows'
16+
if not IsWin:
17+
import pyvips
18+
1419
from kubi import __version__
1520

1621
__author__ = "Keim, Stefan"
@@ -28,28 +33,29 @@
2833

2934

3035
def kubi(args):
31-
os.environ['PATH'] = 'C:/Program Files/vips-dev-8.10/bin' + ';' + os.environ['PATH']
3236

33-
if args.vips:
34-
os.environ['PATH'] = args.vips + ';' + os.environ['PATH']
35-
36-
import pyvips
37+
if IsWin:
38+
if args.vips:
39+
os.environ['PATH'] = args.vips + ';' + os.environ['PATH']
40+
import pyvips
3741

3842
src_names = None
43+
if args.src:
44+
src_names = glob.glob(args.src,recursive=True)
45+
src_count = len(src_names)
46+
src_multi = src_count > 1
47+
48+
if src_count == 0:
49+
print(f'{args.src}: No such file or directory')
50+
return
51+
3952
if args.ii == None:
4053
_logger.info('Generating index')
4154

4255
size = -1
4356
if args.size:
4457
size = args.size
45-
elif args.src:
46-
src_names = glob.glob(args.src,recursive=True)
47-
src_count = len(src_names)
48-
src_multi = src_count > 1
49-
50-
if src_count == 0:
51-
print(f'{args.src}: No such file or directory')
52-
return
58+
elif src_names is not None:
5359
for name in src_names:
5460
image = pyvips.Image.new_from_file(name)
5561
size = max(size, int(image.width / 4))
@@ -100,7 +106,8 @@ def kubi(args):
100106
index = None
101107
idxA = idx
102108
else:
103-
index = pyvips.Image.arrayjoin(idx, across=6 if args.layout == "row" else 1)
109+
across = 6 if args.layout == "row" else 1
110+
index = pyvips.Image.arrayjoin(idx, across = across)
104111
else:
105112
s0 = 0
106113
s1 = size
@@ -155,11 +162,17 @@ def kubi(args):
155162

156163
idx = None
157164

158-
if args.src:
159-
if src_names is None:
160-
src_names = glob.glob(args.src, recursive=True)
161-
src_count = len(src_names)
162-
src_multi = src_count > 1
165+
166+
if src_names is not None:
167+
168+
# # # # has no effect on performance
169+
#
170+
# if src_multi:
171+
# if index is None:
172+
# for f in range(6):
173+
# idxA[f] = idxA[f].copy_memory()
174+
# else:
175+
# index = index.copy_memory()
163176

164177
dst_suffix = '_'+ args.transform
165178
dst_folder = dst_name = dst_ext = None
@@ -196,7 +209,6 @@ def kubi(args):
196209
dst = f'{dst_folder}/{dst_name}{dst_suffix}'
197210

198211
fac = img.width/4
199-
200212

201213
if index is None:
202214
for f in range(6):
@@ -266,10 +278,12 @@ def parse_args(args):
266278
""")
267279
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)')
268280
parser.add_argument('-co', dest='co', metavar='<NAME=VALUE>*', action='append', help='create options (more info in the epilog)')
269-
parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH; e.g. on Windows)')
270281
parser.add_argument('--io', dest='io', help='index file output', metavar='dstindex')
271282
parser.add_argument('--ii', dest='ii', help='index file input', metavar='srcindex')
272283

284+
if IsWin:
285+
parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH)')
286+
273287
args = parser.parse_args(args)
274288

275289
if args.src is None:

tests/test_kubi.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def test_main_none_io(capsys):
6464
assert dst0.bands == 3
6565

6666
def test_main_none_ii(capsys):
67-
args = ['--ii', path_out + 'idx_none', path_in+'baseoverlay.tif', path_out+'baseoverlay_none.png']
67+
args = ['--ii', path_out + 'idx_none', path_in+'base*.tif', path_out+'multi.png']
6868
print('\nargs: '+' '.join(args))
6969
main(args)
7070

71-
dst_names = glob.glob(path_out+"*overlay_none*.png")
72-
assert len(dst_names) == 6
71+
dst_names = glob.glob(path_out+"*multi*.png")
72+
assert len(dst_names) == 12
7373
dst0 = pyvips.Image.new_from_file(dst_names[0])
7474
assert dst0.width == dst0.height == 1024
75-
assert dst0.bands == 4
75+
assert dst0.bands == 3
7676

7777

7878
def test_main_none_inplace(capsys):
@@ -87,7 +87,7 @@ def test_main_none_inplace(capsys):
8787
assert dst0.width == dst0.height == 256
8888

8989
def test_main_none_sub(capsys):
90-
args = ['-s', '256', '-t', 'optan', path_out+'bm.tif', path_out+'sub/warped.png']
90+
args = ['-s', '256', '-t', 'otc', path_out+'bm.tif', path_out+'sub/warped.png']
9191
print('\nargs: '+' '.join(args))
9292
main(args)
9393

@@ -137,7 +137,7 @@ def test_main_crossL(capsys):
137137
assert dst0.width == 1024 * 4 and dst0.height == 1024 * 3
138138

139139
def test_main_crossR(capsys):
140-
args = ['-l','crossR','-t','optan', path_in+'basemap.tif', path_out+'basemap_crossR.png']
140+
args = ['-l','crossR','-t','otc', path_in+'basemap.tif', path_out+'basemap_crossR.png']
141141
print('\nargs: '+' '.join(args))
142142
main(args)
143143

0 commit comments

Comments
 (0)