1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
|
%global _empty_manifest_terminate_build 0
Name: python-wasabi
Version: 1.1.1
Release: 1
Summary: A lightweight console printing and formatting toolkit
License: MIT
URL: https://github.com/explosion/wasabi
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/8d/d3/abe7d7d745657e43af711bdc58d4c9016f63546795ec9b5b62b2d9b89fa6/wasabi-1.1.1.tar.gz
BuildArch: noarch
Requires: python3-typing-extensions
Requires: python3-colorama
%description
a1 a2 a3
b1 b2 b3
```
| Argument | Type | Description | Default |
| ----------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable / dict | The data to render. Either a list of lists (one per row) or a dict for two-column tables. | |
| `header` | iterable | Optional header columns. | `None` |
| `footer` | iterable | Optional footer columns. | `None` |
| `divider` | bool | Show a divider line between header/footer and body. | `False` |
| `widths` | iterable / `"auto"` | Column widths in order. If `"auto"`, widths will be calculated automatically based on the largest value. | `"auto"` |
| `max_col` | int | Maximum column width. | `30` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | iterable / unicode | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). If If a string, value is used for all columns. | `None` |
| `multiline` | bool | If a cell value is a list of a tuple, render it on multiple lines, with one value per line. | `False` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `color_values` | dict | Add or overwrite color values, name mapped to value. | `None` |
| `fg_colors` | iterable | Foreground colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| `bg_colors` | iterable | Background colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted table. | |
#### <kbd>function</kbd> `row`
```python
from wasabi import row
data = ("a1", "a2", "a3")
formatted = row(data)
```
```
a1 a2 a3
```
| Argument | Type | Description | Default |
| ----------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable | The individual columns to format. | |
| `widths` | list / int / `"auto"` | Column widths, either one integer for all columns or an iterable of values. If "auto", widths will be calculated automatically based on the largest value. | `"auto"` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | list | Columns alignments in order. `"l"` (left), `"r"` (right) or `"c"` (center). | `None` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `fg_colors` | list | Foreground colors for the columns, in order. None can be specified for individual columns to retain the default foreground color. | `None` |
| `bg_colors` | list | Background colors for the columns, in order. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted row. | |
### <kbd>class</kbd> `TracebackPrinter`
Helper to output custom formatted tracebacks and error messages. Currently used
in [Thinc](https://github.com/explosion/thinc).
#### <kbd>method</kbd> `TracebackPrinter.__init__`
Initialize a traceback printer.
```python
from wasabi import TracebackPrinter
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
```
| Argument | Type | Description | Default |
| ----------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| `color_error` | str / int | Color name or code for errors (passed to `color` helper). | `"red"` |
| `color_tb` | str / int | Color name or code for traceback headline (passed to `color` helper). | `"blue"` |
| `color_highlight` | str / int | Color name or code for highlighted text (passed to `color` helper). | `"yellow"` |
| `indent` | int | Number of spaces to use for indentation. | `2` |
| `tb_base` | str | Name of directory to use to show relative paths. For example, `"thinc"` will look for the last occurence of `"/thinc/"` in a path and only show path to the right of it. | `None` |
| `tb_exclude` | tuple | List of filenames to exclude from traceback. | `tuple()` |
| **RETURNS** | `TracebackPrinter` | The traceback printer. | |
#### <kbd>method</kbd> `TracebackPrinter.__call__`
Output custom formatted tracebacks and errors.
```python
from wasabi import TracebackPrinter
import traceback
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
error = tb("Some error", "Error description", highlight="kwargs", tb=traceback.extract_stack())
raise ValueError(error)
```
```
Some error
Some error description
Traceback:
├─ <lambda> [61] in .env/lib/python3.6/site-packages/pluggy/manager.py
├─── _multicall [187] in .env/lib/python3.6/site-packages/pluggy/callers.py
└───── pytest_fixture_setup [969] in .env/lib/python3.6/site-packages/_pytest/fixtures.py
>>> result = call_fixture_func(fixturefunc, request, kwargs)
```
| Argument | Type | Description | Default |
| ----------- | -------- | ------------------------------------------------------------------------------------------ | ------- |
| `title` | str | The message title. | |
| `*texts` | str | Optional texts to print (one per line). | |
| `highlight` | str | Optional sequence to highlight in the traceback, e.g. the bad value that caused the error. | `False` |
| `tb` | iterable | The traceback, e.g. generated by `traceback.extract_stack()`. | `None` |
| **RETURNS** | str | The formatted traceback. Can be printed or raised by custom exception. | |
### <kbd>class</kbd> `MarkdownRenderer`
Helper to create Markdown-formatted content. Will store the blocks added to the Markdown document in order.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add("This is a paragraph")
print(md.text)
```
### <kbd>method</kbd> `MarkdownRenderer.__init__`
Initialize a Markdown renderer.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
```
| Argument | Type | Description | Default |
| ----------- | ------------------ | ------------------------------ | ------- |
| `no_emoji` | bool | Don't include emoji in titles. | `False` |
| **RETURNS** | `MarkdownRenderer` | The renderer. |
### <kbd>method</kbd> `MarkdownRenderer.add`
Add a block to the Markdown document.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add("This is a paragraph")
```
| Argument | Type | Description | Default |
| -------- | ---- | ------------------- | ------- |
| `text` | str | The content to add. | |
### <kbd>property</kbd> `MarkdownRenderer.text`
The rendered Markdown document.
```python
md = MarkdownRenderer()
md.add("This is a paragraph")
print(md.text)
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------- | ------- |
| **RETURNS** | str | The document as a single string. | |
### <kbd>method</kbd> `MarkdownRenderer.table`
Create a Markdown-formatted table.
```python
md = MarkdownRenderer()
table = md.table([("a", "b"), ("c", "d")], ["Column 1", "Column 2"])
md.add(table)
```
<!-- prettier-ignore -->
```markdown
| Column 1 | Column 2 |
| --- | --- |
| a | b |
| c | d |
```
| Argument | Type | Description | Default |
| ----------- | ----------------------- | ------------------------------------------------------------------------------------ | ------- |
| `data` | Iterable[Iterable[str]] | The body, one iterable per row, containig an interable of column contents. | |
| `header` | Iterable[str] | The column names. | |
| `aligns` | Iterable[str] | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). | `None` |
| **RETURNS** | str | The table. | |
### <kbd>method</kbd> `MarkdownRenderer.title`
Create a Markdown-formatted heading.
```python
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add(md.title(2, "Subheading", "💖"))
```
```markdown
# Hello world
## 💖 Subheading
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------------- | ------- |
| `level` | int | The heading level, e.g. `3` for `###`. | |
| `text` | str | The heading text. | |
| `emoji` | str | Optional emoji to show before heading. | `None` |
| **RETURNS** | str | The rendered title. | |
### <kbd>method</kbd> `MarkdownRenderer.list`
Create a Markdown-formatted non-nested list.
```python
md = MarkdownRenderer()
md.add(md.list(["item", "other item"]))
md.add(md.list(["first item", "second item"], numbered=True))
```
```markdown
- item
- other item
1. first item
2. second item
```
| Argument | Type | Description | Default |
| ----------- | ------------- | ------------------------------- | ------- |
| `items` | Iterable[str] | The list items. | |
| `numbered` | bool | Whether to use a numbered list. | `False` |
| **RETURNS** | str | The rendered list. | |
### <kbd>method</kbd> `MarkdownRenderer.link`
Create a Markdown-formatted link.
```python
md = MarkdownRenderer()
md.add(md.link("Google", "https://google.com"))
```
```markdown
[Google](https://google.com)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------ | ------- |
| `text` | str | The link text. | |
| `url` | str | The link URL. | |
| **RETURNS** | str | The rendered link. | |
### <kbd>method</kbd> `MarkdownRenderer.code_block`
Create a Markdown-formatted code block.
```python
md = MarkdownRenderer()
md.add(md.code_block("import spacy", "python"))
```
````markdown
```python
import spacy
```
````
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------ | ------- |
| `text` | str | The code text. | |
| `lang` | str | Optional code language. | `""` |
| **RETURNS** | str | The rendered code block. | |
### <kbd>method</kbd> `MarkdownRenderer.code`, `MarkdownRenderer.bold`, `MarkdownRenderer.italic`
Create a Markdown-formatted text.
```python
md = MarkdownRenderer()
md.add(md.code("import spacy"))
md.add(md.bold("Hello!"))
md.add(md.italic("Emphasis"))
```
```markdown
`import spacy`
**Hello!**
_Emphasis_
```
### Utilities
#### <kbd>function</kbd> `color`
```python
from wasabi import color
formatted = color("This is a text", fg="white", bg="green", bold=True)
```
| Argument | Type | Description | Default |
| ----------- | --------- | --------------------------------------------- | ------- |
| `text` | str | The text to be formatted. | - |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `None` |
| `bg` | str / int | Background color. String name or `0` - `256`. | `None` |
| `bold` | bool | Format the text in bold. | `False` |
| `underline` | bool | Format the text by underlining. | `False` |
| **RETURNS** | str | The formatted string. | |
#### <kbd>function</kbd> `wrap`
```python
from wasabi import wrap
wrapped = wrap("Hello world, this is a text.", indent=2)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------------------------ | ------- |
| `text` | str | The text to wrap. | - |
| `wrap_max` | int | Maximum line width, including indentation. | `80` |
| `indent` | int | Number of spaces used for indentation. | `4` |
| **RETURNS** | str | The wrapped text with line breaks. | |
#### <kbd>function</kbd> `diff_strings`
```python
from wasabi import diff_strings
diff = diff_strings("hello world!", "helloo world")
```
| Argument | Type | Description | Default |
| ----------- | --------- | ---------------------------------------------------------------------------- | ------------------ |
| `a` | str | The first string to diff. |
| `b` | str | The second string to diff. |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `"black"` |
| `bg` | tuple | Background colors as `(insert, delete)` tuple of string name or `0` - `256`. | `("green", "red")` |
| **RETURNS** | str | The formatted diff. | |
### Environment variables
Wasabi also respects the following environment variables. The prefix can be
customised on the `Printer` via the `env_prefix` argument. For example, setting
`env_prefix="SPACY"` will expect the environment variable `SPACY_LOG_FRIENDLY`.
| Name | Description |
| ---------------------- | ------------------------------------------------------ |
| `ANSI_COLORS_DISABLED` | Disable colors. |
| `WASABI_LOG_FRIENDLY` | Make output nicer for logs (no colors, no animations). |
| `WASABI_NO_PRETTY` | Disable pretty printing, e.g. colors and icons. |
## 🔔 Run tests
Fork or clone the repo, make sure you have `pytest` installed and then run it on
the package directory. The tests are located in
[`/wasabi/tests`](/wasabi/tests).
```bash
pip install pytest
cd wasabi
python -m pytest wasabi
```
%package -n python3-wasabi
Summary: A lightweight console printing and formatting toolkit
Provides: python-wasabi
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-wasabi
a1 a2 a3
b1 b2 b3
```
| Argument | Type | Description | Default |
| ----------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable / dict | The data to render. Either a list of lists (one per row) or a dict for two-column tables. | |
| `header` | iterable | Optional header columns. | `None` |
| `footer` | iterable | Optional footer columns. | `None` |
| `divider` | bool | Show a divider line between header/footer and body. | `False` |
| `widths` | iterable / `"auto"` | Column widths in order. If `"auto"`, widths will be calculated automatically based on the largest value. | `"auto"` |
| `max_col` | int | Maximum column width. | `30` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | iterable / unicode | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). If If a string, value is used for all columns. | `None` |
| `multiline` | bool | If a cell value is a list of a tuple, render it on multiple lines, with one value per line. | `False` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `color_values` | dict | Add or overwrite color values, name mapped to value. | `None` |
| `fg_colors` | iterable | Foreground colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| `bg_colors` | iterable | Background colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted table. | |
#### <kbd>function</kbd> `row`
```python
from wasabi import row
data = ("a1", "a2", "a3")
formatted = row(data)
```
```
a1 a2 a3
```
| Argument | Type | Description | Default |
| ----------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable | The individual columns to format. | |
| `widths` | list / int / `"auto"` | Column widths, either one integer for all columns or an iterable of values. If "auto", widths will be calculated automatically based on the largest value. | `"auto"` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | list | Columns alignments in order. `"l"` (left), `"r"` (right) or `"c"` (center). | `None` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `fg_colors` | list | Foreground colors for the columns, in order. None can be specified for individual columns to retain the default foreground color. | `None` |
| `bg_colors` | list | Background colors for the columns, in order. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted row. | |
### <kbd>class</kbd> `TracebackPrinter`
Helper to output custom formatted tracebacks and error messages. Currently used
in [Thinc](https://github.com/explosion/thinc).
#### <kbd>method</kbd> `TracebackPrinter.__init__`
Initialize a traceback printer.
```python
from wasabi import TracebackPrinter
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
```
| Argument | Type | Description | Default |
| ----------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| `color_error` | str / int | Color name or code for errors (passed to `color` helper). | `"red"` |
| `color_tb` | str / int | Color name or code for traceback headline (passed to `color` helper). | `"blue"` |
| `color_highlight` | str / int | Color name or code for highlighted text (passed to `color` helper). | `"yellow"` |
| `indent` | int | Number of spaces to use for indentation. | `2` |
| `tb_base` | str | Name of directory to use to show relative paths. For example, `"thinc"` will look for the last occurence of `"/thinc/"` in a path and only show path to the right of it. | `None` |
| `tb_exclude` | tuple | List of filenames to exclude from traceback. | `tuple()` |
| **RETURNS** | `TracebackPrinter` | The traceback printer. | |
#### <kbd>method</kbd> `TracebackPrinter.__call__`
Output custom formatted tracebacks and errors.
```python
from wasabi import TracebackPrinter
import traceback
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
error = tb("Some error", "Error description", highlight="kwargs", tb=traceback.extract_stack())
raise ValueError(error)
```
```
Some error
Some error description
Traceback:
├─ <lambda> [61] in .env/lib/python3.6/site-packages/pluggy/manager.py
├─── _multicall [187] in .env/lib/python3.6/site-packages/pluggy/callers.py
└───── pytest_fixture_setup [969] in .env/lib/python3.6/site-packages/_pytest/fixtures.py
>>> result = call_fixture_func(fixturefunc, request, kwargs)
```
| Argument | Type | Description | Default |
| ----------- | -------- | ------------------------------------------------------------------------------------------ | ------- |
| `title` | str | The message title. | |
| `*texts` | str | Optional texts to print (one per line). | |
| `highlight` | str | Optional sequence to highlight in the traceback, e.g. the bad value that caused the error. | `False` |
| `tb` | iterable | The traceback, e.g. generated by `traceback.extract_stack()`. | `None` |
| **RETURNS** | str | The formatted traceback. Can be printed or raised by custom exception. | |
### <kbd>class</kbd> `MarkdownRenderer`
Helper to create Markdown-formatted content. Will store the blocks added to the Markdown document in order.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add("This is a paragraph")
print(md.text)
```
### <kbd>method</kbd> `MarkdownRenderer.__init__`
Initialize a Markdown renderer.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
```
| Argument | Type | Description | Default |
| ----------- | ------------------ | ------------------------------ | ------- |
| `no_emoji` | bool | Don't include emoji in titles. | `False` |
| **RETURNS** | `MarkdownRenderer` | The renderer. |
### <kbd>method</kbd> `MarkdownRenderer.add`
Add a block to the Markdown document.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add("This is a paragraph")
```
| Argument | Type | Description | Default |
| -------- | ---- | ------------------- | ------- |
| `text` | str | The content to add. | |
### <kbd>property</kbd> `MarkdownRenderer.text`
The rendered Markdown document.
```python
md = MarkdownRenderer()
md.add("This is a paragraph")
print(md.text)
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------- | ------- |
| **RETURNS** | str | The document as a single string. | |
### <kbd>method</kbd> `MarkdownRenderer.table`
Create a Markdown-formatted table.
```python
md = MarkdownRenderer()
table = md.table([("a", "b"), ("c", "d")], ["Column 1", "Column 2"])
md.add(table)
```
<!-- prettier-ignore -->
```markdown
| Column 1 | Column 2 |
| --- | --- |
| a | b |
| c | d |
```
| Argument | Type | Description | Default |
| ----------- | ----------------------- | ------------------------------------------------------------------------------------ | ------- |
| `data` | Iterable[Iterable[str]] | The body, one iterable per row, containig an interable of column contents. | |
| `header` | Iterable[str] | The column names. | |
| `aligns` | Iterable[str] | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). | `None` |
| **RETURNS** | str | The table. | |
### <kbd>method</kbd> `MarkdownRenderer.title`
Create a Markdown-formatted heading.
```python
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add(md.title(2, "Subheading", "💖"))
```
```markdown
# Hello world
## 💖 Subheading
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------------- | ------- |
| `level` | int | The heading level, e.g. `3` for `###`. | |
| `text` | str | The heading text. | |
| `emoji` | str | Optional emoji to show before heading. | `None` |
| **RETURNS** | str | The rendered title. | |
### <kbd>method</kbd> `MarkdownRenderer.list`
Create a Markdown-formatted non-nested list.
```python
md = MarkdownRenderer()
md.add(md.list(["item", "other item"]))
md.add(md.list(["first item", "second item"], numbered=True))
```
```markdown
- item
- other item
1. first item
2. second item
```
| Argument | Type | Description | Default |
| ----------- | ------------- | ------------------------------- | ------- |
| `items` | Iterable[str] | The list items. | |
| `numbered` | bool | Whether to use a numbered list. | `False` |
| **RETURNS** | str | The rendered list. | |
### <kbd>method</kbd> `MarkdownRenderer.link`
Create a Markdown-formatted link.
```python
md = MarkdownRenderer()
md.add(md.link("Google", "https://google.com"))
```
```markdown
[Google](https://google.com)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------ | ------- |
| `text` | str | The link text. | |
| `url` | str | The link URL. | |
| **RETURNS** | str | The rendered link. | |
### <kbd>method</kbd> `MarkdownRenderer.code_block`
Create a Markdown-formatted code block.
```python
md = MarkdownRenderer()
md.add(md.code_block("import spacy", "python"))
```
````markdown
```python
import spacy
```
````
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------ | ------- |
| `text` | str | The code text. | |
| `lang` | str | Optional code language. | `""` |
| **RETURNS** | str | The rendered code block. | |
### <kbd>method</kbd> `MarkdownRenderer.code`, `MarkdownRenderer.bold`, `MarkdownRenderer.italic`
Create a Markdown-formatted text.
```python
md = MarkdownRenderer()
md.add(md.code("import spacy"))
md.add(md.bold("Hello!"))
md.add(md.italic("Emphasis"))
```
```markdown
`import spacy`
**Hello!**
_Emphasis_
```
### Utilities
#### <kbd>function</kbd> `color`
```python
from wasabi import color
formatted = color("This is a text", fg="white", bg="green", bold=True)
```
| Argument | Type | Description | Default |
| ----------- | --------- | --------------------------------------------- | ------- |
| `text` | str | The text to be formatted. | - |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `None` |
| `bg` | str / int | Background color. String name or `0` - `256`. | `None` |
| `bold` | bool | Format the text in bold. | `False` |
| `underline` | bool | Format the text by underlining. | `False` |
| **RETURNS** | str | The formatted string. | |
#### <kbd>function</kbd> `wrap`
```python
from wasabi import wrap
wrapped = wrap("Hello world, this is a text.", indent=2)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------------------------ | ------- |
| `text` | str | The text to wrap. | - |
| `wrap_max` | int | Maximum line width, including indentation. | `80` |
| `indent` | int | Number of spaces used for indentation. | `4` |
| **RETURNS** | str | The wrapped text with line breaks. | |
#### <kbd>function</kbd> `diff_strings`
```python
from wasabi import diff_strings
diff = diff_strings("hello world!", "helloo world")
```
| Argument | Type | Description | Default |
| ----------- | --------- | ---------------------------------------------------------------------------- | ------------------ |
| `a` | str | The first string to diff. |
| `b` | str | The second string to diff. |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `"black"` |
| `bg` | tuple | Background colors as `(insert, delete)` tuple of string name or `0` - `256`. | `("green", "red")` |
| **RETURNS** | str | The formatted diff. | |
### Environment variables
Wasabi also respects the following environment variables. The prefix can be
customised on the `Printer` via the `env_prefix` argument. For example, setting
`env_prefix="SPACY"` will expect the environment variable `SPACY_LOG_FRIENDLY`.
| Name | Description |
| ---------------------- | ------------------------------------------------------ |
| `ANSI_COLORS_DISABLED` | Disable colors. |
| `WASABI_LOG_FRIENDLY` | Make output nicer for logs (no colors, no animations). |
| `WASABI_NO_PRETTY` | Disable pretty printing, e.g. colors and icons. |
## 🔔 Run tests
Fork or clone the repo, make sure you have `pytest` installed and then run it on
the package directory. The tests are located in
[`/wasabi/tests`](/wasabi/tests).
```bash
pip install pytest
cd wasabi
python -m pytest wasabi
```
%package help
Summary: Development documents and examples for wasabi
Provides: python3-wasabi-doc
%description help
a1 a2 a3
b1 b2 b3
```
| Argument | Type | Description | Default |
| ----------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable / dict | The data to render. Either a list of lists (one per row) or a dict for two-column tables. | |
| `header` | iterable | Optional header columns. | `None` |
| `footer` | iterable | Optional footer columns. | `None` |
| `divider` | bool | Show a divider line between header/footer and body. | `False` |
| `widths` | iterable / `"auto"` | Column widths in order. If `"auto"`, widths will be calculated automatically based on the largest value. | `"auto"` |
| `max_col` | int | Maximum column width. | `30` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | iterable / unicode | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). If If a string, value is used for all columns. | `None` |
| `multiline` | bool | If a cell value is a list of a tuple, render it on multiple lines, with one value per line. | `False` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `color_values` | dict | Add or overwrite color values, name mapped to value. | `None` |
| `fg_colors` | iterable | Foreground colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| `bg_colors` | iterable | Background colors, one per column. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted table. | |
#### <kbd>function</kbd> `row`
```python
from wasabi import row
data = ("a1", "a2", "a3")
formatted = row(data)
```
```
a1 a2 a3
```
| Argument | Type | Description | Default |
| ----------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `data` | iterable | The individual columns to format. | |
| `widths` | list / int / `"auto"` | Column widths, either one integer for all columns or an iterable of values. If "auto", widths will be calculated automatically based on the largest value. | `"auto"` |
| `spacing` | int | Number of spaces between columns. | `3` |
| `aligns` | list | Columns alignments in order. `"l"` (left), `"r"` (right) or `"c"` (center). | `None` |
| `env_prefix` | unicode | Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. | `"WASABI"` |
| `fg_colors` | list | Foreground colors for the columns, in order. None can be specified for individual columns to retain the default foreground color. | `None` |
| `bg_colors` | list | Background colors for the columns, in order. None can be specified for individual columns to retain the default background color. | `None` |
| **RETURNS** | str | The formatted row. | |
### <kbd>class</kbd> `TracebackPrinter`
Helper to output custom formatted tracebacks and error messages. Currently used
in [Thinc](https://github.com/explosion/thinc).
#### <kbd>method</kbd> `TracebackPrinter.__init__`
Initialize a traceback printer.
```python
from wasabi import TracebackPrinter
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
```
| Argument | Type | Description | Default |
| ----------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| `color_error` | str / int | Color name or code for errors (passed to `color` helper). | `"red"` |
| `color_tb` | str / int | Color name or code for traceback headline (passed to `color` helper). | `"blue"` |
| `color_highlight` | str / int | Color name or code for highlighted text (passed to `color` helper). | `"yellow"` |
| `indent` | int | Number of spaces to use for indentation. | `2` |
| `tb_base` | str | Name of directory to use to show relative paths. For example, `"thinc"` will look for the last occurence of `"/thinc/"` in a path and only show path to the right of it. | `None` |
| `tb_exclude` | tuple | List of filenames to exclude from traceback. | `tuple()` |
| **RETURNS** | `TracebackPrinter` | The traceback printer. | |
#### <kbd>method</kbd> `TracebackPrinter.__call__`
Output custom formatted tracebacks and errors.
```python
from wasabi import TracebackPrinter
import traceback
tb = TracebackPrinter(tb_base="thinc", tb_exclude=("check.py",))
error = tb("Some error", "Error description", highlight="kwargs", tb=traceback.extract_stack())
raise ValueError(error)
```
```
Some error
Some error description
Traceback:
├─ <lambda> [61] in .env/lib/python3.6/site-packages/pluggy/manager.py
├─── _multicall [187] in .env/lib/python3.6/site-packages/pluggy/callers.py
└───── pytest_fixture_setup [969] in .env/lib/python3.6/site-packages/_pytest/fixtures.py
>>> result = call_fixture_func(fixturefunc, request, kwargs)
```
| Argument | Type | Description | Default |
| ----------- | -------- | ------------------------------------------------------------------------------------------ | ------- |
| `title` | str | The message title. | |
| `*texts` | str | Optional texts to print (one per line). | |
| `highlight` | str | Optional sequence to highlight in the traceback, e.g. the bad value that caused the error. | `False` |
| `tb` | iterable | The traceback, e.g. generated by `traceback.extract_stack()`. | `None` |
| **RETURNS** | str | The formatted traceback. Can be printed or raised by custom exception. | |
### <kbd>class</kbd> `MarkdownRenderer`
Helper to create Markdown-formatted content. Will store the blocks added to the Markdown document in order.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add("This is a paragraph")
print(md.text)
```
### <kbd>method</kbd> `MarkdownRenderer.__init__`
Initialize a Markdown renderer.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
```
| Argument | Type | Description | Default |
| ----------- | ------------------ | ------------------------------ | ------- |
| `no_emoji` | bool | Don't include emoji in titles. | `False` |
| **RETURNS** | `MarkdownRenderer` | The renderer. |
### <kbd>method</kbd> `MarkdownRenderer.add`
Add a block to the Markdown document.
```python
from wasabi import MarkdownRenderer
md = MarkdownRenderer()
md.add("This is a paragraph")
```
| Argument | Type | Description | Default |
| -------- | ---- | ------------------- | ------- |
| `text` | str | The content to add. | |
### <kbd>property</kbd> `MarkdownRenderer.text`
The rendered Markdown document.
```python
md = MarkdownRenderer()
md.add("This is a paragraph")
print(md.text)
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------- | ------- |
| **RETURNS** | str | The document as a single string. | |
### <kbd>method</kbd> `MarkdownRenderer.table`
Create a Markdown-formatted table.
```python
md = MarkdownRenderer()
table = md.table([("a", "b"), ("c", "d")], ["Column 1", "Column 2"])
md.add(table)
```
<!-- prettier-ignore -->
```markdown
| Column 1 | Column 2 |
| --- | --- |
| a | b |
| c | d |
```
| Argument | Type | Description | Default |
| ----------- | ----------------------- | ------------------------------------------------------------------------------------ | ------- |
| `data` | Iterable[Iterable[str]] | The body, one iterable per row, containig an interable of column contents. | |
| `header` | Iterable[str] | The column names. | |
| `aligns` | Iterable[str] | Columns alignments in order. `"l"` (left, default), `"r"` (right) or `"c"` (center). | `None` |
| **RETURNS** | str | The table. | |
### <kbd>method</kbd> `MarkdownRenderer.title`
Create a Markdown-formatted heading.
```python
md = MarkdownRenderer()
md.add(md.title(1, "Hello world"))
md.add(md.title(2, "Subheading", "💖"))
```
```markdown
# Hello world
## 💖 Subheading
```
| Argument | Type | Description | Default |
| ----------- | ---- | -------------------------------------- | ------- |
| `level` | int | The heading level, e.g. `3` for `###`. | |
| `text` | str | The heading text. | |
| `emoji` | str | Optional emoji to show before heading. | `None` |
| **RETURNS** | str | The rendered title. | |
### <kbd>method</kbd> `MarkdownRenderer.list`
Create a Markdown-formatted non-nested list.
```python
md = MarkdownRenderer()
md.add(md.list(["item", "other item"]))
md.add(md.list(["first item", "second item"], numbered=True))
```
```markdown
- item
- other item
1. first item
2. second item
```
| Argument | Type | Description | Default |
| ----------- | ------------- | ------------------------------- | ------- |
| `items` | Iterable[str] | The list items. | |
| `numbered` | bool | Whether to use a numbered list. | `False` |
| **RETURNS** | str | The rendered list. | |
### <kbd>method</kbd> `MarkdownRenderer.link`
Create a Markdown-formatted link.
```python
md = MarkdownRenderer()
md.add(md.link("Google", "https://google.com"))
```
```markdown
[Google](https://google.com)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------ | ------- |
| `text` | str | The link text. | |
| `url` | str | The link URL. | |
| **RETURNS** | str | The rendered link. | |
### <kbd>method</kbd> `MarkdownRenderer.code_block`
Create a Markdown-formatted code block.
```python
md = MarkdownRenderer()
md.add(md.code_block("import spacy", "python"))
```
````markdown
```python
import spacy
```
````
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------ | ------- |
| `text` | str | The code text. | |
| `lang` | str | Optional code language. | `""` |
| **RETURNS** | str | The rendered code block. | |
### <kbd>method</kbd> `MarkdownRenderer.code`, `MarkdownRenderer.bold`, `MarkdownRenderer.italic`
Create a Markdown-formatted text.
```python
md = MarkdownRenderer()
md.add(md.code("import spacy"))
md.add(md.bold("Hello!"))
md.add(md.italic("Emphasis"))
```
```markdown
`import spacy`
**Hello!**
_Emphasis_
```
### Utilities
#### <kbd>function</kbd> `color`
```python
from wasabi import color
formatted = color("This is a text", fg="white", bg="green", bold=True)
```
| Argument | Type | Description | Default |
| ----------- | --------- | --------------------------------------------- | ------- |
| `text` | str | The text to be formatted. | - |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `None` |
| `bg` | str / int | Background color. String name or `0` - `256`. | `None` |
| `bold` | bool | Format the text in bold. | `False` |
| `underline` | bool | Format the text by underlining. | `False` |
| **RETURNS** | str | The formatted string. | |
#### <kbd>function</kbd> `wrap`
```python
from wasabi import wrap
wrapped = wrap("Hello world, this is a text.", indent=2)
```
| Argument | Type | Description | Default |
| ----------- | ---- | ------------------------------------------ | ------- |
| `text` | str | The text to wrap. | - |
| `wrap_max` | int | Maximum line width, including indentation. | `80` |
| `indent` | int | Number of spaces used for indentation. | `4` |
| **RETURNS** | str | The wrapped text with line breaks. | |
#### <kbd>function</kbd> `diff_strings`
```python
from wasabi import diff_strings
diff = diff_strings("hello world!", "helloo world")
```
| Argument | Type | Description | Default |
| ----------- | --------- | ---------------------------------------------------------------------------- | ------------------ |
| `a` | str | The first string to diff. |
| `b` | str | The second string to diff. |
| `fg` | str / int | Foreground color. String name or `0` - `256`. | `"black"` |
| `bg` | tuple | Background colors as `(insert, delete)` tuple of string name or `0` - `256`. | `("green", "red")` |
| **RETURNS** | str | The formatted diff. | |
### Environment variables
Wasabi also respects the following environment variables. The prefix can be
customised on the `Printer` via the `env_prefix` argument. For example, setting
`env_prefix="SPACY"` will expect the environment variable `SPACY_LOG_FRIENDLY`.
| Name | Description |
| ---------------------- | ------------------------------------------------------ |
| `ANSI_COLORS_DISABLED` | Disable colors. |
| `WASABI_LOG_FRIENDLY` | Make output nicer for logs (no colors, no animations). |
| `WASABI_NO_PRETTY` | Disable pretty printing, e.g. colors and icons. |
## 🔔 Run tests
Fork or clone the repo, make sure you have `pytest` installed and then run it on
the package directory. The tests are located in
[`/wasabi/tests`](/wasabi/tests).
```bash
pip install pytest
cd wasabi
python -m pytest wasabi
```
%prep
%autosetup -n wasabi-1.1.1
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-wasabi -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1.1-1
- Package Spec generated
|