Brandon Chinn pushed to branch wip/bchinn-argparse-filetype at Glasgow Haskell Compiler / GHC
Commits:
-
cc7d226d
by Brandon Chinn at 2025-10-21T16:36:26-07:00
3 changed files:
Changes:
| ... | ... | @@ -35,7 +35,7 @@ def expected_undocumented(flag: str) -> bool: |
| 35 | 35 | |
| 36 | 36 | return False
|
| 37 | 37 | |
| 38 | -def read_documented_flags(doc_flags) -> Set[str]:
|
|
| 38 | +def read_documented_flags(doc_flags: Path) -> Set[str]:
|
|
| 39 | 39 | # Map characters that mark the end of a flag
|
| 40 | 40 | # to whitespace.
|
| 41 | 41 | trans = str.maketrans({
|
| ... | ... | @@ -44,10 +44,10 @@ def read_documented_flags(doc_flags) -> Set[str]: |
| 44 | 44 | '⟨': ' ',
|
| 45 | 45 | })
|
| 46 | 46 | return {line.translate(trans).split()[0]
|
| 47 | - for line in doc_flags.read().split('\n')
|
|
| 47 | + for line in doc_flags.read_text().split('\n')
|
|
| 48 | 48 | if line != ''}
|
| 49 | 49 | |
| 50 | -def read_ghc_flags(ghc_path: str) -> Set[str]:
|
|
| 50 | +def read_ghc_flags(ghc_path: Path) -> Set[str]:
|
|
| 51 | 51 | ghc_output = subprocess.check_output([ghc_path, '--show-options'])
|
| 52 | 52 | ghci_output = subprocess.check_output([ghc_path, '--interactive', '--show-options'])
|
| 53 | 53 | |
| ... | ... | @@ -63,16 +63,16 @@ def error(s: str): |
| 63 | 63 | def main() -> None:
|
| 64 | 64 | import argparse
|
| 65 | 65 | parser = argparse.ArgumentParser()
|
| 66 | - parser.add_argument('--ghc', type=argparse.FileType('r'),
|
|
| 66 | + parser.add_argument('--ghc', type=Path,
|
|
| 67 | 67 | help='path of GHC executable',
|
| 68 | 68 | required=True)
|
| 69 | - parser.add_argument('--doc-flags', type=argparse.FileType(mode='r', encoding='UTF-8'),
|
|
| 69 | + parser.add_argument('--doc-flags', type=Path,
|
|
| 70 | 70 | help='path of ghc-flags.txt output from Sphinx',
|
| 71 | 71 | required=True)
|
| 72 | 72 | args = parser.parse_args()
|
| 73 | 73 | |
| 74 | 74 | doc_flags = read_documented_flags(args.doc_flags)
|
| 75 | - ghc_flags = read_ghc_flags(args.ghc.name)
|
|
| 75 | + ghc_flags = read_ghc_flags(args.ghc)
|
|
| 76 | 76 | |
| 77 | 77 | failed = False
|
| 78 | 78 |
| 1 | 1 | #!/usr/bin/env python
|
| 2 | 2 | # -*- coding: utf-8 -*-
|
| 3 | 3 | |
| 4 | +from pathlib import Path
|
|
| 4 | 5 | from typing import List, Union, Dict
|
| 5 | 6 | from collections import namedtuple
|
| 6 | 7 | |
| ... | ... | @@ -198,17 +199,17 @@ def generate_event_types_defines() -> str: |
| 198 | 199 | def main() -> None:
|
| 199 | 200 | import argparse
|
| 200 | 201 | parser = argparse.ArgumentParser()
|
| 201 | - parser.add_argument('--event-types-array', type=argparse.FileType('w'), metavar='FILE')
|
|
| 202 | - parser.add_argument('--event-types-defines', type=argparse.FileType('w'), metavar='FILE')
|
|
| 202 | + parser.add_argument('--event-types-array', type=Path, metavar='FILE')
|
|
| 203 | + parser.add_argument('--event-types-defines', type=Path, metavar='FILE')
|
|
| 203 | 204 | args = parser.parse_args()
|
| 204 | 205 | |
| 205 | 206 | check_events()
|
| 206 | 207 | |
| 207 | 208 | if args.event_types_array:
|
| 208 | - args.event_types_array.write(generate_event_types_array())
|
|
| 209 | + args.event_types_array.write_text(generate_event_types_array())
|
|
| 209 | 210 | |
| 210 | 211 | if args.event_types_defines:
|
| 211 | - args.event_types_defines.write(generate_event_types_defines())
|
|
| 212 | + args.event_types_defines.write_text(generate_event_types_defines())
|
|
| 212 | 213 | |
| 213 | 214 | if __name__ == '__main__':
|
| 214 | 215 | main() |
| ... | ... | @@ -83,7 +83,7 @@ parser.add_argument("--way", action="append", help="just this way") |
| 83 | 83 | parser.add_argument("--skipway", action="append", help="skip this way")
|
| 84 | 84 | parser.add_argument("--threads", type=int, help="threads to run simultaneously")
|
| 85 | 85 | parser.add_argument("--verbose", type=int, choices=[0,1,2,3,4,5], help="verbose (Values 0 through 5 accepted)")
|
| 86 | -parser.add_argument("--junit", type=argparse.FileType('wb'), help="output testsuite summary in JUnit format")
|
|
| 86 | +parser.add_argument("--junit", type=Path, help="output testsuite summary in JUnit format")
|
|
| 87 | 87 | parser.add_argument("--broken-test", action="append", default=[], help="a test name to mark as broken for this run")
|
| 88 | 88 | parser.add_argument("--test-env", default='local', help="Override default chosen test-env.")
|
| 89 | 89 | parser.add_argument("--perf-baseline", type=GitRef, metavar='COMMIT', help="Baseline commit for performance comparsons.")
|
| ... | ... | @@ -91,7 +91,7 @@ perf_group.add_argument("--skip-perf-tests", action="store_true", help="skip per |
| 91 | 91 | perf_group.add_argument("--only-perf-tests", action="store_true", help="Only do performance tests")
|
| 92 | 92 | parser.add_argument("--ignore-perf-failures", choices=['increases','decreases','all'],
|
| 93 | 93 | help="Do not fail due to out-of-tolerance perf tests")
|
| 94 | -parser.add_argument("--only-report-hadrian-deps", type=argparse.FileType('w'),
|
|
| 94 | +parser.add_argument("--only-report-hadrian-deps", type=Path,
|
|
| 95 | 95 | help="Dry run the testsuite and report all extra hadrian dependencies needed on the given file")
|
| 96 | 96 | |
| 97 | 97 | args = parser.parse_args()
|
| ... | ... | @@ -615,14 +615,14 @@ else: |
| 615 | 615 | summary(t, f)
|
| 616 | 616 | |
| 617 | 617 | if args.junit:
|
| 618 | - junit(t).write(args.junit)
|
|
| 619 | - args.junit.close()
|
|
| 618 | + with args.junit.open("wb") as f:
|
|
| 619 | + junit(t).write(f)
|
|
| 620 | 620 | |
| 621 | 621 | if config.only_report_hadrian_deps:
|
| 622 | 622 | print("WARNING - skipping all tests and only reporting required hadrian dependencies:", config.hadrian_deps)
|
| 623 | - for d in config.hadrian_deps:
|
|
| 624 | - print(d,file=config.only_report_hadrian_deps)
|
|
| 625 | - config.only_report_hadrian_deps.close()
|
|
| 623 | + with config.only_report_hadrian_deps.open("w") as f:
|
|
| 624 | + for d in config.hadrian_deps:
|
|
| 625 | + print(d, file=f)
|
|
| 626 | 626 | |
| 627 | 627 | if len(t.unexpected_failures) > 0 or \
|
| 628 | 628 | len(t.unexpected_stat_failures) > 0 or \
|