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

Support scoped _GO_* variables for plugins #130

Merged
merged 4 commits into from
Jan 24, 2017
Merged

Support scoped _GO_* variables for plugins #130

merged 4 commits into from
Jan 24, 2017

Conversation

mbland
Copy link
Owner

@mbland mbland commented Jan 23, 2017

Part of #120. Plugin command scripts now have their own scoped _GO_ROOTDIR, _GO_SCRIPTS_DIR, _GO_SEARCH_PATHS, and _GO_PLUGINS_PATHS. This will encourage more composable plugins, some of which may even operate as standalone applications that can be incorporated wholesale into other applications.

Notice that the search path precedence is:

  • _GO_INJECT_SEARCH_PATH
  • _GO_CORE_DIR/libexec
  • _GO_SCRIPTS_DIR
  • _GO_SCRIPTS_DIR/plugins/*/bin
  • any inherited _GO_PLUGINS_PATHS from the parent environment

The implication of the last two points is that plugin command scripts will first search for other command scripts in their own _GO_SCRIPTS_DIR, for plugins in their own _GO_SCRIPTS_DIR/plugins/*/bin, then through the _GO_PLUGINS_PATHS inherited from the parent script. These _GO_PLUGINS_PATHS search paths effectively build a command path search that recurses up to the top-level _GO_PLUGINS_DIR.

This lays the groundwork for:

  • sharing a single copy of a plugin between all plugins that may depend on it
  • installing specific versions of a plugin within plugins themselves to resolve version incompatibilities with other installed versions of a plugin
  • circular dependency support, though such dependencies are strongly discouraged

A future PR/commit will support a similar mechanism for plugin module (plugin/lib) imports.

This is a step towards #120, in which plugin command scripts will now
have their own scoped `_GO_ROOTDIR`, `_GO_SCRIPTS_DIR`,
`_GO_SEARCH_PATHS`, and `_GO_PLUGINS_PATHS`. This will encourage more
composable plugins, some which may even operate as standalone
applications that can be incorporated wholesale into other applications.

Notice that the search path precedence is:

- _GO_INJECT_SEARCH_PATH
- _GO_CORE_DIR/libexec
- _GO_SCRIPTS_DIR
- _GO_SCRIPTS_DIR/plugins/*/bin
- any inherited _GO_PLUGINS_PATHS from the parent environment

The implication of the last two points is that command scripts installed
as plugins will first search for plugins in their own `_GO_SCRIPTS_DIR`,
then through the `_GO_PLUGINS_PATHS` inherited from its parent script.
These `_GO_PLUGINS_PATHS` search paths effectively build a command path
search that recurses up to the top-level `_GO_PLUGINS_DIR`.
Part of #120. Plugin command scripts now have their own scoped
`_GO_ROOTDIR`, `_GO_SCRIPTS_DIR`, `_GO_SEARCH_PATHS`, and
`_GO_PLUGINS_PATHS`. This will encourage more composable plugins, some
which may even operate as standalone applications that can be
incorporated wholesale into other applications.

This lays the groundwork for:

- sharing a single copy of a plugin between all plugins that may depend
  on it
- installing specific versions of a plugin within plugins themselves to
  resolve version incompatibilities with other installed versions of a
  plugin
- circular dependency support, though such dependencies are strongly
  discouraged
@mbland mbland added this to the v1.4.0 milestone Jan 23, 2017
@mbland mbland self-assigned this Jan 23, 2017
In the previous commit for PR #130, in order to allow plugins to have
their own scoped `_GO_ROOTDIR`, it was necessary to remove its
`readonly` constraint. I'd forgotten to update `tests/vars.bats` to
remove the `-r` flag in the expected output.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 95.325% when pulling af3cb36 on plugin-scope into 829c98e on master.

I realized that the previous way `_GO_PLUGINS_PATHS` was getting built
would allow nested plugin paths to leak up into the environment of
plugins closer to the `_GO_PLUGINS_DIR` root. After considering how to
filter `_GO_PLUGINS_PATHS`, I realized the best solution was to build it
by walking up the directory tree whenever a plugin is executed.

Ironically, this is similar to another commit I'm working on in another
branch to find plugin files (specifically plugin modules, though the
mechanism is generic) in a similar fashion.
@coveralls
Copy link

Coverage Status

Coverage decreased (-68.5%) to 26.763% when pulling d1d63a5 on plugin-scope into 829c98e on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 95.341% when pulling d393f38 on plugin-scope into 829c98e on master.

@mbland mbland merged commit 69312a7 into master Jan 24, 2017
@mbland mbland deleted the plugin-scope branch January 24, 2017 03:41
mbland added a commit that referenced this pull request Jan 26, 2017
Part of #120. This implements semantics similar to npm's `node_modules`
by providing a parent directory-recursive plugin search.

After implementing #130 and coming back to my original
`@go.find_plugin_item_path` that I'd had in another branch, I realized
the parent-recursive search could be abstracted into
`@go.search_plugins`. Ironically, it was implementing the algorithm
first in `_@go.set_search_paths` than enabled me to more thoroughly test
the extracted function, since plugin scope was already established and
tested. Talk about circular dependencies!

As with the earlier commits building up #120, the implication is that
rather than having all plugins comprising an application always checkout
their own plugins in their own subtree, eventually they can be installed
in their parent's plugin directory.  This nesting of plugins can be
arbitrarily deep, ending at the top-level `_GO_PLUGINS_DIR`.

This will help break cyclical dependencies (though they should still be
avoided) and save disk space, and paves the way for semantic versioning
and `npm`-like functionality (but in pure Bash, modulo `git` or `curl`,
et. al, via `./go get`).
This was referenced Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants