Commit 336b4e4f authored by Éric Araujo's avatar Éric Araujo

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.)
parent b8edbdf4
...@@ -756,8 +756,7 @@ needs to have its options defined in a dedicated section. Here's an example:: ...@@ -756,8 +756,7 @@ needs to have its options defined in a dedicated section. Here's an example::
[files] [files]
packages = coconut packages = coconut
[extension=_fastcoconut] [extension: coconut._fastcoconut]
name = coconut._fastcoconut
language = cxx language = cxx
sources = cxx_src/cononut_utils.cxx sources = cxx_src/cononut_utils.cxx
cxx_src/python_module.cxx cxx_src/python_module.cxx
...@@ -768,8 +767,10 @@ needs to have its options defined in a dedicated section. Here's an example:: ...@@ -768,8 +767,10 @@ needs to have its options defined in a dedicated section. Here's an example::
-DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32' -DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32'
/DGECODE_VERSION='win32' -- sys.platform == 'win32' /DGECODE_VERSION='win32' -- sys.platform == 'win32'
The section name must start with ``extension=``; the righ-hand part is currently The section name must start with ``extension:``; the right-hand part is used as
discarded. Valid fields and their values are listed in the documentation of the the full name (including a parent package, if any) of the extension. Whitespace
around the extension name is allowed.
Valid fields and their values are listed in the documentation of the
:class:`packaging.compiler.extension.Extension` class; values documented as :class:`packaging.compiler.extension.Extension` class; values documented as
Python lists translate to multi-line values in the configuration file. In Python lists translate to multi-line values in the configuration file. In
addition, multi-line values accept environment markers on each line, after a addition, multi-line values accept environment markers on each line, after a
......
...@@ -251,13 +251,16 @@ class Config: ...@@ -251,13 +251,16 @@ class Config:
ext_modules = self.dist.ext_modules ext_modules = self.dist.ext_modules
for section_key in content: for section_key in content:
labels = section_key.split('=') # no str.partition in 2.4 :(
labels = section_key.split(':')
if len(labels) == 2 and labels[0] == 'extension': if len(labels) == 2 and labels[0] == 'extension':
# labels[1] not used from now but should be implemented
# for extension build dependency
values_dct = content[section_key] values_dct = content[section_key]
if 'name' in values_dct:
raise PackagingOptionError(
'extension name should be given as [extension: name], '
'not as key')
ext_modules.append(Extension( ext_modules.append(Extension(
values_dct.pop('name'), labels[1].strip(),
_pop_values(values_dct, 'sources'), _pop_values(values_dct, 'sources'),
_pop_values(values_dct, 'include_dirs'), _pop_values(values_dct, 'include_dirs'),
_pop_values(values_dct, 'define_macros'), _pop_values(values_dct, 'define_macros'),
......
...@@ -6,7 +6,7 @@ from io import StringIO ...@@ -6,7 +6,7 @@ from io import StringIO
from packaging import command from packaging import command
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.errors import PackagingFileError from packaging.errors import PackagingFileError, PackagingOptionError
from packaging.compiler import new_compiler, _COMPILERS from packaging.compiler import new_compiler, _COMPILERS
from packaging.command.sdist import sdist from packaging.command.sdist import sdist
...@@ -100,21 +100,20 @@ sub_commands = foo ...@@ -100,21 +100,20 @@ sub_commands = foo
# Can not be merged with SETUP_CFG else install_dist # Can not be merged with SETUP_CFG else install_dist
# command will fail when trying to compile C sources # command will fail when trying to compile C sources
# TODO use a DummyCommand to mock build_ext
EXT_SETUP_CFG = """ EXT_SETUP_CFG = """
[files] [files]
packages = one packages = one
two two
[extension=speed_coconuts] [extension:one.speed_coconuts]
name = one.speed_coconuts
sources = c_src/speed_coconuts.c sources = c_src/speed_coconuts.c
extra_link_args = "`gcc -print-file-name=libgcc.a`" -shared extra_link_args = "`gcc -print-file-name=libgcc.a`" -shared
define_macros = HAVE_CAIRO HAVE_GTK2 define_macros = HAVE_CAIRO HAVE_GTK2
libraries = gecodeint gecodekernel -- sys.platform != 'win32' libraries = gecodeint gecodekernel -- sys.platform != 'win32'
GecodeInt GecodeKernel -- sys.platform == 'win32' GecodeInt GecodeKernel -- sys.platform == 'win32'
[extension=fast_taunt] [extension: two.fast_taunt]
name = two.fast_taunt
sources = cxx_src/utils_taunt.cxx sources = cxx_src/utils_taunt.cxx
cxx_src/python_module.cxx cxx_src/python_module.cxx
include_dirs = /usr/include/gecode include_dirs = /usr/include/gecode
...@@ -123,7 +122,11 @@ extra_compile_args = -fPIC -O2 ...@@ -123,7 +122,11 @@ extra_compile_args = -fPIC -O2
-DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32' -DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32'
/DGECODE_VERSION='win32' -- sys.platform == 'win32' /DGECODE_VERSION='win32' -- sys.platform == 'win32'
language = cxx language = cxx
"""
EXT_SETUP_CFG_BUGGY_1 = """
[extension: realname]
name = crash_here
""" """
HOOKS_MODULE = """ HOOKS_MODULE = """
...@@ -335,6 +338,9 @@ class ConfigTestCase(support.TempdirManager, ...@@ -335,6 +338,9 @@ class ConfigTestCase(support.TempdirManager,
self.assertEqual(ext.extra_compile_args, cargs) self.assertEqual(ext.extra_compile_args, cargs)
self.assertEqual(ext.language, 'cxx') self.assertEqual(ext.language, 'cxx')
self.write_file('setup.cfg', EXT_SETUP_CFG_BUGGY_1)
self.assertRaises(PackagingOptionError, self.get_dist)
def test_project_setup_hook_works(self): def test_project_setup_hook_works(self):
# Bug #11637: ensure the project directory is on sys.path to allow # Bug #11637: ensure the project directory is on sys.path to allow
# project-specific hooks # project-specific hooks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment