Skip to content

Commit 559b943

Browse files
author
Andy Landy
committed
new version 2.5.0
1 parent ee98907 commit 559b943

File tree

158 files changed

+2519
-1190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+2519
-1190
lines changed

.github/workflows/dev-test.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ on:
77
branches:
88
- '*'
99
jobs:
10-
unit-tests:
10+
tests:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, windows-latest]
15-
python-version: [3.8, 3.9]
15+
# 3.13 not available yet somehow
16+
# 3.7 has issues with multiline expressions
17+
# 3.6- not found for ubuntu-latest
18+
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
1619
steps:
1720
- name: Set up Python ${{ matrix.python-version }}
1821
uses: actions/setup-python@v1
@@ -22,7 +25,7 @@ jobs:
2225
- name: Install dependencies
2326
run: |
2427
python -m pip install --upgrade pip
25-
pip install flake8 pytest-cov ipython
28+
pip install flake8 pytest-cov ipython notebook==6.2.0
2629
2730
- name: Checkout code
2831
uses: actions/checkout@v2
@@ -33,9 +36,24 @@ jobs:
3336
3437
- name: Test with pytest
3538
run: |
36-
python -m pytest -vv --cov=./traceback_with_variables --cov-report=xml
39+
python -m pytest -vv --cov=traceback_with_variables --cov-report=json
3740
38-
- name: Upload Codecov
39-
uses: codecov/codecov-action@v1
41+
- name: Upload coverage report
42+
uses: actions/upload-artifact@v4
4043
with:
41-
file: ./coverage.xml
44+
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
45+
path: coverage.json
46+
47+
coverage:
48+
needs: tests
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
53+
- name: Download all coverage reports
54+
uses: actions/download-artifact@v4
55+
with:
56+
path: coverage-reports
57+
58+
- name: Check coverage
59+
run: python3 check_coverage_reports.py --inp-dir coverage-reports --max-allowed-num-uncovered-lines 0

.github/workflows/master-test.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Dev-Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- 'master'
6+
push:
7+
branches:
8+
- 'master'
9+
jobs:
10+
tests:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest]
15+
# 3.13 not available yet somehow
16+
# 3.7 has issues with multiline expressions
17+
# 3.6- not found for ubuntu-latest
18+
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
19+
steps:
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v1
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install flake8 pytest-cov ipython notebook==6.2.0
29+
30+
- name: Checkout code
31+
uses: actions/checkout@v2
32+
33+
- name: Lint with flake8
34+
run: |
35+
flake8 traceback_with_variables --count --show-source --statistics --max-line-length=127
36+
37+
- name: Test with pytest
38+
run: |
39+
python -m pytest -vv --cov=traceback_with_variables --cov-report=json
40+
41+
- name: Upload coverage report
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
45+
path: coverage.json
46+
47+
coverage:
48+
needs: tests
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
53+
- name: Download all coverage reports
54+
uses: actions/download-artifact@v4
55+
with:
56+
path: coverage-reports
57+
58+
- name: Check coverage
59+
run: python3 check_coverage_reports.py --inp-dir coverage-reports --max-allowed-num-uncovered-lines 0

.github/workflows/test.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.lgtm.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.5.0
4+
- Add short names for frequently used things like `a` and `fmt`
5+
- Fixed some bugs
6+
7+
## 2.0.4
8+
- ...
9+
310
## 2.0.3
411
- Fixed tests in Windows/Mac
512
- Removed `sys` from globals in the "main" mode
@@ -11,18 +18,15 @@
1118
- Some renames
1219
- Add `Format` and pack all style arguments inside it
1320
- Add `before` and `after` instead of `num_context_lines`
14-
- Add `README.tmpl`
15-
- Add `print_tb()` to use out of try/except
1621
- Add `skip-files-except` and `brief-files-except`
1722
- Add warning on sensitive data
1823
- Add colab badge
19-
- Make a single `customized` example
24+
- Add a single `customized` example
2025
- Add `custom_var_printers`
2126
- Add past exceptions discovery
2227
- Add current tb printing
2328
- Rm outer try block in `core`
2429
- Add `format_*` functions to `core`
2530
- Rename `*_tb` functions to `*_exc`
2631
- Add `*_cur_tb*` methods
27-
- Add contributing md
2832

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
<p align="center">
77
<a href="https://github.com/andy-landy/traceback_with_variables/actions"><img alt="Actions Status" src="https://github.com/andy-landy/traceback_with_variables/workflows/Tests/badge.svg"></a>
8-
<a href="https://codecov.io/gh/andy-landy/traceback_with_variables"><img alt="Codecov" src="https://codecov.io/gh/andy-landy/traceback_with_variables/branch/master/graph/badge.svg"></a>
9-
<a href="https://lgtm.com/projects/g/andy-landy/traceback_with_variables/context:python"><img alt="Language grade: Python" src="https://img.shields.io/lgtm/grade/python/g/andy-landy/traceback_with_variables.svg"/></a>
8+
<a href="https://github.com/andy-landy/traceback_with_variables/blob/master/.github/workflows/dev-test.yml#L59"><img title="code tests coverage is 100%" alt="code tests coverage is 100%" src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"></a>
109
<a href="https://github.com/andy-landy/traceback_with_variables/tree/master/LICENSE"><img alt="License: MIT" src="https://img.shields.io/github/license/andy-landy/traceback_with_variables?color=informational"></a>
10+
<a href="https://pepy.tech/project/traceback-with-variables"><img alt="Downloads" src="https://static.pepy.tech/badge/traceback-with-variables"></a>
1111
<a href="https://pypi.org/project/traceback-with-variables"><img alt="PyPI" src="https://img.shields.io/pypi/v/traceback-with-variables"></a>
1212
<a href="https://anaconda.org/conda-forge/traceback-with-variables"><img src="https://img.shields.io/conda/vn/conda-forge/traceback-with-variables"></a>
13-
<a href="https://pypi.org/project/traceback-with-variables"><img alt="PyPI" src="https://img.shields.io/badge/python-3.5+-blue.svg"></a>
13+
<a href="https://pypi.org/project/traceback-with-variables"><img alt="PyPI" src="https://img.shields.io/badge/python-3.6+-blue.svg"></a>
1414
<a href="https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling"><img title="windows, mac, linux etc." alt="Platform" src="https://img.shields.io/badge/platform-all-blue.svg"></a>
1515
<a href="https://github.com/andy-landy/traceback_with_variables/tree/master/traceback_with_variables/override.py#L9"><img title="type hints everywhere" alt="Annotations coverage" src="https://img.shields.io/badge/type--hints-100%25-blueviolet.svg"></a>
1616
<a href="https://github.com/andy-landy/traceback_with_variables/tree/master/traceback_with_variables/override.py#L8"><img title="no obscure objects, only transparent functions and data classes" alt="No-OOP" src="https://img.shields.io/badge/no OOP-100%25-blueviolet.svg"></a>
@@ -40,17 +40,17 @@ _Contents:_ **[Installation](#installation)** | **[🚀 Quick Start](#-quick-sta
4040

4141
---
4242

43-
> :warning: **I'm open to update this module to meet new use cases and to make using it easier and fun**: so any proposal or advice or warning is very welcome and will be taken into account of course. When I started it I wanted to make a tool meeting all standard use cases. I think in this particular domain this is rather achievable, so I'll try. Note `next_version` branch also. Have fun!
43+
> :warning: **This module is actively updated and has a substantial list of features to add this week**: so any proposal or advice or warning is very welcome and will be taken into account of course. When I started it I wanted to make a tool meeting all standard use cases. I think in this particular domain this is rather achievable, so I'll try. Note `next_version` branch also. Have fun!
4444
4545
---
4646

4747
### Installation
4848

4949
```
50-
pip install traceback-with-variables==2.0.4
50+
pip install traceback-with-variables==2.1.0
5151
```
5252
```
53-
conda install -c conda-forge traceback-with-variables=2.0.4
53+
conda install -c conda-forge traceback-with-variables=2.1.0
5454
```
5555

5656
### 🚀 Quick Start
@@ -106,8 +106,8 @@ Using a logger [<a href="https://github.com/andy-landy/traceback_with_variables/
106106

107107
<a href="https://github.com/andy-landy/traceback_with_variables/tree/master/examples/format_customized.py">Customize</a> any of the previous examples:
108108
```python
109-
default_format.max_value_str_len = 10000
110-
default_format.skip_files_except = 'my_project'
109+
fmt.max_value_str_len = 10000
110+
fmt.skip_files_except = 'my_project'
111111
```
112112

113113

@@ -245,8 +245,7 @@ Using a logger [<a href="https://github.com/andy-landy/traceback_with_variables/
245245
* — Should I use it after debugging is over, i.e. *in production*?
246246

247247
Yes, of course! That way it might save you even more time (watch out for sensitive data
248-
like passwords and tokens in you logs). Note: you can deploy more serious frameworks,
249-
e.g. `Sentry` :)
248+
like passwords and tokens in you logs, use skip_files_except to hide code from libs AND custom_var_printers to hide own locals). Note: you can deploy more serious frameworks, e.g. `Sentry`
250249

251250
<br/>
252251

@@ -282,6 +281,8 @@ Using a logger [<a href="https://github.com/andy-landy/traceback_with_variables/
282281

283282
#### All functions have `fmt=` argument, a `Format` object with fields:
284283
* `max_value_str_len` max length of each variable string, -1 to disable, default=1000
284+
* `objects_details` depth of details of objects inspection
285+
* `ellipsis_rel_pos` when truncating long strings where to put the "...", from 0.0 to 1.0, default=0.7
285286
* `max_exc_str_len` max length of exception, should variable print fail, -1 to disable, default=10000
286287
* `before` number of code lines before the raising line, default=0
287288
* `after` number of code lines after the raising line, default=0

README.tmpl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
<p align="center">
77
<a href="{{ repo_url }}/actions"><img alt="Actions Status" src="{{ repo_url }}/workflows/Tests/badge.svg"></a>
8-
<a href="https://codecov.io/gh/{{ user_repo_name }}"><img alt="Codecov" src="https://codecov.io/gh/{{ user_repo_name }}/branch/master/graph/badge.svg"></a>
9-
<a href="https://lgtm.com/projects/g/{{ user_repo_name }}/context:python"><img alt="Language grade: Python" src="https://img.shields.io/lgtm/grade/python/g/{{ user_repo_name }}.svg"/></a>
8+
<a href="{{ repo_url }}/blob/master/.github/workflows/dev-test.yml#L59"><img title="code tests coverage is 100%" alt="code tests coverage is 100%" src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"></a>
109
<a href="{{ code_url }}/LICENSE"><img alt="License: MIT" src="https://img.shields.io/github/license/{{ user_repo_name }}?color=informational"></a>
10+
<a href="https://pepy.tech/project/traceback-with-variables"><img alt="Downloads" src="https://static.pepy.tech/badge/traceback-with-variables"></a>
1111
<a href="{{ pypi_url }}"><img alt="PyPI" src="https://img.shields.io/pypi/v/{{ package_name }}"></a>
1212
<a href="https://anaconda.org/conda-forge/{{ package_name }}"><img src="https://img.shields.io/conda/vn/conda-forge/{{ package_name }}"></a>
13-
<a href="{{ pypi_url }}"><img alt="PyPI" src="https://img.shields.io/badge/python-3.5+-blue.svg"></a>
13+
<a href="{{ pypi_url }}"><img alt="PyPI" src="https://img.shields.io/badge/python-3.6+-blue.svg"></a>
1414
<a href="https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling"><img title="windows, mac, linux etc." alt="Platform" src="https://img.shields.io/badge/platform-all-blue.svg"></a>
1515
<a href="{{ lib_code_url }}/override.py#L9"><img title="type hints everywhere" alt="Annotations coverage" src="https://img.shields.io/badge/type--hints-100%25-blueviolet.svg"></a>
1616
<a href="{{ lib_code_url }}/override.py#L8"><img title="no obscure objects, only transparent functions and data classes" alt="No-OOP" src="https://img.shields.io/badge/no OOP-100%25-blueviolet.svg"></a>
@@ -106,8 +106,8 @@ Using a logger [<a href="{{ examples_code_url }}/log_for_function.py">with a dec
106106

107107
<a href="{{ examples_code_url }}/format_customized.py">Customize</a> any of the previous examples:
108108
```python
109-
default_format.max_value_str_len = 10000
110-
default_format.skip_files_except = 'my_project'
109+
fmt.max_value_str_len = 10000
110+
fmt.skip_files_except = 'my_project'
111111
```
112112

113113

@@ -245,8 +245,7 @@ Using a logger [<a href="{{ examples_code_url }}/log_for_function.py">with a dec
245245
* — Should I use it after debugging is over, i.e. *in production*?
246246

247247
Yes, of course! That way it might save you even more time (watch out for sensitive data
248-
like passwords and tokens in you logs). Note: you can deploy more serious frameworks,
249-
e.g. `Sentry` :)
248+
like passwords and tokens in you logs, use skip_files_except to hide code from libs AND custom_var_printers to hide own locals). Note: you can deploy more serious frameworks, e.g. `Sentry`
250249

251250
<br/>
252251

@@ -282,6 +281,8 @@ Using a logger [<a href="{{ examples_code_url }}/log_for_function.py">with a dec
282281

283282
#### All functions have `fmt=` argument, a `Format` object with fields:
284283
* `max_value_str_len` max length of each variable string, -1 to disable, default=1000
284+
* `objects_details` depth of details of objects inspection
285+
* `ellipsis_rel_pos` when truncating long strings where to put the "...", from 0.0 to 1.0, default=0.7
285286
* `max_exc_str_len` max length of exception, should variable print fail, -1 to disable, default=10000
286287
* `before` number of code lines before the raising line, default=0
287288
* `after` number of code lines after the raising line, default=0

check_coverage_reports.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import argparse
2+
import json
3+
import sys
4+
from collections import defaultdict
5+
from pathlib import Path
6+
from typing import List
7+
8+
9+
def check_coverage_reports(inp_dir: Path, max_allowed_num_uncovered_lines: int) -> None:
10+
file_to_line_to_was_hit: Dict[str, Dict[int, bool]] = defaultdict(dict)
11+
12+
for report_path in inp_dir.rglob('*.json'):
13+
with report_path.open('r') as inp:
14+
for file_, data in json.load(inp)['files'].items():
15+
line_to_was_hit = file_to_line_to_was_hit[file_.replace('\\', '/')]
16+
for line in data['executed_lines']:
17+
line_to_was_hit[line] = True
18+
for line in data['missing_lines']:
19+
line_to_was_hit.setdefault(line, False)
20+
21+
num_uncovered_lines = 0
22+
for file_, line_to_was_hit in file_to_line_to_was_hit.items():
23+
for line, was_hit in line_to_was_hit.items():
24+
if not was_hit:
25+
sys.stderr.write(f'miss at {file_}:{line}\n')
26+
num_uncovered_lines += 1
27+
28+
if num_uncovered_lines > max_allowed_num_uncovered_lines:
29+
raise ValueError('check failed')
30+
31+
32+
def parse_args():
33+
p = argparse.ArgumentParser()
34+
p.add_argument('--inp-dir', required=True, type=Path)
35+
p.add_argument('--max-allowed-num-uncovered-lines', required=True, type=int)
36+
37+
return p.parse_args()
38+
39+
40+
def main():
41+
args = parse_args()
42+
43+
check_coverage_reports(
44+
inp_dir=args.inp_dir,
45+
max_allowed_num_uncovered_lines=args.max_allowed_num_uncovered_lines
46+
)
47+
48+
49+
if __name__ == '__main__':
50+
main()
51+

examples/format_customized.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from traceback_with_variables import Format, ColorSchemes, is_ipython_global, default_format as defaults
1+
from traceback_with_variables import Format, ColorSchemes, is_ipython_global, fmt
22

33

44
# approach 1
55

6-
defaults.max_value_str_len = 10000
6+
fmt.max_value_str_len = 10000
77

88

99
# approach 2
@@ -12,6 +12,8 @@
1212
before=3,
1313
after=1,
1414
max_value_str_len=10000,
15+
objects_details=0,
16+
ellipsis_rel_pos=0.7
1517
max_exc_str_len=1000,
1618
ellipsis_='...',
1719
color_scheme=ColorSchemes.synthwave,

examples/simple.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from traceback_with_variables import activate_by_import # , defaut_format
1+
from traceback_with_variables import a # , fmt
2+
# or
3+
from traceback_with_variables import activate_by_import # , fmt
24

35

4-
# default_format.max_value_str_len = 10000
6+
# fmt.max_value_str_len = 10000
57

68
def main():
79
n = 0

0 commit comments

Comments
 (0)