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

Initialize plugin because depends_on can be property #820

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

dachengx
Copy link
Collaborator

What is the problem / what does the code in this PR do

Bug observed if:

import strax

st = strax.Context()

class A(strax.Plugin):
    @property
    def depends_on(self):
        self._depends_on = tuple()
        return self._depends_on

    @depends_on.setter
    def depends_on(self, str_or_tuple):
        self._depends_on = strax.to_str_tuple(str_or_tuple)

st.register((A,))

st.deregister_plugins_with_missing_dependencies()

error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 17
     13         self._depends_on = strax.to_str_tuple(str_or_tuple)
     15 st.register((A,))
---> 17 st.deregister_plugins_with_missing_dependencies()

File ~/strax/strax/context.py:416, in Context.deregister_plugins_with_missing_dependencies(self)
    413     all_provides |= set(p.provides)
    415 for p_key, p in self._plugin_class_registry.items():
--> 416     requires = set(strax.to_str_tuple(p.depends_on))
    417     if not requires.issubset(all_provides):
    418         plugins_to_deregister.append(p_key)

File ~/strax/strax/utils.py:268, in to_str_tuple(x)
    266 elif isinstance(x, np.ndarray):
    267     return tuple(x.tolist())
--> 268 raise TypeError(f"Expected string or tuple of strings, got {type(x)}")

TypeError: Expected string or tuple of strings, got <class 'property'>

Because the depends_on of A is a property but not attribute.

Can you briefly describe how it works?
Initialize plugin instance inside deregister_plugins_with_missing_dependencies.

Can you give a minimal working example (or illustrate with a figure)?

Please include the following if applicable:

  • Update the docstring(s)
  • Update the documentation
  • Tests to check the (new) code is working as desired.
  • Does it solve one of the open issues on github?

Please make sure that all automated tests have passed before asking for a review (you can save the PR as a draft otherwise).

@dachengx dachengx requested review from WenzDaniel and yuema137 April 10, 2024 14:01
@dachengx dachengx marked this pull request as ready for review April 10, 2024 14:15
@coveralls
Copy link

Coverage Status

coverage: 91.494%. remained the same
when pulling 759e380 on deregister_property_depends_on
into 0728d2c on master.

Copy link
Collaborator

@yuema137 yuema137 left a comment

Choose a reason for hiding this comment

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

Straightforward change. Thanks

@dachengx dachengx merged commit 8aea645 into master Apr 10, 2024
9 checks passed
@dachengx dachengx deleted the deregister_property_depends_on branch April 10, 2024 20:54
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.

3 participants