Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
d2f43a0e
Commit
d2f43a0e
authored
Mar 31, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#5583 Added optional Extensions in Distutils
parent
e96f0dd0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
command/build_ext.py
command/build_ext.py
+7
-1
extension.py
extension.py
+5
-0
tests/test_build_ext.py
tests/test_build_ext.py
+21
-1
No files found.
command/build_ext.py
View file @
d2f43a0e
...
@@ -476,7 +476,13 @@ class build_ext (Command):
...
@@ -476,7 +476,13 @@ class build_ext (Command):
self
.
check_extensions_list
(
self
.
extensions
)
self
.
check_extensions_list
(
self
.
extensions
)
for
ext
in
self
.
extensions
:
for
ext
in
self
.
extensions
:
self
.
build_extension
(
ext
)
try
:
self
.
build_extension
(
ext
)
except
(
CCompilerError
,
DistutilsError
),
e
:
if
not
ext
.
optional
:
raise
self
.
warn
(
'building extension "%s" failed: %s'
%
(
ext
.
name
,
e
))
def
build_extension
(
self
,
ext
):
def
build_extension
(
self
,
ext
):
sources
=
ext
.
sources
sources
=
ext
.
sources
...
...
extension.py
View file @
d2f43a0e
...
@@ -83,6 +83,9 @@ class Extension:
...
@@ -83,6 +83,9 @@ class Extension:
language : string
language : string
extension language (i.e. "c", "c++", "objc"). Will be detected
extension language (i.e. "c", "c++", "objc"). Will be detected
from the source extensions if not provided.
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
# When adding arguments to this constructor, be sure to update
...
@@ -101,6 +104,7 @@ class Extension:
...
@@ -101,6 +104,7 @@ class Extension:
swig_opts
=
None
,
swig_opts
=
None
,
depends
=
None
,
depends
=
None
,
language
=
None
,
language
=
None
,
optional
=
None
,
**
kw
# To catch unknown keywords
**
kw
# To catch unknown keywords
):
):
assert
type
(
name
)
is
StringType
,
"'name' must be a string"
assert
type
(
name
)
is
StringType
,
"'name' must be a string"
...
@@ -123,6 +127,7 @@ class Extension:
...
@@ -123,6 +127,7 @@ class Extension:
self
.
swig_opts
=
swig_opts
or
[]
self
.
swig_opts
=
swig_opts
or
[]
self
.
depends
=
depends
or
[]
self
.
depends
=
depends
or
[]
self
.
language
=
language
self
.
language
=
language
self
.
optional
=
optional
# If there are unknown keyword options, warn about them
# If there are unknown keyword options, warn about them
if
len
(
kw
):
if
len
(
kw
):
...
...
tests/test_build_ext.py
View file @
d2f43a0e
...
@@ -8,6 +8,8 @@ from distutils.core import Extension, Distribution
...
@@ -8,6 +8,8 @@ from distutils.core import Extension, Distribution
from
distutils.command.build_ext
import
build_ext
from
distutils.command.build_ext
import
build_ext
from
distutils
import
sysconfig
from
distutils
import
sysconfig
from
distutils.tests
import
support
from
distutils.tests
import
support
from
distutils.extension
import
Extension
from
distutils.errors
import
UnknownFileError
import
unittest
import
unittest
from
test
import
test_support
from
test
import
test_support
...
@@ -20,7 +22,9 @@ def _get_source_filename():
...
@@ -20,7 +22,9 @@ def _get_source_filename():
srcdir
=
sysconfig
.
get_config_var
(
'srcdir'
)
srcdir
=
sysconfig
.
get_config_var
(
'srcdir'
)
return
os
.
path
.
join
(
srcdir
,
'Modules'
,
'xxmodule.c'
)
return
os
.
path
.
join
(
srcdir
,
'Modules'
,
'xxmodule.c'
)
class
BuildExtTestCase
(
support
.
TempdirManager
,
unittest
.
TestCase
):
class
BuildExtTestCase
(
support
.
TempdirManager
,
support
.
LoggingSilencer
,
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
# Create a simple test environment
# Create a simple test environment
# Note that we're making changes to sys.path
# Note that we're making changes to sys.path
...
@@ -142,6 +146,22 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase):
...
@@ -142,6 +146,22 @@ class BuildExtTestCase(support.TempdirManager, unittest.TestCase):
self
.
assert_
(
lib
in
cmd
.
library_dirs
)
self
.
assert_
(
lib
in
cmd
.
library_dirs
)
self
.
assert_
(
incl
in
cmd
.
include_dirs
)
self
.
assert_
(
incl
in
cmd
.
include_dirs
)
def
test_optional_extension
(
self
):
# this extension will fail, but let's ignore this failure
# with the optional argument.
modules
=
[
Extension
(
'foo'
,
[
'xxx'
],
optional
=
False
)]
dist
=
Distribution
({
'name'
:
'xx'
,
'ext_modules'
:
modules
})
cmd
=
build_ext
(
dist
)
cmd
.
ensure_finalized
()
self
.
assertRaises
(
UnknownFileError
,
cmd
.
run
)
# should raise an error
modules
=
[
Extension
(
'foo'
,
[
'xxx'
],
optional
=
True
)]
dist
=
Distribution
({
'name'
:
'xx'
,
'ext_modules'
:
modules
})
cmd
=
build_ext
(
dist
)
cmd
.
ensure_finalized
()
cmd
.
run
()
# should pass
def
test_suite
():
def
test_suite
():
src
=
_get_source_filename
()
src
=
_get_source_filename
()
if
not
os
.
path
.
exists
(
src
):
if
not
os
.
path
.
exists
(
src
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment