We should support loading command files from "DRUPAL_ROOT . '/.drush" to make it easier to use drush extensions on a project.
The current options for installing extensions are:
/usr/share/drush - needs sudo
~/.drush - not global
modules/themes - requires an enabled .module to load
I think it's reasonable to expect that there are hosting environments where these options won't work, and you just need it tied to the codebase, which docroot/.drush would cover nicely. It's also similar to what npm does for node projects where it installs in docroot/.node_modules.
Patch attached.
Comments
Comment #1
greg.1.anderson commentedThis is similar in concept to the "Grayside feature" (load drush config from the root of the git repository). I am in favor of this, but could we call the folder "drush" instead of ".drush"? I think it makes sense to hide this folder in $HOME, but not in /etc or DRUPAL_ROOT.
Comment #2
moshe weitzman commentedIt is supported to put site alias files in drupal root so this makes sense. we really need to unify search paths for commandfiles, aliases, and drushrc files
Comment #3
robloachMaybe have the additional Drush extensions in sites/all/drush? I get anxious about having a bunch of stuff in the Drupal root. Would also be cool if extensions could be installed via
drush dl drush_shelltoo, but that's a separate matter.Comment #4
greg.1.anderson commented+1 for sites/all/drush.
Comment #5
moshe weitzman commentedHaving said that, we took a long time to convince people not to put drush or its commandfiles inside of a drupal site. I'm not eager to going backwards on this. sites/all/drush does not sound appetizing to me.
Comment #6
msonnabaum commentedI'm not crazy about sites/all/drush since it implies multisite functionality, which I'd rather we didn't bother with.
I suppose I could go either way on .drush vs drush. I assume my preference for .drush is influenced by what npm does. It might be nice to not always see it at the root of your repository since it's not part of Drupal.
Comment #7
becw commentedI agree that folks should be discouraged from keeping drush inside a Drupal site, but for projects where code is shared across a variety of environments, it may be necessary.
Since Drush is a utility, I think it makes sense semantically to put a drush directory in the drupal root rather than within sites/all, but sites/all has practical advantages like making core updates smoother and keeping all non-core pieces in one place.
Comment #8
greg.1.anderson commentedIf #5 is true (and it does seem compelling), then I think that DRUPAL_ROOT is not better than sites/all/drush in this respect, and ".drush" does not really fix this IMO. How about '../drush'? A lot of people put their DRUPAL_ROOT inside of a "project" for the site.
Comment #9
dman commentedRather not that the website make any assumptions about the structure above it. A number of projects do have a project directory there, but in another number of cases, that's the 'shared' space that a lot of different sites call home. Just look at an Aegir platform setup.
Referring to ../ is one of the first scary things that would cause nervousness in a security audit. Justified or not, it looks like a bad smell in the code.
Comment #10
greg.1.anderson commentedWell, the reference to ".." only happens in Drush, not in the Drupal site, so security audits are not really applicable here.
I don't think it would be terrible to have a shared drush folder for a collection of Aegir sites, but you are correct, if that is your environment, then you wouldn't have a place to put one drush folder per site if we used "../drush". I think what this boils down to is that the sentiments of #9 are in opposition with #5. If we want the feature of one drush commandfile folder per site, then sites/all/drush is best, and if we don't -- well, I guess we can skip the feature. In Drush 5, we already load a drushrc.php file from DRUPAL_ROOT/drushrc.php during drush_bootstrap_drush. Inside this file, you can put in your own logic and call
_drush_add_commandfiles($searchpath);, where $searchpath is any arbitrary array of paths where you would like to search for commandfiles in.Perhaps we should just remove the _ from drush_add_commandfiles and fix this in documentation (examples/example.drushrc.php).
Comment #11
dman commentedWell, with Aegir, i've got enough root anyway... it's just an example of an equally common architecture. I feel icky about upward leakage.
I don't actually mind {drupalroot}/.drush
But I think that it would be hard to get good consensus on everyones requirements, so I suggest adding an include path in drushrc - similar to the site_aliases search path array - would give folk who need it the appropriate control - or that _drush_add_commandfiles() as above works the same.
Thumbs up recommending to that approach - I can't see this bikeshed getting painted otherwise.
Comment #12
msonnabaum commentedWe can't go up a directory. That's too big of an assumption.
It might be nice to have this path be configurable, but I'd rather that not hold up this getting in.
So far I feel like the decision is still between .drush, drush, and sites/all/drush.
Comment #13
msonnabaum commentedAlso, I'm not convinced by the argument for sites/all/drush that we don't want to mix it in with core. D8 has already moved everything to /core, so we can assume that the docroot will be much cleaner in the future.
Comment #14
greg.1.anderson commentedI'll also mention that #759906: Update core without moving core files out of the way. may be a factor here.
Comment #15
greg.1.anderson commentedHere is a patch that "solves" this problem through documentation. Note that the technique isn't terribly clean; it works if placed in drushrc.php files at the Drupal root, but does not work for other drushrc.php locations (unless your Drupal site is selected via cwd instead of an alias or cli option...).
Maybe one of the compromises suggested above would be better.
Comment #16
moshe weitzman commentedOf the possible locations, I'm now leaning toward sites/all/drush. Sorry I have been waffling on this.
Yet I have a nagging feeling that we're asking for support requests. Commands that have to run before DRUSH_DRUPAL_ROOT phase will not be found. There are going to be a fair number of commandfiles that won't work when put inside of Drupal. For example, we can't auto-download extensions to this dir as suggested in #3.
If we proceed, the original patch adds code to the SITE bootstrap phase instead of ROOT. Needs docs changes as well.
Comment #17
greg.1.anderson commentedDue to my recent changes to the Drush bootstrap (identify site earlier in bootstrap), I expect that DRUSH_BOOTSTRAP_DRUSH commands can be placed in sites/all/drush (if a patch similar to #0 is applied), and will be found, and will run at the specified bootstrap level (DRUSH_BOOTSTRAP_DRUSH). Haven't tested this exact configuration, but essentially that's what I was doing when I tested #15, and early-bootstrap commands work.
Comment #18
moshe weitzman commentedGreat - that resolves one major hurdle.
The other is that alias and config files can be put in the root of a drupal site today, but commandfiles are proposed for sites/all/drush or ROOT/.drush. Shouldn't these all look in in the same place?
Comment #19
robloachI'm in support of sites/all/drush. People already know how to use it (ie modules/themes/libraries), and if we document it correctly, I don't think we'll run into many support issues around the lack of multi-site. We could even add multi-site support in as a follow-up issue if it's desired...
Do you think
drush pm-download drush_queueshould download to sites/all/drush? I'm conflicted about that one.Comment #20
greg.1.anderson commentedYes, currently alias files can be placed at DRUPAL_ROOT; in Drush 5, I think this location should move to sites/all/drush, same as for commandfiles.
pm-download of Drush extensions could go to /etc/drush if it exists, or sites/all/drush if it exists (and a site is bootstrapped), or $HOME/.drush otherwise.
Comment #21
dman commentedI like the implications of this. I've had the site aliases in local sites folders, and had to copy or symlink them, or keep them somewhere global.
sites/all/drush will be a good alternative
Comment #22
greg.1.anderson commentedc.f. related issue #1377824: Centralize logic for determining location of site-wide and user-specific configuration directories
Comment #23
greg.1.anderson commentedBased on the discussion in #1377824: Centralize logic for determining location of site-wide and user-specific configuration directories, maybe commandfiles should go in sites/all/drush/commands.
Should alias and config files also be allowed in sites/all/drush? It would be strange if this were not supported; this seems to be moshe's point in #18. If we allow aliases and config files here, do we eliminate support for placing them at the Drupal root?
Would it be less confusing for folks to close this issue as a dup of #1377824?
Comment #24
moshe weitzman commentedThis patch standardizes on sites/all/drush for alias files, config files, and commandfiles when searched for in a drupal site. alias and config files may no longer be placed in DRUPAL_ROOT. As suggested, the commandfiles are loaded during DRUSH_BOOTSTRAP_DRUSH so even early command should succeed.
I did not change the default destination for pm-download when it download commandfiles. I'm pretty neutral on that.
All tests are passing.
Comment #25
greg.1.anderson commentedYeah, that looks good to me.
There are pros and cons to changing the default for pm-download. I suppose that if you inserted a check for DRUPAL_ROOT/sites/all/modules (exists and is writable) in after the test for the site-wide file, but before the test for the user's $HOME/.drush folder, then it would usually do the right thing. I'm neutral on this as well, and feel the patch can go in as-is.
I do get the following error in the site upgrade test:
Other than that, the patch looks good.
Comment #26
moshe weitzman commentedI forgot to mention that all cached environments from unit tests are invalid as they don't have sites/all/drush dir. Thats why you got that error. To delete cached environments,
rm -rf $TMPDIR/drush-cacheCommitted.
I will do the Change Notification soon.
Comment #27
moshe weitzman commentedAdded Change record and removed tag.