|
1 |
| -from distutils.errors import DistutilsArgError |
2 |
| -from distutils.fancy_getopt import FancyGetopt |
| 1 | +from getopt import GetoptError, getopt |
3 | 2 | from typing import Dict, List
|
4 | 3 |
|
5 | 4 | _options = [
|
6 |
| - ("exec-prefix=", None, ""), |
7 |
| - ("home=", None, ""), |
8 |
| - ("install-base=", None, ""), |
9 |
| - ("install-data=", None, ""), |
10 |
| - ("install-headers=", None, ""), |
11 |
| - ("install-lib=", None, ""), |
12 |
| - ("install-platlib=", None, ""), |
13 |
| - ("install-purelib=", None, ""), |
14 |
| - ("install-scripts=", None, ""), |
15 |
| - ("prefix=", None, ""), |
16 |
| - ("root=", None, ""), |
17 |
| - ("user", None, ""), |
| 5 | + "exec-prefix=", |
| 6 | + "home=", |
| 7 | + "install-base=", |
| 8 | + "install-data=", |
| 9 | + "install-headers=", |
| 10 | + "install-lib=", |
| 11 | + "install-platlib=", |
| 12 | + "install-purelib=", |
| 13 | + "install-scripts=", |
| 14 | + "prefix=", |
| 15 | + "root=", |
| 16 | + "user", |
18 | 17 | ]
|
19 | 18 |
|
20 | 19 |
|
21 |
| -# typeshed doesn't permit Tuple[str, None, str], see python/typeshed#3469. |
22 |
| -_distutils_getopt = FancyGetopt(_options) # type: ignore |
23 |
| - |
24 |
| - |
25 | 20 | def parse_distutils_args(args: List[str]) -> Dict[str, str]:
|
26 |
| - """Parse provided arguments, returning an object that has the |
27 |
| - matched arguments. |
| 21 | + """Parse provided arguments, returning an object that has the matched arguments. |
28 | 22 |
|
29 | 23 | Any unknown arguments are ignored.
|
30 | 24 | """
|
31 | 25 | result = {}
|
32 | 26 | for arg in args:
|
33 | 27 | try:
|
34 |
| - _, match = _distutils_getopt.getopt(args=[arg]) |
35 |
| - except DistutilsArgError: |
| 28 | + parsed_opt, _ = getopt(args=[arg], shortopts="", longopts=_options) |
| 29 | + except GetoptError: |
36 | 30 | # We don't care about any other options, which here may be
|
37 | 31 | # considered unrecognized since our option list is not
|
38 | 32 | # exhaustive.
|
39 |
| - pass |
40 |
| - else: |
41 |
| - result.update(match.__dict__) |
| 33 | + continue |
| 34 | + |
| 35 | + if not parsed_opt: |
| 36 | + continue |
| 37 | + |
| 38 | + option = parsed_opt[0] |
| 39 | + name_from_parsed = option[0][2:].replace("-", "_") |
| 40 | + value_from_parsed = option[1] or "true" |
| 41 | + result[name_from_parsed] = value_from_parsed |
| 42 | + |
42 | 43 | return result
|
0 commit comments