|
1 | | -#!/usr/bin/python |
| 1 | +#!/usr/bin/python3 |
2 | 2 |
|
3 | 3 | import sys, re |
4 | 4 |
|
5 | 5 | if len(sys.argv) != 2: |
6 | | - print 'Usage: %s <file>' % sys.argv[0] |
| 6 | + print(f"Usage: {sys.argv[0]} <file>") |
7 | 7 | sys.exit() |
8 | 8 |
|
9 | 9 | filename = sys.argv[1] |
10 | | -print 'Checking %s' % filename |
| 10 | +print(f"Checking {filename}") |
11 | 11 |
|
12 | | -regex = re.compile('^#include.*<(.*)>') |
| 12 | +regex = re.compile("^#include.*<(.*)>") |
13 | 13 | ql_headers = [] |
14 | 14 | boost_headers = [] |
15 | 15 | std_headers = [] |
|
18 | 18 | for n, line in enumerate(source): |
19 | 19 | match = regex.search(line) |
20 | 20 | if match: |
21 | | - header, = match.groups() |
22 | | - line_num = n+1 |
23 | | - if header.startswith('ql/'): |
24 | | - ql_headers.append((header,line_num)) |
25 | | - if header.startswith('ql/experimental') and 'internal' not in line: |
26 | | - experimental_headers.append((header,line_num)) |
27 | | - elif header.startswith('boost/'): |
28 | | - boost_headers.append((header,line_num)) |
| 21 | + (header,) = match.groups() |
| 22 | + line_num = n + 1 |
| 23 | + if header.startswith("ql/"): |
| 24 | + ql_headers.append((header, line_num)) |
| 25 | + if header.startswith("ql/experimental") and "internal" not in line: |
| 26 | + experimental_headers.append((header, line_num)) |
| 27 | + elif header.startswith("boost/"): |
| 28 | + boost_headers.append((header, line_num)) |
29 | 29 | else: |
30 | | - std_headers.append((header,line_num)) |
| 30 | + std_headers.append((header, line_num)) |
31 | 31 | source.close() |
32 | 32 |
|
33 | 33 | # At least one QuantLib header muct be included (which, hopefully, |
34 | 34 | # ultimately leads to including ql/qldefines.hpp) |
35 | 35 | if not ql_headers: |
36 | | - print "./%s:1: error: no QuantLib header included" % filename |
| 36 | + print(f"./{filename}:1: error: no QuantLib header included") |
37 | 37 | sys.exit(1) |
38 | 38 |
|
39 | | -if 'ql/experimental' not in filename: |
| 39 | +if "ql/experimental" not in filename: |
40 | 40 | # files in core library can't include stuff in experimental |
41 | 41 | if experimental_headers: |
42 | | - for f,n in experimental_headers: |
43 | | - print "./%s:%d: error: experimental header '%s' included" % (filename, n, f) |
| 42 | + for f, n in experimental_headers: |
| 43 | + print(f"./{filename}:{n}: error: experimental header '{f}' included") |
44 | 44 | sys.exit(1) |
45 | 45 |
|
46 | | -for f,n in ql_headers: |
47 | | - if f.endswith('/all.hpp'): |
48 | | - print "./%s:%d: error: generated header '%s' included" % (filename, n, f) |
| 46 | +for f, n in ql_headers: |
| 47 | + if f.endswith("/all.hpp"): |
| 48 | + print(f"./{filename}:{n}: error: generated header '{f}' included") |
49 | 49 | sys.exit(1) |
50 | 50 |
|
51 | 51 | # All Boost headers must be included after QuantLib ones |
52 | | -last_ql_header = max([ n for _,n in ql_headers]) |
| 52 | +last_ql_header = max([n for _, n in ql_headers]) |
53 | 53 |
|
54 | | -for _,n in boost_headers: |
| 54 | +for _, n in boost_headers: |
55 | 55 | if n < last_ql_header: |
56 | | - print "./%s:%d: error: Boost header included before last QuantLib header" % (filename, n) |
| 56 | + print( |
| 57 | + f"./{filename}:{n}: error: Boost header included before last QuantLib header" |
| 58 | + ) |
57 | 59 | sys.exit(1) |
58 | 60 |
|
59 | 61 |
|
60 | 62 | # All standard headers must be included after QuantLib and Boost ones |
61 | 63 | if boost_headers: |
62 | | - last_boost_header = max([ n for _,n in boost_headers]) |
| 64 | + last_boost_header = max([n for _, n in boost_headers]) |
63 | 65 |
|
64 | | -for _,n in std_headers: |
| 66 | +for _, n in std_headers: |
65 | 67 | if n < last_ql_header: |
66 | | - print "./%s:%d: error: standard header included before last QuantLib header" % (filename, n) |
| 68 | + print( |
| 69 | + f"./{filename}:{n}: error: standard header included before last QuantLib header" |
| 70 | + ) |
67 | 71 | sys.exit(1) |
68 | 72 | if boost_headers and n < last_boost_header: |
69 | | - print "./%s:%d: error: standard header included before last Boost header" % (filename, n) |
| 73 | + print( |
| 74 | + f"./{filename}:{n}: error: standard header included before last Boost header" |
| 75 | + ) |
70 | 76 | sys.exit(1) |
71 | | - |
|
0 commit comments