summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/extension.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/extension.py')
-rw-r--r--Lib/distutils/extension.py82
1 files changed, 30 insertions, 52 deletions
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index 9a67ca8..a93655a 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -3,15 +3,9 @@
Provides the Extension class, used to describe C/C++ extension
modules in setup scripts."""
-__revision__ = "$Id$"
-
-import os, string, sys
-from types import *
-
-try:
- import warnings
-except ImportError:
- warnings = None
+import os
+import sys
+import warnings
# This class is really only used by the "build_ext" command, so it might
# make sense to put it in distutils.command.build_ext. However, that
@@ -83,11 +77,14 @@ class Extension:
language : string
extension language (i.e. "c", "c++", "objc"). Will be detected
from the source extensions if not provided.
+ optional : boolean
+ specifies that a build failure in the extension should not abort the
+ build process, but simply not install the failing extension.
"""
# When adding arguments to this constructor, be sure to update
# setup_keywords in core.py.
- def __init__ (self, name, sources,
+ def __init__(self, name, sources,
include_dirs=None,
define_macros=None,
undef_macros=None,
@@ -101,12 +98,14 @@ class Extension:
swig_opts = None,
depends=None,
language=None,
+ optional=None,
**kw # To catch unknown keywords
):
- assert type(name) is StringType, "'name' must be a string"
- assert (type(sources) is ListType and
- map(type, sources) == [StringType]*len(sources)), \
- "'sources' must be a list of strings"
+ if not isinstance(name, str):
+ raise AssertionError("'name' must be a string")
+ if not (isinstance(sources, list) and
+ all(isinstance(v, str) for v in sources)):
+ raise AssertionError("'sources' must be a list of strings")
self.name = name
self.sources = sources
@@ -123,22 +122,20 @@ class Extension:
self.swig_opts = swig_opts or []
self.depends = depends or []
self.language = language
+ self.optional = optional
# If there are unknown keyword options, warn about them
- if len(kw):
- L = kw.keys() ; L.sort()
- L = map(repr, L)
- msg = "Unknown Extension options: " + string.join(L, ', ')
- if warnings is not None:
- warnings.warn(msg)
- else:
- sys.stderr.write(msg + '\n')
-# class Extension
-
-
-def read_setup_file (filename):
- from distutils.sysconfig import \
- parse_makefile, expand_makefile_vars, _variable_rx
+ if len(kw) > 0:
+ options = [repr(option) for option in kw]
+ options = ', '.join(sorted(options))
+ msg = "Unknown Extension options: %s" % options
+ warnings.warn(msg)
+
+def read_setup_file(filename):
+ """Reads a Setup file and returns Extension instances."""
+ from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
+ _variable_rx)
+
from distutils.text_file import TextFile
from distutils.util import split_quoted
@@ -153,21 +150,19 @@ def read_setup_file (filename):
try:
extensions = []
- while 1:
+ while True:
line = file.readline()
if line is None: # eof
break
if _variable_rx.match(line): # VAR=VALUE, handled in first pass
continue
- if line[0] == line[-1] == "*":
- file.warn("'%s' lines not handled yet" % line)
- continue
+ if line[0] == line[-1] == "*":
+ file.warn("'%s' lines not handled yet" % line)
+ continue
- #print "original line: " + line
line = expand_makefile_vars(line, vars)
words = split_quoted(line)
- #print "expanded line: " + line
# NB. this parses a slightly different syntax than the old
# makesetup script: here, there must be exactly one extension per
@@ -196,7 +191,7 @@ def read_setup_file (filename):
elif switch == "-I":
ext.include_dirs.append(value)
elif switch == "-D":
- equals = string.find(value, "=")
+ equals = value.find("=")
if equals == -1: # bare "-DFOO" -- no value
ext.define_macros.append((value, None))
else: # "-DFOO=blah"
@@ -222,12 +217,6 @@ def read_setup_file (filename):
ext.extra_link_args.append(word)
if not value:
append_next_word = ext.extra_link_args
- elif word == "-Xcompiler":
- append_next_word = ext.extra_compile_args
- elif switch == "-u":
- ext.extra_link_args.append(word)
- if not value:
- append_next_word = ext.extra_link_args
elif suffix in (".a", ".so", ".sl", ".o", ".dylib"):
# NB. a really faithful emulation of makesetup would
# append a .o file to extra_objects only if it
@@ -241,15 +230,4 @@ def read_setup_file (filename):
finally:
file.close()
- #print "module:", module
- #print "source files:", source_files
- #print "cpp args:", cpp_args
- #print "lib args:", library_args
-
- #extensions[module] = { 'sources': source_files,
- # 'cpp_args': cpp_args,
- # 'lib_args': library_args }
-
return extensions
-
-# read_setup_file ()