Mercurial > hg-stable
annotate tests/filtertraceback.py @ 45693:64a9423450ef
automation: support running against Python 3.9
We just added CPython 3.9.0 to the automation environment. Let's
support actions targeting it.
One side-effect of this change is that we'll produce Windows wheels
for Python 3.9 by default. This is desirable.
Differential Revision: https://phab.mercurial-scm.org/D9189
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 09 Oct 2020 09:46:03 -0700 |
parents | d359f0d1a3d3 |
children | c102b704edb5 |
rev | line source |
---|---|
41476
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Filters traceback lines from stdin. |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from __future__ import absolute_import, print_function |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
44656
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
7 import io |
41476
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 import sys |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
44656
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
10 if sys.version_info[0] >= 3: |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
11 # Prevent \r from being inserted on Windows. |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
12 sys.stdout = io.TextIOWrapper( |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
13 sys.stdout.buffer, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
14 sys.stdout.encoding, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
15 sys.stdout.errors, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
16 newline="\n", |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
17 line_buffering=sys.stdout.line_buffering, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
18 ) |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41476
diff
changeset
|
19 |
41476
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 for line in sys.stdin: |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 if state == 'none': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 if line.startswith('Traceback '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 elif state == 'tb': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 if line.startswith(' File '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 state = 'file' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 elif not line.startswith(' '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 elif state == 'file': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 # Ignore lines after " File " |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 print(line, end='') |