|
1 | 1 | # text parts
|
2 |
| -processed_files = { } |
| 2 | +processed_files = {} |
3 | 3 |
|
4 | 4 | # authors
|
5 |
| -for filename in ['AUTHORS', 'CONTRIBUTORS']: |
6 |
| - with open(filename, encoding='utf8') as f: |
7 |
| - text = '' |
8 |
| - for line in f: |
9 |
| - if filename == 'AUTHORS': |
10 |
| - text += '// fast_float by ' + line |
11 |
| - if filename == 'CONTRIBUTORS': |
12 |
| - text += '// with contributions from ' + line |
13 |
| - processed_files[filename] = text + '//\n//\n' |
| 5 | +for filename in ["AUTHORS", "CONTRIBUTORS"]: |
| 6 | + with open(filename, encoding="utf8") as f: |
| 7 | + text = "" |
| 8 | + for line in f: |
| 9 | + if filename == "AUTHORS": |
| 10 | + text += "// fast_float by " + line |
| 11 | + if filename == "CONTRIBUTORS": |
| 12 | + text += "// with contributions from " + line |
| 13 | + processed_files[filename] = text + "//\n//\n" |
14 | 14 |
|
15 | 15 | # licenses
|
16 |
| -for filename in ['LICENSE-MIT', 'LICENSE-APACHE', 'LICENSE-BOOST']: |
17 |
| - lines = [] |
18 |
| - with open(filename, encoding='utf8') as f: |
19 |
| - lines = f.readlines() |
| 16 | +for filename in ["LICENSE-MIT", "LICENSE-APACHE", "LICENSE-BOOST"]: |
| 17 | + lines = [] |
| 18 | + with open(filename, encoding="utf8") as f: |
| 19 | + lines = f.readlines() |
20 | 20 |
|
21 |
| - # Retrieve subset required for inclusion in source |
22 |
| - if filename == 'LICENSE-APACHE': |
23 |
| - lines = [ |
24 |
| - ' Copyright 2021 The fast_float authors\n', |
25 |
| - *lines[179:-1] |
26 |
| - ] |
| 21 | + # Retrieve subset required for inclusion in source |
| 22 | + if filename == "LICENSE-APACHE": |
| 23 | + lines = [" Copyright 2021 The fast_float authors\n", *lines[179:-1]] |
27 | 24 |
|
28 |
| - text = '' |
29 |
| - for line in lines: |
30 |
| - line = line.strip() |
31 |
| - if len(line): |
32 |
| - line = ' ' + line |
33 |
| - text += '//' + line + '\n' |
34 |
| - processed_files[filename] = text |
| 25 | + text = "" |
| 26 | + for line in lines: |
| 27 | + line = line.strip() |
| 28 | + if len(line): |
| 29 | + line = " " + line |
| 30 | + text += "//" + line + "\n" |
| 31 | + processed_files[filename] = text |
35 | 32 |
|
36 | 33 | # code
|
37 |
| -for filename in [ 'constexpr_feature_detect.h', 'float_common.h', 'fast_float.h', 'ascii_number.h', |
38 |
| - 'fast_table.h', 'decimal_to_binary.h', 'bigint.h', 'digit_comparison.h', 'parse_number.h']: |
39 |
| - with open('include/fast_float/' + filename, encoding='utf8') as f: |
40 |
| - text = '' |
41 |
| - for line in f: |
42 |
| - if line.startswith('#include "'): continue |
43 |
| - text += line |
44 |
| - processed_files[filename] = '\n' + text |
| 34 | +for filename in [ |
| 35 | + "constexpr_feature_detect.h", |
| 36 | + "float_common.h", |
| 37 | + "fast_float.h", |
| 38 | + "ascii_number.h", |
| 39 | + "fast_table.h", |
| 40 | + "decimal_to_binary.h", |
| 41 | + "bigint.h", |
| 42 | + "digit_comparison.h", |
| 43 | + "parse_number.h", |
| 44 | +]: |
| 45 | + with open("include/fast_float/" + filename, encoding="utf8") as f: |
| 46 | + text = "" |
| 47 | + for line in f: |
| 48 | + if line.startswith('#include "'): |
| 49 | + continue |
| 50 | + text += line |
| 51 | + processed_files[filename] = "\n" + text |
45 | 52 |
|
46 | 53 | # command line
|
47 | 54 | import argparse
|
48 | 55 |
|
49 |
| -parser = argparse.ArgumentParser(description='Amalgamate fast_float.') |
50 |
| -parser.add_argument('--license', default='TRIPLE', choices=['DUAL', 'TRIPLE', 'MIT', 'APACHE', 'BOOST'], help='choose license') |
51 |
| -parser.add_argument('--output', default='', help='output file (stdout if none') |
| 56 | +parser = argparse.ArgumentParser(description="Amalgamate fast_float.") |
| 57 | +parser.add_argument( |
| 58 | + "--license", |
| 59 | + default="TRIPLE", |
| 60 | + choices=["DUAL", "TRIPLE", "MIT", "APACHE", "BOOST"], |
| 61 | + help="choose license", |
| 62 | +) |
| 63 | +parser.add_argument("--output", default="", help="output file (stdout if none") |
52 | 64 |
|
53 | 65 | args = parser.parse_args()
|
54 | 66 |
|
| 67 | + |
55 | 68 | def license_content(license_arg):
|
56 |
| - result = [] |
57 |
| - if license_arg == 'TRIPLE': |
58 |
| - result += [ |
59 |
| - '// Licensed under the Apache License, Version 2.0, or the\n', |
60 |
| - '// MIT License or the Boost License. This file may not be copied,\n', |
61 |
| - '// modified, or distributed except according to those terms.\n', |
62 |
| - '//\n' |
63 |
| - ] |
64 |
| - if license_arg == 'DUAL': |
65 |
| - result += [ |
66 |
| - '// Licensed under the Apache License, Version 2.0, or the\n', |
67 |
| - '// MIT License at your option. This file may not be copied,\n', |
68 |
| - '// modified, or distributed except according to those terms.\n', |
69 |
| - '//\n' |
70 |
| - ] |
| 69 | + result = [] |
| 70 | + if license_arg == "TRIPLE": |
| 71 | + result += [ |
| 72 | + "// Licensed under the Apache License, Version 2.0, or the\n", |
| 73 | + "// MIT License or the Boost License. This file may not be copied,\n", |
| 74 | + "// modified, or distributed except according to those terms.\n", |
| 75 | + "//\n", |
| 76 | + ] |
| 77 | + if license_arg == "DUAL": |
| 78 | + result += [ |
| 79 | + "// Licensed under the Apache License, Version 2.0, or the\n", |
| 80 | + "// MIT License at your option. This file may not be copied,\n", |
| 81 | + "// modified, or distributed except according to those terms.\n", |
| 82 | + "//\n", |
| 83 | + ] |
| 84 | + |
| 85 | + if license_arg in ("DUAL", "TRIPLE", "MIT"): |
| 86 | + result.append("// MIT License Notice\n//\n") |
| 87 | + result.append(processed_files["LICENSE-MIT"]) |
| 88 | + result.append("//\n") |
| 89 | + if license_arg in ("DUAL", "TRIPLE", "APACHE"): |
| 90 | + result.append("// Apache License (Version 2.0) Notice\n//\n") |
| 91 | + result.append(processed_files["LICENSE-APACHE"]) |
| 92 | + result.append("//\n") |
| 93 | + if license_arg in ("TRIPLE", "BOOST"): |
| 94 | + result.append("// BOOST License Notice\n//\n") |
| 95 | + result.append(processed_files["LICENSE-BOOST"]) |
| 96 | + result.append("//\n") |
71 | 97 |
|
72 |
| - if license_arg in ('DUAL', 'TRIPLE', 'MIT'): |
73 |
| - result.append('// MIT License Notice\n//\n') |
74 |
| - result.append(processed_files['LICENSE-MIT']) |
75 |
| - result.append('//\n') |
76 |
| - if license_arg in ('DUAL', 'TRIPLE', 'APACHE'): |
77 |
| - result.append('// Apache License (Version 2.0) Notice\n//\n') |
78 |
| - result.append(processed_files['LICENSE-APACHE']) |
79 |
| - result.append('//\n') |
80 |
| - if license_arg in ('TRIPLE', 'BOOST'): |
81 |
| - result.append('// BOOST License Notice\n//\n') |
82 |
| - result.append(processed_files['LICENSE-BOOST']) |
83 |
| - result.append('//\n') |
| 98 | + return result |
84 | 99 |
|
85 |
| - return result |
86 | 100 |
|
87 |
| -text = ''.join([ |
88 |
| - processed_files['AUTHORS'], processed_files['CONTRIBUTORS'], |
89 |
| - *license_content(args.license), |
90 |
| - processed_files['constexpr_feature_detect.h'], |
91 |
| - processed_files['float_common.h'], processed_files['fast_float.h'], |
92 |
| - processed_files['ascii_number.h'], processed_files['fast_table.h'], |
93 |
| - processed_files['decimal_to_binary.h'], processed_files['bigint.h'], |
94 |
| - processed_files['digit_comparison.h'], processed_files['parse_number.h']]) |
| 101 | +text = "".join( |
| 102 | + [ |
| 103 | + processed_files["AUTHORS"], |
| 104 | + processed_files["CONTRIBUTORS"], |
| 105 | + *license_content(args.license), |
| 106 | + processed_files["constexpr_feature_detect.h"], |
| 107 | + processed_files["float_common.h"], |
| 108 | + processed_files["fast_float.h"], |
| 109 | + processed_files["ascii_number.h"], |
| 110 | + processed_files["fast_table.h"], |
| 111 | + processed_files["decimal_to_binary.h"], |
| 112 | + processed_files["bigint.h"], |
| 113 | + processed_files["digit_comparison.h"], |
| 114 | + processed_files["parse_number.h"], |
| 115 | + ] |
| 116 | +) |
95 | 117 |
|
96 | 118 | if args.output:
|
97 |
| - with open(args.output, 'wt', encoding='utf8') as f: |
98 |
| - f.write(text) |
| 119 | + with open(args.output, "wt", encoding="utf8") as f: |
| 120 | + f.write(text) |
99 | 121 | else:
|
100 |
| - print(text) |
| 122 | + print(text) |
0 commit comments