|
1 | 1 | # Autodetecting setup.py script for building the Python extensions
|
2 | 2 | #
|
3 | 3 |
|
4 |
| -import sys, os, importlib.machinery, re, optparse |
| 4 | +import sys, os, importlib.machinery, re, argparse |
5 | 5 | from glob import glob
|
6 | 6 | import importlib._bootstrap
|
7 | 7 |
10537
import importlib.util
|
@@ -560,24 +560,9 @@ def detect_modules(self):
|
560 | 560 | ('CPPFLAGS', '-I', self.compiler.include_dirs)):
|
561 | 561 | env_val = sysconfig.get_config_var(env_var)
|
562 | 562 | if env_val:
|
563 |
| - # To prevent optparse from raising an exception about any |
564 |
| - # options in env_val that it doesn't know about we strip out |
565 |
| - # all double dashes and any dashes followed by a character |
566 |
| - # that is not for the option we are dealing with. |
567 |
| - # |
568 |
| - # Please note that order of the regex is important! We must |
569 |
| - # strip out double-dashes first so that we don't end up with |
570 |
| - # substituting "--Long" to "-Long" and thus lead to "ong" being |
571 |
| - # used for a library directory. |
572 |
| - env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], |
573 |
| - ' ', env_val) |
574 |
| - parser = optparse.OptionParser() |
575 |
| - # Make sure that allowing args interspersed with options is |
576 |
| - # allowed |
577 |
| - parser.allow_interspersed_args = True |
578 |
| - parser.error = lambda msg: None |
579 |
| - parser.add_option(arg_name, dest="dirs", action="append") |
580 |
| - options = parser.parse_args(env_val.split())[0] |
| 563 | + parser = argparse.ArgumentParser() |
| 564 | + parser.add_argument(arg_name, dest="dirs", action="append") |
| 565 | + options, _ = parser.parse_known_args(env_val.split()) |
581 | 566 | if options.dirs:
|
582 | 567 | for directory in reversed(options.dirs):
|
583 | 568 | add_dir_to_list(dir_list, directory)
|
|
0 commit comments