summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorChih-Hsuan Yen <yan12125@gmail.com>2018-07-11 16:48:43 +0800
committerINADA Naoki <methane@users.noreply.github.com>2018-07-11 17:48:43 +0900
commit09b2bece78f62c3d363236dce593ecfe130afd2f (patch)
tree5c956ce1c212616db4c18b38d5c53c63b6ecd1c6 /setup.py
parentd5c875bbf1ef9b24349d3243b1ffaab6a9d5a78e (diff)
downloadcpython-git-09b2bece78f62c3d363236dce593ecfe130afd2f.tar.gz
bpo-29442: Replace optparse with argparse in setup.py (GH-139)
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py23
1 files changed, 4 insertions, 19 deletions
diff --git a/setup.py b/setup.py
index 170ade81c4..37c5dd58a6 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
# Autodetecting setup.py script for building the Python extensions
#
-import sys, os, importlib.machinery, re, optparse
+import sys, os, importlib.machinery, re, argparse
from glob import glob
import importlib._bootstrap
import importlib.util
@@ -560,24 +560,9 @@ class PyBuildExt(build_ext):
('CPPFLAGS', '-I', self.compiler.include_dirs)):
env_val = sysconfig.get_config_var(env_var)
if env_val:
- # To prevent optparse from raising an exception about any
- # options in env_val that it doesn't know about we strip out
- # all double dashes and any dashes followed by a character
- # that is not for the option we are dealing with.
- #
- # Please note that order of the regex is important! We must
- # strip out double-dashes first so that we don't end up with
- # substituting "--Long" to "-Long" and thus lead to "ong" being
- # used for a library directory.
- env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
- ' ', env_val)
- parser = optparse.OptionParser()
- # Make sure that allowing args interspersed with options is
- # allowed
- parser.allow_interspersed_args = True
- parser.error = lambda msg: None
- parser.add_option(arg_name, dest="dirs", action="append")
- options = parser.parse_args(env_val.split())[0]
+ parser = argparse.ArgumentParser()
+ parser.add_argument(arg_name, dest="dirs", action="append")
+ options, _ = parser.parse_known_args(env_val.split())
if options.dirs:
for directory in reversed(options.dirs):
add_dir_to_list(dir_list, directory)