From: Vladimír Vondruš Date: Tue, 4 Jan 2022 15:14:34 +0000 (+0100) Subject: documentation/python: drop pybind11 2.2 support. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=71fb96e7636377b12c33c404a931adb56668a370;p=blog.git documentation/python: drop pybind11 2.2 support. Version 2.3 is the oldest supported now. It got released in Oct 2019 and there were a bunch of extra hacks needed for 2.2. Ubuntu 18.04 has 2.0.1 which isn't feasible to be supported either, but 20.04 already has 2.4, so staying at 2.3 at a minimum is good enough I'd say. --- diff --git a/documentation/python.py b/documentation/python.py index 8ae8347f..d29ee660 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -934,9 +934,7 @@ def parse_pybind_signature(state: State, referrer_path: List[str], signature: st arg_type_link = None # Default (optional) - # The equals has spaces around since 2.3.0, preserve 2.2 compatibility. - # https://github.com/pybind/pybind11/commit/0826b3c10607c8d96e1d89dc819c33af3799a7b8 - if signature.startswith(('=', ' = ')): + if signature.startswith(' = '): signature = signature[1 if signature[0] == '=' else 3:] signature, default = _pybind11_extract_default_argument(signature) else: @@ -1014,11 +1012,9 @@ def format_value(state: State, referrer_path: List[str], value) -> Optional[str] if value is None: return str(value) if isinstance(value, enum.Enum): return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name)) - # pybind enums have the __members__ attribute instead. Since 2.3 pybind11 - # has .name like enum.Enum, but we still need to support 2.2 so hammer it - # out of a str() instead. + # pybind enums have the __members__ attribute instead elif state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__'): - return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, str(value).partition('.')[2])) + return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name)) elif inspect.isfunction(value): return html.escape(''.format(value.__name__)) elif '__repr__' in type(value).__dict__: diff --git a/documentation/test_python/test_pybind.py b/documentation/test_python/test_pybind.py index e8dfe967..4570663e 100644 --- a/documentation/test_python/test_pybind.py +++ b/documentation/test_python/test_pybind.py @@ -127,53 +127,7 @@ class Signature(unittest.TestCase): ('**kwargs', None, None, None), ], None, None)) - # https://github.com/pybind/pybind11/commit/0826b3c10607c8d96e1d89dc819c33af3799a7b8, - # released in 2.3.0. We want to support both, so test both. - def test_default_values_pybind22(self): - self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: float=1.0, b: str=\'hello\')'), - ('foo', '', [ - ('a', 'float', 'float', '1.0'), - ('b', 'str', 'str', '\'hello\''), - ], None, None)) - - self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: float=libA.foo(libB.goo(123), libB.bar + 13) + 2, b=3)'), - ('foo', '', [ - ('a', 'float', 'float', 'libA.foo(libB.goo(123), libB.bar + 13) + 2'), - ('b', None, None, '3'), - ], None, None)) - - self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: List=[1, 2, 3], b: Tuple=(1, 2, 3, "str"))'), - ('foo', '', [ - ('a', 'typing.List', 'typing.List', '[1, 2, 3]'), - ('b', "typing.Tuple", "typing.Tuple", '(1, 2, 3, "str")'), - ], None, None)) - - self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: Tuple[int, ...]=(1,("hello", \'world\'),3,4))'), - ('foo', '', [ - ('a', 'typing.Tuple[int, ...]', - 'typing.Tuple[int, ...]', - '(1,("hello", \'world\'),3,4)') - ], None, None)) - - self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: str=[dict(key="A", value=\'B\')["key"][0], None][0])'), - ('foo', '', [ - ('a', 'str', 'str', '[dict(key="A", value=\'B\')["key"][0], None][0]') - ], None, None)) - - bad_signature = ('foo', '', [('…', None, None, None)], None, None) - - self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=[0][)'), bad_signature) - self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=()'), bad_signature) - self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=(()'), bad_signature) - self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=))'), bad_signature) - self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=])'), bad_signature) - - def test_default_values_pybind23(self): + def test_default_values(self): self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float = 1.0, b: str = \'hello\')'), ('foo', '', [ @@ -182,7 +136,7 @@ class Signature(unittest.TestCase): ], None, None)) self.assertEqual(parse_pybind_signature(self.state, [], - 'foo(a: float = libA.foo(libB.goo(123), libB.bar + 13) + 2, b=3)'), + 'foo(a: float = libA.foo(libB.goo(123), libB.bar + 13) + 2, b = 3)'), ('foo', '', [ ('a', 'float', 'float', 'libA.foo(libB.goo(123), libB.bar + 13) + 2'), ('b', None, None, '3'), @@ -214,7 +168,7 @@ class Signature(unittest.TestCase): # annoying but what can I do. Want to support both this and the original # behavior in case they revert the insanity again, so test that both # variants give the same output. - def test_default_values_pybind26(self): + def test_default_enum_values_pybind26(self): # Before the insane change self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: bar.Enum = Enum.FOO_BAR)'), diff --git a/package/ci/circleci.yml b/package/ci/circleci.yml index 9b3f86de..1ef9c62e 100644 --- a/package/ci/circleci.yml +++ b/package/ci/circleci.yml @@ -196,9 +196,8 @@ jobs: - test-plugins - test-documentation-themes: python-version: "3.6" - # Again, deliberately using an old version to verify the old hacks - # still work for it - pybind-version: "2.2.4" + # We don't support anything before 2.3.0 anymore. + pybind-version: "2.3.0" - coverage py307: