diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ # 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 import sysconfig from distutils import log from distutils.errors import * from distutils.core import Extension, setup @@ -506,34 +506,20 @@ class PyBuildExt(build_ext): # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). for env_var, arg_name, dir_list in ( ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), ('LDFLAGS', '-L', self.compiler.library_dirs), ('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 = argparse.ArgumentParser() parser.error = lambda msg: None - parser.add_option(arg_name, dest="dirs", action="append") - options = parser.parse_args(env_val.split())[0] + parser.add_argument(arg_name, dest="dirs", action="append") + options = parser.parse_args(env_val.split()) if options.dirs: for directory in reversed(options.dirs): add_dir_to_list(dir_list, directory) if (not cross_compiling and os.path.normpath(sys.base_prefix) != '/usr' and not sysconfig.get_config_var('PYTHONFRAMEWORK')): # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework