Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 336b4e4

Browse files
committed
Minor improvement to extensions section in setup.cfg.
The right-hand part in [extension: foo] is now used as the name of the extension module. (I changed the separator from = to : and allowed whitespace to make the sections look nicer.)
1 parent b8edbdf commit 336b4e4

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

Doc/packaging/setupcfg.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ needs to have its options defined in a dedicated section. Here's an example::
756756
[files]
757757
packages = coconut
758758

759-
[extension=_fastcoconut]
760-
name = coconut._fastcoconut
759+
[extension: coconut._fastcoconut]
761760
language = cxx
762761
sources = cxx_src/cononut_utils.cxx
763762
cxx_src/python_module.cxx
@@ -768,8 +767,10 @@ needs to have its options defined in a dedicated section. Here's an example::
768767
-DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32'
769768
/DGECODE_VERSION='win32' -- sys.platform == 'win32'
770769

771-
The section name must start with ``extension=``; the righ-hand part is currently
772-
discarded. Valid fields and their values are listed in the documentation of the
770+
The section name must start with ``extension:``; the right-hand part is used as
771+
the full name (including a parent package, if any) of the extension. Whitespace
772+
around the extension name is allowed.
773+
Valid fields and their values are listed in the documentation of the
773774
:class:`packaging.compiler.extension.Extension` class; values documented as
774775
Python lists translate to multi-line values in the configuration file. In
775776
addition, multi-line values accept environment markers on each line, after a

Lib/packaging/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,16 @@ def _read_setup_cfg(self, parser, cfg_filename):
251251

252252
ext_modules = self.dist.ext_modules
253253
for section_key in content:
254-
labels = section_key.split('=')
254+
# no str.partition in 2.4 :(
255+
labels = section_key.split(':')
255256
if len(labels) == 2 and labels[0] == 'extension':
256-
# labels[1] not used from now but should be implemented
257-
# for extension build dependency
258257
values_dct = content[section_key]
258+
if 'name' in values_dct:
259+
raise PackagingOptionError(
260+
'extension name should be given as [extension: name], '
261+
'not as key')
259262
ext_modules.append(Extension(
260-
values_dct.pop('name'),
263+
labels[1].strip(),
261264
_pop_values(values_dct, 'sources'),
262265
_pop_values(values_dct, 'include_dirs'),
263266
_pop_values(values_dct, 'define_macros'),

Lib/packaging/tests/test_config.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from packaging import command
88
from packaging.dist import Distribution
9-
from packaging.errors import PackagingFileError
9+
from packaging.errors import PackagingFileError, PackagingOptionError
1010
from packaging.compiler import new_compiler, _COMPILERS
1111
from packaging.command.sdist import sdist
1212

@@ -100,21 +100,20 @@
100100

101101
# Can not be merged with SETUP_CFG else install_dist
102102
# command will fail when trying to compile C sources
103+
# TODO use a DummyCommand to mock build_ext
103104
EXT_SETUP_CFG = """
104105
[files]
105106
packages = one
106107
two
107108
108-
[extension=speed_coconuts]
109-
name = one.speed_coconuts
109+
[extension:one.speed_coconuts]
110110
sources = c_src/speed_coconuts.c
111111
extra_link_args = "`gcc -print-file-name=libgcc.a`" -shared
112112
define_macros = HAVE_CAIRO HAVE_GTK2
113113
libraries = gecodeint gecodekernel -- sys.platform != 'win32'
114114
GecodeInt GecodeKernel -- sys.platform == 'win32'
115115
116-
[extension=fast_taunt]
117-
name = two.fast_taunt
116+
[extension: two.fast_taunt]
118117
sources = cxx_src/utils_taunt.cxx
119118
cxx_src/python_module.cxx
120119
include_dirs = /usr/include/gecode
@@ -123,7 +122,11 @@
123122
-DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32'
124123
/DGECODE_VERSION='win32' -- sys.platform == 'win32'
125124
language = cxx
125+
"""
126126

127+
EXT_SETUP_CFG_BUGGY_1 = """
128+
[extension: realname]
129+
name = crash_here
127130
"""
128131

129132
HOOKS_MODULE = """
@@ -335,6 +338,9 @@ def test_parse_extensions_in_config(self):
335338
self.assertEqual(ext.extra_compile_args, cargs)
336339
self.assertEqual(ext.language, 'cxx')
337340

341+
self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_1)
342+
self.assertRaises(PackagingOptionError, self.get_dist)
343+
338344
def test_project_setup_hook_works(self):
339345
# Bug #11637: ensure the project directory is on sys.path to allow
340346
# project-specific hooks

0 commit comments

Comments
 (0)