8000 bpo-29442: Replace optparse with argparse in setup.py (GH-139) · python/cpython@09b2bec · GitHub
[go: up one dir, main page]

Skip to content

Commit 09b2bec

Browse files
yan12125methane
authored andcommitted
bpo-29442: Replace optparse with argparse in setup.py (GH-139)
1 parent d5c875b commit 09b2bec

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace optparse with argparse in setup.py

setup.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Autodetecting setup.py script for building the Python extensions
22
#
33

4-
import sys, os, importlib.machinery, re, optparse
4+
import sys, os, importlib.machinery, re, argparse
55
from glob import glob
66
import importlib._bootstrap
77
10537 import importlib.util
@@ -560,24 +560,9 @@ def detect_modules(self):
560560
('CPPFLAGS', '-I', self.compiler.include_dirs)):
561561
env_val = sysconfig.get_config_var(env_var)
562562
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())
581566
if options.dirs:
582567
for directory in reversed(options.dirs):
583568
add_dir_to_list(dir_list, directory)

0 commit comments

Comments
 (0)
0