Commit 4f1374ba authored by Christoph Reiter's avatar Christoph Reiter 🐍

maintransformer: parse deprecation annotations for section blocks. Fixes #213

The scanner matches gtk-doc sections which match the lower case type name
to the type and uses that for the type documentation. The only problem is
it only takes the docs and none of the other annotations like deprecation
info etc.

This changes things to also parse the annotations in that case and adds some
tests while at it.
parent 19e1c72d
Pipeline #50387 passed with stages
in 6 minutes and 29 seconds
......@@ -229,9 +229,7 @@ class MainTransformer(object):
name = self._get_annotation_name(node)
section_name = 'SECTION:%s' % (name.lower(), )
block = self._blocks.get(section_name)
if block and block.description:
node.doc = block.description
node.doc_position = block.position
self._apply_annotations_annotated(node, block)
if isinstance(node, (ast.Class, ast.Interface)):
for prop in node.properties:
self._apply_annotations_property(node, prop)
......
......@@ -236,7 +236,8 @@ PYTESTS = \
test_transformer.py \
test_xmlwriter.py \
test_docwriter.py \
test_scanner.py
test_scanner.py \
test_maintransformer.py
TESTS = $(CHECKGIRS) $(CHECKDOCS) $(TYPELIBS) $(PYTESTS)
TESTS_ENVIRONMENT = env srcdir=$(srcdir) top_srcdir=$(top_srcdir) builddir=$(builddir) top_builddir=$(top_builddir) \
......
......@@ -13,6 +13,7 @@ scanner_test_files = [
'test_pkgconfig.py',
'test_docwriter.py',
'test_scanner.py',
'test_maintransformer.py',
]
foreach f : scanner_test_files
......
import unittest
import tempfile
import os
os.environ['GI_SCANNER_DISABLE_CACHE'] = '1'
from giscanner import ast
from giscanner.sourcescanner import SourceScanner
from giscanner.transformer import Transformer
from giscanner.annotationparser import GtkDocCommentBlockParser
from giscanner.maintransformer import MainTransformer
def create_scanner_from_source_string(source):
ss = SourceScanner()
tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True)
try:
with os.fdopen(tmp_fd, 'wt') as file:
file.write(source)
ss.parse_files([tmp_name])
finally:
os.unlink(tmp_name)
return ss
def load_namespace_from_source_string(namespace, source):
ss = create_scanner_from_source_string(source)
transformer = Transformer(namespace)
transformer.parse(ss.get_symbols())
cbp = GtkDocCommentBlockParser()
blocks = cbp.parse_comment_blocks(ss.get_comments())
main = MainTransformer(transformer, blocks)
main.transform()
class TestDeprecations(unittest.TestCase):
def test_record_deprecated(self):
namespace = ast.Namespace('Test', '1.0')
load_namespace_from_source_string(namespace, """
/** TestStruct:
* foo
* Deprecated: 1.2: something
*/
typedef struct _TestStruct TestStruct;
""")
node = namespace.get('Struct')
self.assertEqual(node.doc, "foo")
self.assertEqual(node.deprecated, "1.2")
self.assertEqual(node.deprecated_doc, "something")
def test_record_deprecated_from_section(self):
namespace = ast.Namespace('Test', '1.0')
load_namespace_from_source_string(namespace, """
/** SECTION:teststruct
* foo
* Deprecated: 1.2: something
*/
typedef struct _TestStruct TestStruct;
""")
node = namespace.get('Struct')
self.assertEqual(node.doc, "foo")
self.assertEqual(node.deprecated, "1.2")
self.assertEqual(node.deprecated_doc, "something")
if __name__ == '__main__':
unittest.main()
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