Problems with entry points

15 views
Skip to first unread message

Otto Kohulák

unread,
Feb 6, 2023, 10:23:41 AM2/6/23
to aiida...@googlegroups.com
Dear AiiDAians,

I am writing my plugin (aiida_python), and I would like to dynamically setup my entry_points for testing purposes. When I setup my entry points via pkg_resources it cannot be seen by AiiDA. By examination for AiiDA source code I noticed AiiDA uses importlib_metadata in order to get the registered entry points. Is it possible to get setup my entry points dynamically to see it in AiiDA? Further explanation of the topic can be found in this StackOverflow post of mine:


Thanks,
Best Regards,

O.

Sebastiaan Huber

unread,
Feb 6, 2023, 3:57:02 PM2/6/23
to aiida...@googlegroups.com
Hi Otto,

You are in luck, as I recently added a pytest fixture for just this purpose.
You can find the documentation online: https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/plugins.html#topics-plugins-testfixtures-entry-points
If you are running your tests with `pytest` (which I highly recommend you do) you could run a test like the following:
def test_parser(entry_points):
    """Test a custom ``Parser`` implementation."""
    from aiida.parsers import Parser
    from aiida.plugins import ParserFactory

    class CustomParser(Parser):
        """Parser implementation."""

    entry_points.add(CustomParser, 'custom.parser')

    assert ParserFactory('custom.parser', CustomParser)

In this example, I define a custom implementation of the `Parser` class and "register" it with the `custom.parser` entry point through the `entry_points` fixture.
By doing so, AiiDA will be aware of this plugin, for the duration of the test, as if you would have installed it through an actual package.
Note that the fixture was added in aiida-core v2.1.0  so you need at least that version.

Hope that helps,

Sebastiaan
--
AiiDA is supported by the NCCR MARVEL (http://nccr-marvel.ch/), funded by the Swiss National Science Foundation, and by the European H2020 MaX Centre of Excellence (http://www.max-centre.eu/).
 
Before posting your first question, please see the posting guidelines at http://www.aiida.net/?page_id=356 .
---
You received this message because you are subscribed to the Google Groups "aiidausers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aiidausers+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aiidausers/CAK%3DGx5gmi0PkTJ16rAr2MD_p7J1WsX3PTaMVzvdF%3Da7BiJ5c5A%40mail.gmail.com.

Otto Kohulák

unread,
Feb 7, 2023, 4:27:15 AM2/7/23
to aiida...@googlegroups.com
Dear Sebastiaan,

this is exactly what I was looking for. Thanks a lot.

Best, O.

po 6. 2. 2023 o 21:57 Sebastiaan Huber <ma...@sphuber.net> napísal(a):
Reply all
Reply to author
Forward
0 new messages