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

Register plugin from entry points #1872

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Ni-g-3l
Copy link

@Ni-g-3l Ni-g-3l commented Nov 11, 2024

Hello

As suggest here I implemented the support of entrypoints in order to make the process of adding plugin to REZ easier.

Closes #1661

Feel free to add feedback !

Have a great day

@Ni-g-3l Ni-g-3l requested a review from a team as a code owner November 11, 2024 15:07
Signed-off-by: Nig3l <[email protected]>
@Ni-g-3l Ni-g-3l force-pushed the feat/register_plugin_from_entry_points branch from 8a16886 to da9e66c Compare November 11, 2024 15:08
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 69.69697% with 10 lines in your changes missing coverage. Please review.

Project coverage is 59.25%. Comparing base (c039654) to head (da9e66c).

Files with missing lines Patch % Lines
src/rez/plugin_managers.py 69.69% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1872      +/-   ##
==========================================
- Coverage   59.27%   59.25%   -0.03%     
==========================================
  Files         126      126              
  Lines       17217    17166      -51     
  Branches     3017     2754     -263     
==========================================
- Hits        10206    10171      -35     
+ Misses       6326     6310      -16     
  Partials      685      685              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JeanChristopheMorinPerso JeanChristopheMorinPerso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ni-g-3l for creating this PR. I left a couple of comments that will need to be addressed before we can consider merging it.

Also, if you have the time and want to, we should adjust our newly written plugins doc (https://rez.readthedocs.io/en/stable/plugins.html).

if sys.version_info.minor >= 8:
from importlib.metadata import entry_points
else:
from importlib_metadata import entry_points

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will force us to vendor importlib-metadata (which is fine since it's an APACHE-2.0 licensed).

Comment on lines +187 to +191
plugin = plugin.load()
plugin_name = plugin.__name__.split('.')[-1]
plugin_path = os.path.dirname(plugin.__file__)
self.register_plugin_module(plugin_name, plugin, plugin_path)
self.load_config_from_plugin(plugin)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put this code under a try/except block and add logs similar to logs found in load_plugins_from_namespace.

@@ -68,6 +69,13 @@ def test_new_loading_style(self):
"package_repository", "cloud")
self.assertEqual(cloud_cls.name(), "cloud")

def test_load_plugin_from_entry_points(self):
"""Test loading rez plugin from setuptools entry points"""
with restore_pip("baz", os.path.join(self.data_path("extensions"), "baz")):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be safer to either just install into a temporary directory, or just commit the dist-info folder in the repo to avoid having to install it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the plugin defined twice?

discovered_plugins = entry_points(group='rez.plugins')
for plugin in discovered_plugins:
plugin = plugin.load()
plugin_name = plugin.__name__.split('.')[-1]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand why we need to do this. Can't we just use plugin.name? For the old plugin style, we needed to do split('.')[-1] because we were getting the name from rezplugins.<type>.<name>. But with entrypoints, we don't need to split.

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.

Simplify plugin development by supporting entrypoint based plugins
2 participants