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

Plugin loading #855

Merged
merged 46 commits into from
Nov 11, 2018
Merged

Plugin loading #855

merged 46 commits into from
Nov 11, 2018

Conversation

weirdan
Copy link
Collaborator

@weirdan weirdan commented Jul 2, 2018

Status

Ready for merge. Outstanding todo items can be added in subsequent PRs

Overview

Plugin installation/distribution system that piggy-backs on composer infrastructure. Follow-up to #849

Screenshot

image

Details

Available commands for psalm-plugin

  • psalm-plugin list - lists available and enabled plugins
  • psalm-plugin enable 'Plugin\Class\Name' - enables plugin (modifies psalm.xml)
  • psalm-plugin disable 'Plugin\Class\Name' - disables plugin (modifies psalm.xml)

Discovering plugins

https://packagist.org/packages/list.json?type=psalm-plugin

Plugin installation

composer install plugin-vendor/plugin-package-name

Plugin authoring

  • Skeleton plugin (usable with composer create-project ...): https://github.com/weirdan/psalm-plugin-skeleton
  • Plugins are identified by package type field, which should contain psalm-plugin string.
  • extra.psalm.pluginClass should refer to the name of the class implementing Psalm\PluginApi\PluginEntryPointInterface
  • Plugins are enabled by adding <pluginClass class="Qualified\Class\Name"/> to config file
  • Psalm\PluginApi namespace should be used to provide stable interfaces plugins can rely on

Sample plugin

Packagist: https://packagist.org/packages/weirdan/psalm-doctrine-collections
Git repo: https://github.com/weirdan/psalm-doctrine-collections

Todo

  • tests
  • better config file search (split and reuse)
  • cli argument to specify config file name
  • better output for psalm-plugin
  • phar compatibility
  • composer skeleton project for plugins
  • ability to refer to plugins by package name (cli only)
  • interface for plugin entry point
  • Plugin configuration (allows arbitrary content for pluginClass)

Further development

  • ~ migration path for legacy plugins~ Doesn't seem to be possible, because current plugins directly depend on Psalm internals (?)
  • better formatting for modified xml file
  • composer plugin to (optionally) enable plugin upon installation
  • documentation on plugin installation and authoring
  • interfaces for plugin dependencies

@weirdan
Copy link
Collaborator Author

weirdan commented Jul 2, 2018

@muglug here's the draft I promised. It's quite rough around the edges at the moment, but shows the general direction I had in mind.

@muglug
Copy link
Collaborator

muglug commented Jul 2, 2018

It's quite rough around the edges at the moment

I'll refrain from digging to deep, but I'm very on-board with command-line tools.

psalm-plugin enable 'Plugin\Class\Name'

why not use the composer name here?

@weirdan
Copy link
Collaborator Author

weirdan commented Jul 2, 2018

why not use the composer name here?

It's in todo ("ability to refer to plugins by package name (cli only)"). But if this is going to be used to manage non-composer plugins, there's also got to be a way to refer to plugins that are not packages. Since I don't want file names there, it leaves class names as the only choice.

@muglug
Copy link
Collaborator

muglug commented Jul 2, 2018

Ah sorry for missing that. I guess it's 100% fine to use either package name or classname there, as they can't overlap

This wouldn't work with a phar, right? Current plugins don't either, but I'm not massively bothered

@weirdan
Copy link
Collaborator Author

weirdan commented Jul 2, 2018

This wouldn't work with a phar, right?

I think it could be made to. Autoloading is functional in phar builds, so as long as interfaces used by plugin is not mangled by box rewriting it should just work.

Current plugins don't either, but I'm not massively bothered

Is it because their base class is prefixed?

@weirdan
Copy link
Collaborator Author

weirdan commented Jul 2, 2018

One point I'd like to decide before moving further is naming. How do we name this entire thing: "plugins", "extensions", "bundles", something else? "plugins" is currently ambiguous, as it refers both to old plugins as well to this new package based thing. My preference would be keep this named "plugins", add a LegacyPlugin adapter for old way of doing things and eventually deprecate it. But choosing a different name may also have its merits.

@muglug
Copy link
Collaborator

muglug commented Jul 2, 2018

Yeah, "plugins" is fine, I think. I don't know how many, if any, have implemented their own plugins outside of Vimeo, but this would be part of a V3 change if it broke them.

@muglug
Copy link
Collaborator

muglug commented Jul 4, 2018

Once your plugin is ready, it can go in https://github.com/psalm!

docs/plugins.md Outdated Show resolved Hide resolved
@weirdan
Copy link
Collaborator Author

weirdan commented Jul 10, 2018

@muglug Is it ok to promote symfony/console from indirect dev-dependency to direct dependency? Would help with output and a bit with testability.

@weirdan weirdan force-pushed the plugin-loading branch 2 times, most recently from 79305b5 to 140bf35 Compare July 12, 2018 16:44
@coveralls
Copy link

coveralls commented Jul 12, 2018

Coverage Status

Coverage decreased (-0.02%) to 87.521% when pulling 903f5a4 on weirdan:plugin-loading into 6cf6d2c on vimeo:master.

@weirdan weirdan force-pushed the plugin-loading branch 5 times, most recently from 2c6aace to 13c67cc Compare July 17, 2018 23:50
@weirdan weirdan force-pushed the plugin-loading branch 2 times, most recently from 806d9ea to 7c04717 Compare July 28, 2018 00:16
@weirdan
Copy link
Collaborator Author

weirdan commented Jul 28, 2018

Skeleton plugin (usable with composer create-project ...): https://github.com/weirdan/psalm-plugin-skeleton

@weirdan weirdan mentioned this pull request Oct 31, 2018
4 tasks
@weirdan weirdan changed the title [wip] Plugin loading Plugin loading Nov 3, 2018
@weirdan
Copy link
Collaborator Author

weirdan commented Nov 3, 2018

@muglug I believe it's ready for merge.

@muglug
Copy link
Collaborator

muglug commented Nov 3, 2018

@weirdan great! I don’t have my computer with me for the next 24 hours, but I’ll review once I’m back

Copy link
Collaborator

@muglug muglug left a comment

Choose a reason for hiding this comment

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

Got back a little later than intended, I've left some suggestions for documentation.

On a first glance this looks good - would you be able to migrate the plugins in the examples directory to the new format?

docs/plugins.md Outdated Show resolved Hide resolved
docs/plugins.md Outdated Show resolved Hide resolved
docs/plugins.md Outdated Show resolved Hide resolved
docs/plugins.md Outdated Show resolved Hide resolved
src/Psalm/Config.php Outdated Show resolved Hide resolved
- dropped todos I'm not going to pursues
- locked entry point to be a class implementing entry point interface
It mimics the way old plugins were registered in Psalm\Config, so
handler classes extending Psalm\Plugin should be fully compatible with
it.

Since Psalm\Plugin-style plugin registration was moved to
RegistrationSocket, LegacyPlugin now only load file-based plugins, so it
was renamed to FileBasedPluginAdapter.
- Its subfolder is registered as a local composer package in the root
composer.json, so it's directly installable with
	```
	composer require psalm/echo-checker-plugin
	```
- Migration is trivial: drop the plugin into a separate folder, then add
simple composer.json and the entry point class.
@weirdan
Copy link
Collaborator Author

weirdan commented Nov 6, 2018

@muglug all done

@muglug
Copy link
Collaborator

muglug commented Nov 7, 2018

Awesome, thanks. I'm going to make this part of a 3.0 release together with the Internal namespace changes. I'll change Psalm\Plugin to Psalm\LegacyPlugin or somesuch, with the API changes in the branch mentioned above. Should merge to master sometime this weekend. I'll create a 2.x branch to preserve that version so I can port select fixes where necessary.

@muglug muglug merged commit 052d4f6 into vimeo:master Nov 11, 2018
@weirdan weirdan deleted the plugin-loading branch November 11, 2018 13:18
@muglug
Copy link
Collaborator

muglug commented Nov 14, 2018

Just created my first composer plugin: https://github.com/psalm/phpunit-psalm-plugin

It works! Thanks so much

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