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

Use plugins to define rhino installable packages #614

Merged
merged 4 commits into from Sep 16, 2020

Conversation

gonzalocasas
Copy link
Member

@gonzalocasas gonzalocasas commented Sep 11, 2020

The main goal of this PR is to change the way other packages install themselves into Rhino to make it a more straightforward experience for the user.

Currently, non-core packages (eg. compas_fab) need to be explicitly installed using something like python -m compas_rhino.install -p compas_fab. This works fine for simple packages, but as soon as packages have other dependencies, the thing gets messy. In the case of compas_fab, we provide a wrapped installer that takes care of both compas core and compas_fab+dependencies (python -m compas_fab.rhino.install) but this means extra code on each package that needs this behavior, and a confusing situation with similar but not entirely identical commands to install compas stuff.

So this PR leverages the new plugin system, defines a new pluggable extension point for packages to announce which packages they need and changes the install process to discover all existing plugins on that extension point and retrieve all the required rhino-installable packages.

For this purpose, the plugin system now has two types of plugins (first_match (default) and collect_all), and as an almost side note, I create a doc page to list all available extension points, otherwise it's very hard to discover them (eventually, this page generation should be automated):

image

There are already 3 examples of using this new end-point, two are in this PR: compas_rhino and compas_ghpython, instead of hard-coding the package names that need to go to Rhino, they define them using the same extension point. And for compas_fab, just opened a pr to do the same.

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

@gonzalocasas
Copy link
Member Author

ping

Copy link
Member

@tomvanmele tomvanmele left a comment

Choose a reason for hiding this comment

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

cool, let's just try it :)

Comment on lines +122 to +142
@compas.plugins.pluggable(category='install', selector='collect_all')
def installable_rhino_packages():
"""Provide a list of packages to make available inside Rhino.

Extensions providing Rhino or Grasshopper features
can implement this pluggable interface to automatically
have their packages made available inside Rhino when
COMPAS is installed into it.

Examples
--------
>>> import compas.plugins
>>> @compas.plugins.plugin(category='install')
... def installable_rhino_packages():
... return ['compas_fab']

Returns
-------
:obj:`list` of :obj:`str`
List of package names to make available inside Rhino.
"""
Copy link
Member

Choose a reason for hiding this comment

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

so in some other package you would basically write a plugin for this function that adds itself to the list of installable packages?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, eg. compas_fab: compas-dev/compas_fab#200

@gonzalocasas gonzalocasas merged commit f918d90 into master Sep 16, 2020
@gonzalocasas gonzalocasas deleted the installable-extension-point branch September 16, 2020 12:52
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.

None yet

2 participants