Spack can be extended with external commands#8612
Conversation
davydden
left a comment
There was a problem hiding this comment.
I think it’s a nice feature 👍
9ac801c to
af6a355
Compare
|
@alalazo What do you do if you need to load another python file from the same extension direcotry as the custom command? |
|
@alalazo @tgamblin @adamjstewart @scheibelp What's the status on this PR, please? It seems moribund, but we (Fermilab / SpackDev) are very interested in it. So much so, in fact, that we have some proposed changes, viz:
How should we proceed, please? Non-null options include:
Any input appreciated. |
The PR is not abandoned but just waiting for somebody to review it (in fact I have quite a few PRs in that state). As there's interest, I'll rebase it asap.
If you don't mind I'd proceed with 3. (basically post a review to the PR with requested changes). I am not sure I fully got what you need and that would give me the opportunity to discuss and understand your use case. Would that be fine with you? |
af6a355 to
3d0b5b3
Compare
|
We can certainly discuss it here, but at 200+ lines for the two commits I have, pasting them in here would get pretty messy. I can point you to the relevant branch of my fork and we can refer to items in there, perhaps? The commits in question are from my feature/enhanced-comments branch, specifically: The first commit generalizes the command-finding facilities of Spack to allow for the location of commands in places other than Taken together, these commits enable the formulation of extensions like SpackDev, where the top level command dev connects to (from its point of view) an arbitrary set of sub-commands in a similar fashion as the Spack command itself. Evolving the concept further, Thoughts appreciated. |
3d0b5b3 to
91c71a1
Compare
|
@alalazo What is the nature of your push on Dec 4? Was it just a rebase or were there substantive changes. Should I update my enhancements branch with respect to |
91c71a1 to
d5c47bd
Compare
I am regularly rebasing most of my PRs on top of the latest
So there have been no additional commits or changes.
That's great to hear! I'll also hope that this and other PRs of mine will get reviewed soon, but as the number of contributions grows I understand this might require some time due to priorities. Would it be worth to try to incorporate your changes in this PR in some way, and then ping people more aggressively to review it once we are ready? |
|
I can start looking at this on 3/25 |
|
@alalazo Sorry I missed your last entry here. I promised @scheibelp I would formally review this before next week in my capacity as someone who is using this PR already. I am perfectly fine with your adding my (just brought up-to-date with |
greenc-FNAL
left a comment
There was a problem hiding this comment.
I believe this is fine as far as it goes. My suggested enhancements could be added to this PR or submitted by me separately post-merge.
Desirable enhancements for the future:
- Command extensions to be provided from external repos.
- More flexibility in paths to extension commands and location of (e.g.) subcommands and supporting code.
- Ability to use
spack flake8to examine command extensions and supporting code.
scheibelp
left a comment
There was a problem hiding this comment.
A few requests:
- where possible, wrap details of management of the extension directory into the extension module. I have a couple comments about this; in general that means avoiding using
config.get("extensions")in modules outside theextensionsmodule. - there are a couple stylistic changes that don't appear related to the PR. I'd prefer they were removed (if you want me to squash) or placed in separate commits (if you want to rebase)
|
|
||
| @pytest.fixture(scope='session') | ||
| def _ignore_stage_files(): | ||
| def ignore_stage_files(): |
There was a problem hiding this comment.
This appears unrelated to other changes in the PR. If suddenly other test modules were using this fixture, removing the preceding _ would make more sense.
There was a problem hiding this comment.
I think fixtures should always be without preceding _, but can live with that. Will change it.
There was a problem hiding this comment.
If suddenly other test modules were using this fixture, removing the preceding _ would make more sense.
Sorry for the noise above, I had to recall why I did this. It turns out this change is needed if you want to use the the statement:
from spack.test.conftest import *in an extension command. By default, if __all__ is not defined, the statement above imports all names that are not prefixed with an underscore.
lib/spack/spack/cmd/__init__.py
Outdated
| tty.debug('Imported {0} from built-in commands'.format(pname)) | ||
| except ImportError: | ||
| # If built-in failed the import search the extension | ||
| # directories in order |
There was a problem hiding this comment.
Does "in order" matter? In one sense it does: any extension directory can support multiple commands, and so you could have conflicting implementations of a command (although if that was the intent with this PR I would be concerned about handling template conflicts).
If conflicts are the main reason for imposing an order, I think it would be simpler to require that each extension directory only supports one command. I acknowledge it may be convenient to implement several commands in one extension directory (in particular if they have related functionality that you want to test); so in general I'm OK with having multiple commands in one extension directory.
Also, IMO the next several lines should be placed into a function inside the extensions module.
There was a problem hiding this comment.
Does "in order" matter? In one sense it does: any extension directory can support multiple commands, and so you could have conflicting implementations of a command
"In order" matters for that reason. If there are multiple commands with the same name you'll currently get the first one that is matched. Those kind of conflicts are probably a niche use-case right now, but this seemed a simple and sensible solution at the time of writing the PR. Templates should work the same, even though again I don't think anybody came up with a use case that requires overriding a template completely.
There was a problem hiding this comment.
I acknowledge it may be convenient to implement several commands in one extension directory (in particular if they have related functionality that you want to test); so in general I'm OK with having multiple commands in one extension directory.
This was my intent when writing this. An extension is meant to provide functionality for a specific purpose and it can be that more than one command is needed for that.
There was a problem hiding this comment.
Also, IMO the next several lines should be placed into a function inside the extensions module.
👍
| Paths where to search for command files. | ||
| """ | ||
| for path in paths: | ||
| extension = extension_name(path) |
There was a problem hiding this comment.
Is there a reason to make this a warning instead of a failure? IMO if the user adds an extension folder, they will not want to skip it if they added it incorrectly - they would likely prefer the process to stop.
There was a problem hiding this comment.
The reasoning is that this doesn't compromise Spack's core functionality, so it should not be an error. I can change it if people prefer otherwise.
d5c47bd to
c6ae2da
Compare
|
@scheibelp @chissg Let me know if, besides any other modification to the existing code, you'd like to implement in this PR the two missing items in the description above (support for the creation of a stub extension and docs). |
|
@alalazo I have no immediate need for the docs or command extension, although I would agree they are both desirable. |
scheibelp
left a comment
There was a problem hiding this comment.
I have one additional request
fixes spack#7967 This commit add hooks to Spack so that it can extend commands reading from a set of external folders. The extensions must respect a strict directory layout to be considered valid.
The command to run unit tests has been modified to allow running tests in Spack's extensions.
c6ae2da to
16fdf56
Compare
16fdf56 to
df50d2b
Compare
…#11209) #8612 added command extensions to Spack: a command implemented in a separate directory. This improves the implementation by allowing the command to import additional utility code stored within the established directory structure for commands. This also: * Adds tests for command extensions * Documents command extensions (including the expected directory layout)
fixes #7967
This PR gives Spack the ability to hook external commands. This is done adding a new keyword (
extensions) toconfig.yaml, which contains a list of paths pointing to valid extensions.Changelist
spack create, so that it can create a stub structure for extensionsWhat is a valid extension?
A valid extension is any path in your filesystem which respect a certain naming and layout for files:
Both naming and layout are tentative at the moment, so comments to improve them are welcome.
Example
To try out a sample extension:
config.yaml: