xlwings-utils 0.0.7.post3__tar.gz → 0.0.7.post4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xlwings-utils might be problematic. Click here for more details.
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/PKG-INFO +21 -14
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/README.md +20 -13
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/pyproject.toml +1 -1
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/tests/test_xlwings_utils.py +35 -25
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils/xlwings_utils.py +53 -57
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/PKG-INFO +21 -14
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/setup.cfg +0 -0
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils/__init__.py +0 -0
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/SOURCES.txt +0 -0
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/dependency_links.txt +0 -0
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/requires.txt +0 -0
- {xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xlwings_utils
|
|
3
|
-
Version: 0.0.7.
|
|
3
|
+
Version: 0.0.7.post4
|
|
4
4
|
Summary: xlwings_utils
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/xlwings_utils
|
|
@@ -123,26 +123,33 @@ In this case, only the really processed rows are copied to the sheet.
|
|
|
123
123
|
|
|
124
124
|
The module has support for capturing stdout and -later- using showing the captured output on a sheet.
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
This is rather important as printing in xlwings lite to the UI pane is rather slow.
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
with xwu.capture_stdout():
|
|
130
|
-
...
|
|
131
|
-
```
|
|
132
|
-
and then the captured output can be copied to the screen, like
|
|
128
|
+
In order to capture stdout output, use
|
|
133
129
|
|
|
134
|
-
```can then be copied to a worksheet in a later stage.
|
|
135
|
-
sheet.range(4,5).value = xwu.captured_stdout_as_value()
|
|
136
|
-
```
|
|
137
130
|
|
|
138
|
-
|
|
131
|
+
```
|
|
132
|
+
with xwu.capture:
|
|
133
|
+
"""
|
|
134
|
+
code with print statements
|
|
135
|
+
"""
|
|
136
|
+
```
|
|
139
137
|
|
|
140
|
-
|
|
138
|
+
and then the captured output can be copied to a sheet, like
|
|
141
139
|
|
|
142
140
|
```
|
|
143
|
-
|
|
144
|
-
...
|
|
141
|
+
sheet.range(4,5).value = xwu.capture.value
|
|
145
142
|
```
|
|
143
|
+
Upon reading the value, the capture buffer will be emptied.
|
|
144
|
+
|
|
145
|
+
If you don't want the buffer to be emptied after accessing the value, use `xwu.capture.value_keep`.
|
|
146
|
+
|
|
147
|
+
The capture buffer can also be retrieved as a string with `xwu.capture.str` and `xwu.capture.str_keep`.
|
|
148
|
+
|
|
149
|
+
Clearing the captured stdout buffer can be done at any time with `xwu.capture.clear()`.
|
|
150
|
+
|
|
151
|
+
Normally, stdout will not be sent to the xlwings lite UI panel when captured with the `xwu.capture` context manager. However, if you specify `xwu.capture.include_print = True`, the output will be sent to the UI panel as well. Note that this setting remains active until a `xwu.capture.include_print = False` is issued.
|
|
152
|
+
|
|
146
153
|
|
|
147
154
|
## Contact info
|
|
148
155
|
|
|
@@ -109,26 +109,33 @@ In this case, only the really processed rows are copied to the sheet.
|
|
|
109
109
|
|
|
110
110
|
The module has support for capturing stdout and -later- using showing the captured output on a sheet.
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
This is rather important as printing in xlwings lite to the UI pane is rather slow.
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
with xwu.capture_stdout():
|
|
116
|
-
...
|
|
117
|
-
```
|
|
118
|
-
and then the captured output can be copied to the screen, like
|
|
114
|
+
In order to capture stdout output, use
|
|
119
115
|
|
|
120
|
-
```can then be copied to a worksheet in a later stage.
|
|
121
|
-
sheet.range(4,5).value = xwu.captured_stdout_as_value()
|
|
122
|
-
```
|
|
123
116
|
|
|
124
|
-
|
|
117
|
+
```
|
|
118
|
+
with xwu.capture:
|
|
119
|
+
"""
|
|
120
|
+
code with print statements
|
|
121
|
+
"""
|
|
122
|
+
```
|
|
125
123
|
|
|
126
|
-
|
|
124
|
+
and then the captured output can be copied to a sheet, like
|
|
127
125
|
|
|
128
126
|
```
|
|
129
|
-
|
|
130
|
-
...
|
|
127
|
+
sheet.range(4,5).value = xwu.capture.value
|
|
131
128
|
```
|
|
129
|
+
Upon reading the value, the capture buffer will be emptied.
|
|
130
|
+
|
|
131
|
+
If you don't want the buffer to be emptied after accessing the value, use `xwu.capture.value_keep`.
|
|
132
|
+
|
|
133
|
+
The capture buffer can also be retrieved as a string with `xwu.capture.str` and `xwu.capture.str_keep`.
|
|
134
|
+
|
|
135
|
+
Clearing the captured stdout buffer can be done at any time with `xwu.capture.clear()`.
|
|
136
|
+
|
|
137
|
+
Normally, stdout will not be sent to the xlwings lite UI panel when captured with the `xwu.capture` context manager. However, if you specify `xwu.capture.include_print = True`, the output will be sent to the UI panel as well. Note that this setting remains active until a `xwu.capture.include_print = False` is issued.
|
|
138
|
+
|
|
132
139
|
|
|
133
140
|
## Contact info
|
|
134
141
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
from pathlib import Path
|
|
4
|
+
import io
|
|
4
5
|
|
|
5
6
|
if __name__ == "__main__": # to make the tests run without the pytest cli
|
|
6
7
|
file_folder = os.path.dirname(__file__)
|
|
@@ -102,37 +103,46 @@ def test_raise():
|
|
|
102
103
|
this_block[1, 7] = 1
|
|
103
104
|
|
|
104
105
|
|
|
105
|
-
def
|
|
106
|
+
def test_capture(capsys):
|
|
106
107
|
print("abc")
|
|
107
108
|
print("def")
|
|
108
109
|
out, err = capsys.readouterr()
|
|
109
110
|
assert out == "abc\ndef\n"
|
|
110
|
-
assert xwu.
|
|
111
|
-
assert xwu.
|
|
111
|
+
assert xwu.capture.str_keep == ""
|
|
112
|
+
assert xwu.capture.value_keep == []
|
|
112
113
|
|
|
113
|
-
xwu.
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
with xwu.capture:
|
|
115
|
+
print("abc")
|
|
116
|
+
print("def")
|
|
116
117
|
out, err = capsys.readouterr()
|
|
117
|
-
assert out == "
|
|
118
|
-
|
|
119
|
-
assert xwu.
|
|
120
|
-
assert xwu.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
118
|
+
assert out == ""
|
|
119
|
+
assert xwu.capture.str_keep == "abc\ndef\n"
|
|
120
|
+
assert xwu.capture.value_keep == [['abc'], ['def']]
|
|
121
|
+
assert xwu.capture.str == "abc\ndef\n"
|
|
122
|
+
assert xwu.capture.value == []
|
|
123
|
+
|
|
124
|
+
with xwu.capture:
|
|
125
|
+
print("abc")
|
|
126
|
+
print("def")
|
|
127
|
+
out, err = capsys.readouterr()
|
|
128
|
+
xwu.capture.clear()
|
|
129
|
+
assert xwu.capture.str_keep == ""
|
|
130
|
+
|
|
131
|
+
with xwu.capture:
|
|
132
|
+
print("abc")
|
|
133
|
+
print("def")
|
|
134
|
+
with xwu.capture:
|
|
135
|
+
print("ghi")
|
|
136
|
+
print("jkl")
|
|
137
|
+
out, err = capsys.readouterr()
|
|
138
|
+
assert out == ""
|
|
139
|
+
assert xwu.capture.str_keep == "abc\ndef\nghi\njkl\n"
|
|
140
|
+
assert xwu.capture.value_keep == [['abc'], ['def'], ['ghi'], ['jkl']]
|
|
141
|
+
assert xwu.capture.value == [['abc'], ['def'], ['ghi'], ['jkl']]
|
|
142
|
+
assert xwu.capture.value == []
|
|
143
|
+
|
|
144
|
+
# include_print is not testable with pytest
|
|
145
|
+
|
|
136
146
|
if __name__ == "__main__":
|
|
137
147
|
pytest.main(["-vv", "-s", "-x", __file__])
|
|
138
148
|
|
|
@@ -13,8 +13,6 @@ from pathlib import Path
|
|
|
13
13
|
import os
|
|
14
14
|
import sys
|
|
15
15
|
|
|
16
|
-
_buffer=[]
|
|
17
|
-
|
|
18
16
|
dbx = None
|
|
19
17
|
Pythonista = sys.platform == "ios"
|
|
20
18
|
|
|
@@ -375,54 +373,8 @@ class block:
|
|
|
375
373
|
return f"block({self.value})"
|
|
376
374
|
|
|
377
375
|
|
|
378
|
-
def clear_captured_stdout(clear=True):
|
|
379
|
-
"""
|
|
380
|
-
empties the captured stdout
|
|
381
376
|
|
|
382
|
-
|
|
383
|
-
----------
|
|
384
|
-
clear : bool
|
|
385
|
-
if True (default), the capture buffer is emptied
|
|
386
|
-
|
|
387
|
-
if False: no action
|
|
388
|
-
"""
|
|
389
|
-
if clear:
|
|
390
|
-
_buffer.clear()
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
def captured_stdout_as_str(clear=True):
|
|
394
|
-
"""
|
|
395
|
-
returns the captured stdout as a string
|
|
396
|
-
|
|
397
|
-
Returns
|
|
398
|
-
-------
|
|
399
|
-
captured stdout : list
|
|
400
|
-
each line is an element of the list
|
|
401
|
-
"""
|
|
402
|
-
result = "".join(_buffer)
|
|
403
|
-
clear_captured_stdout(clear)
|
|
404
|
-
return result
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
def captured_stdout_as_value(clear=True):
|
|
408
|
-
"""
|
|
409
|
-
returns the captured stdout as a list of lists
|
|
410
|
-
|
|
411
|
-
Returns
|
|
412
|
-
-------
|
|
413
|
-
captured stdout : list of lists
|
|
414
|
-
each line is an element of the list
|
|
415
|
-
|
|
416
|
-
Note
|
|
417
|
-
----
|
|
418
|
-
This can be used directly to fill a xlwings range
|
|
419
|
-
"""
|
|
420
|
-
return [[line] for line in captured_stdout_as_str(clear).splitlines()]
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
class capture_stdout:
|
|
377
|
+
class _capture:
|
|
426
378
|
"""
|
|
427
379
|
specifies how to capture stdout
|
|
428
380
|
|
|
@@ -441,11 +393,10 @@ class capture_stdout:
|
|
|
441
393
|
...
|
|
442
394
|
"""
|
|
443
395
|
|
|
444
|
-
def __init__(self
|
|
396
|
+
def __init__(self):
|
|
445
397
|
self.stdout = sys.stdout
|
|
446
|
-
self.
|
|
447
|
-
|
|
448
|
-
_buffer.clear()
|
|
398
|
+
self._include_print = False
|
|
399
|
+
self._buffer=[]
|
|
449
400
|
|
|
450
401
|
def __enter__(self):
|
|
451
402
|
sys.stdout = self
|
|
@@ -454,14 +405,59 @@ class capture_stdout:
|
|
|
454
405
|
sys.stdout = self.stdout
|
|
455
406
|
|
|
456
407
|
def write(self, data):
|
|
457
|
-
_buffer.append(data)
|
|
458
|
-
if self.
|
|
408
|
+
self._buffer.append(data)
|
|
409
|
+
if self._include_print:
|
|
459
410
|
self.stdout.write(data)
|
|
460
411
|
|
|
461
412
|
def flush(self):
|
|
462
|
-
if self.
|
|
413
|
+
if self._include_print:
|
|
463
414
|
self.stdout.flush()
|
|
464
|
-
_buffer.append("\n")
|
|
415
|
+
self._buffer.append("\n")
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
@property
|
|
419
|
+
def value(self):
|
|
420
|
+
result=self.value_keep
|
|
421
|
+
self.clear()
|
|
422
|
+
return result
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@property
|
|
426
|
+
def value_keep(self):
|
|
427
|
+
result= [[line] for line in self.str_keep.splitlines()]
|
|
428
|
+
return result
|
|
429
|
+
|
|
430
|
+
@property
|
|
431
|
+
def str(self):
|
|
432
|
+
result = self.str_keep
|
|
433
|
+
self._buffer.clear()
|
|
434
|
+
return result
|
|
435
|
+
|
|
436
|
+
@property
|
|
437
|
+
def str_keep(self):
|
|
438
|
+
result = "".join(self._buffer)
|
|
439
|
+
return result
|
|
440
|
+
|
|
441
|
+
def clear(self):
|
|
442
|
+
self._buffer.clear()
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
@property
|
|
446
|
+
def include_print(self):
|
|
447
|
+
return self._include_print
|
|
448
|
+
|
|
449
|
+
@include_print.setter
|
|
450
|
+
def include_print(self, value):
|
|
451
|
+
self._include_print=value
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def reset():
|
|
456
|
+
capture.include_print=False
|
|
457
|
+
capture.clear()
|
|
458
|
+
|
|
459
|
+
capture=_capture()
|
|
460
|
+
|
|
465
461
|
|
|
466
462
|
if __name__ == "__main__":
|
|
467
463
|
...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xlwings_utils
|
|
3
|
-
Version: 0.0.7.
|
|
3
|
+
Version: 0.0.7.post4
|
|
4
4
|
Summary: xlwings_utils
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/xlwings_utils
|
|
@@ -123,26 +123,33 @@ In this case, only the really processed rows are copied to the sheet.
|
|
|
123
123
|
|
|
124
124
|
The module has support for capturing stdout and -later- using showing the captured output on a sheet.
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
This is rather important as printing in xlwings lite to the UI pane is rather slow.
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
with xwu.capture_stdout():
|
|
130
|
-
...
|
|
131
|
-
```
|
|
132
|
-
and then the captured output can be copied to the screen, like
|
|
128
|
+
In order to capture stdout output, use
|
|
133
129
|
|
|
134
|
-
```can then be copied to a worksheet in a later stage.
|
|
135
|
-
sheet.range(4,5).value = xwu.captured_stdout_as_value()
|
|
136
|
-
```
|
|
137
130
|
|
|
138
|
-
|
|
131
|
+
```
|
|
132
|
+
with xwu.capture:
|
|
133
|
+
"""
|
|
134
|
+
code with print statements
|
|
135
|
+
"""
|
|
136
|
+
```
|
|
139
137
|
|
|
140
|
-
|
|
138
|
+
and then the captured output can be copied to a sheet, like
|
|
141
139
|
|
|
142
140
|
```
|
|
143
|
-
|
|
144
|
-
...
|
|
141
|
+
sheet.range(4,5).value = xwu.capture.value
|
|
145
142
|
```
|
|
143
|
+
Upon reading the value, the capture buffer will be emptied.
|
|
144
|
+
|
|
145
|
+
If you don't want the buffer to be emptied after accessing the value, use `xwu.capture.value_keep`.
|
|
146
|
+
|
|
147
|
+
The capture buffer can also be retrieved as a string with `xwu.capture.str` and `xwu.capture.str_keep`.
|
|
148
|
+
|
|
149
|
+
Clearing the captured stdout buffer can be done at any time with `xwu.capture.clear()`.
|
|
150
|
+
|
|
151
|
+
Normally, stdout will not be sent to the xlwings lite UI panel when captured with the `xwu.capture` context manager. However, if you specify `xwu.capture.include_print = True`, the output will be sent to the UI panel as well. Note that this setting remains active until a `xwu.capture.include_print = False` is issued.
|
|
152
|
+
|
|
146
153
|
|
|
147
154
|
## Contact info
|
|
148
155
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{xlwings_utils-0.0.7.post3 → xlwings_utils-0.0.7.post4}/xlwings_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|