Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension: add ExtensionPlugin class #116

Closed
wants to merge 1 commit into from

Conversation

steweg
Copy link
Contributor

@steweg steweg commented Apr 6, 2024

This patch introduces new class ExtensionPlugin, which is wrapper around libyang extension plugin, which allows user to define custom action for parsing, compiling, and freeing parsed or compiled extensions.

Custom actions can also raise a new type of exception LibyangExtensionError, which allows proper translation of exception to libyang error codes and logging of error message

@steweg steweg marked this pull request as draft April 6, 2024 10:43
@steweg steweg force-pushed the feature/extension_plugin branch from b744cee to 25be575 Compare April 12, 2024 15:22
@steweg steweg mentioned this pull request Apr 12, 2024
@samuel-gauthier
Copy link
Collaborator

@steweg, what do you want to do with this draft? Shall we close it or do you have questions?

@steweg
Copy link
Contributor Author

steweg commented Aug 2, 2024

I will need to rebase it and then I will mark it for review

@steweg steweg force-pushed the feature/extension_plugin branch 3 times, most recently from e3c2546 to 91b56e5 Compare August 4, 2024 07:30
@steweg steweg marked this pull request as ready for review August 4, 2024 07:31
libyang/schema.py Outdated Show resolved Hide resolved
libyang/schema.py Outdated Show resolved Hide resolved
libyang/schema.py Outdated Show resolved Hide resolved
@samuel-gauthier
Copy link
Collaborator

Having a plugin that counts calls is fine for non-regression testing. Could we have an example of a meaningful plugin? That would help users to play with this feature. How about contributing to the examples section of the README file for this one?

@steweg steweg force-pushed the feature/extension_plugin branch from 91b56e5 to d7fff81 Compare August 5, 2024 08:44
@steweg
Copy link
Contributor Author

steweg commented Aug 5, 2024

I have added another example into tests. Putting the real example is very difficult as it really depends on nature of that extension what you want to achieve. For example in my project we are modifying the parsed structure of given parent node and creating grouping statement on the fly. So I have just put the code that we are using for performing easy checked like whether the extension is only once present on given node and also whether it is put under expected node type.

@steweg steweg force-pushed the feature/extension_plugin branch 7 times, most recently from 23c7b39 to acf7ee0 Compare August 5, 2024 09:18
@steweg steweg force-pushed the feature/extension_plugin branch 2 times, most recently from ea55034 to f8bb900 Compare August 5, 2024 10:37
@samuel-gauthier
Copy link
Collaborator

@steweg there is this warning when running the test after the last commit of this series, can you check it?
Exception ignored from cffi callback <function libyang_c_lyplg_ext_parse_clb at 0x7ff3451ceaf0>:
Traceback (most recent call last):
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/extension.py", line 35, in libyang_c_lyplg_ext_parse_clb
plugin.parse_clb(module, parsed_ext)
File "/home/runner/work/libyang-python/libyang-python/tests/test_extension.py", line 150, in _parse_clb
self._verify_single(parent)
File "/home/runner/work/libyang-python/libyang-python/tests/test_extension.py", line 132, in _verify_single
if e.name() == self.name and e.module().name() == self.module_name:
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/schema.py", line 414, in module
return self._module_from_parsed()
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/schema.py", line 408, in _module_from_parsed
raise self.context.error("cannot get module")
libyang.util.LibyangError: cannot get module
.Exception ignored from cffi callback <function libyang_c_lyplg_ext_parse_clb at 0x7ff3451ceaf0>:
Traceback (most recent call last):
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/extension.py", line 35, in libyang_c_lyplg_ext_parse_clb
plugin.parse_clb(module, parsed_ext)
File "/home/runner/work/libyang-python/libyang-python/tests/test_extension.py", line 150, in _parse_clb
self._verify_single(parent)
File "/home/runner/work/libyang-python/libyang-python/tests/test_extension.py", line 132, in _verify_single
if e.name() == self.name and e.module().name() == self.module_name:
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/schema.py", line 414, in module
return self._module_from_parsed()
File "/home/runner/work/libyang-python/libyang-python/.tox/py39/lib/python3.9/site-packages/libyang/schema.py", line 408, in _module_from_parsed
raise self.context.error("cannot get module")
libyang.util.LibyangError: cannot get module

This patch introduces new class ExtensionPlugin, which is wrapper around
libyang extension plugin, which allows user to define custom action for
parsing, compiling, and freeing parsed or compiled extensions.

Custom actions can also raise a new type of exception
LibyangExtensionError, which allows proper translation of exception to
libyang error codes and logging of error message

Signed-off-by: Stefan Gula <[email protected]>
@steweg steweg force-pushed the feature/extension_plugin branch from f8bb900 to ba76c0e Compare September 29, 2024 21:13
@steweg
Copy link
Contributor Author

steweg commented Sep 29, 2024

Fixed + rebased

@steweg steweg deleted the feature/extension_plugin branch December 16, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants