I'm trying to get Less into a site during an automated site make and site install with drush:
$ drush make mysite.make
$ drush site-install myprofile
However, even if the makefile correctly downloads less, libraries AND the lessphp library:
api = 2
core = 7.x
projects[] = less
projects[] = libraries
; Libraries for less
libraries[lessphp][download][type] = "git"
libraries[lessphp][download][url] = https://github.com/leafo/lessphp.git
libraries[lessphp][directory_name] = lessphp
then the site install fails:
Starting Drupal installation. This takes a few seconds ... [ok]
WD php: Exception: LESS: [error]The lessphp library was not detected. Please follow the instructions on the LESS project page to install the lessphp library. in
install_verify_requirements() (line 756 of /var/www/drupal7-test/includes/install.core.inc).
WD php: Warning: Cannot modify header information - headers already sent by (output started at /opt/drush4/includes/drush.inc:868) in [warning]
drupal_send_headers() (line 1239 of /var/www/drupal7-test/includes/bootstrap.inc).
Exception: LESS:The lessphp library was not detected. Please follow the instructions on the <a href="http://drupal.org/project/less" target="_blank">LESS project page</a> to install the lessphp library. in install_verify_requirements() (line 756 of /var/www/drupal7-test/includes/install.core.inc).
Drush command terminated abnormally due to an unrecoverable error.
Right now this really cool module can't be included in automated site installs without considerable extra fiddling. Here are some possible solutions in order of decreasing preference:
- less.module should be able to be enabled without finding lessphp, on the assumption that it will be able to find it later (and just report an error on the Status Report page.)
- less.install should try to explicitly load libraries.module - remember that during an install phase, each .module file isn't actually loaded, until the next PHP request or until it's done explicitly.
- less.module should "look harder" for lessphp in the absence of libraries.module (not recommended, as you just keep having to hardwire lots of special cases that libraries.module should "just work out" for you)
What's the preferred fix here? My suggestion is #1, where less.module enables but just doesn't work properly in the absence of lessphp. That would be the most "forgiving".
Comment | File | Size | Author |
---|---|---|---|
#17 | less.patch | 6.43 KB | corey.aufang |
#4 | 1536582-look-harder-for-library-4.patch | 3.15 KB | thedavidmeister |
#3 | 1536582-try-harder-to-find-libraries-module-3.patch | 535 bytes | thedavidmeister |
Comments
Comment #1
corey.aufang CreditAttribution: corey.aufang commentedI would like #2 or its equivalent.
For "normal" users that download the module and install it on the module list page, I want the installation to fail if the library is not found.
I also want it to fail if the library is not found in a Drush or install profile install.
I believe that its important for the module to not be enabled if it is not able to perform its function through the absence of the required lessphp library.
I don't want to give the user a sense that things are fine, when the module will fail to perform, especially if there are modules that depend on the this module to function.
I agree that this needs to be resolved, but it still needs to block installation if the library is absent.
Comment #2
thedavidmeister CreditAttribution: thedavidmeister commentedReally? I can't think of any other modules that block installation when they can't find a third party module or API key they need to function. All the modules I can think of that rely on something external politely throw an error and then proceed to do nothing - WYSIWYG, Google Analytics, plupload..
I personally don't see the advantage for "normal" users "fail to install" has over "install but don't do anything, and throw an error on every page".
Since the lessphp library was removed from being bundled with this library (for good reason), for the sake of "normal" users this module causes any profile built by professional users that include the module to completely fail building.
Anyway, comment out line 57 of less.install, this one:
And the error becomes a runtime problem rather than an install time problem. I'm going to get lunch, and then I'll send through some proper patches. At least my build isn't dead anymore >.<
Comment #3
thedavidmeister CreditAttribution: thedavidmeister commentedHere's a patch that implements suggestion #2, it just loads the libraries' module file and then checks for existence of libraries_get_path() before calling it. Ends up being that little bit more robust when you're installing LESS with a profile instead of the "normal" way through the UI. Well.. it works on my setup at least! :P
IMO if the decision is made not to do #1 because corey doesn't like that idea, i think we probably *should* try to look harder for the library when the fate of the whole site build hangs in the balance.
Well, that's a bit of FUD. The entire Libraries module is 102 lines long across just two functions, they're not really about catering for module developers with "special cases" there. The opposite is more true in that they're encouraging good standards by forcing developers who want to leverage the Libraries API to do things the "right" way.
Libraries currently does this in libraries_get_path (and nothing else):
It wouldn't be very hard to check the first 3 places as a fallback if the libraries module is not installed on a site and that's inline with what is supported by D7, and was the same in d6 core anyway. You'd only have to update the list once every major release of Drupal at the most.
Comment #4
thedavidmeister CreditAttribution: thedavidmeister commentedI reworked less_requirements() and _less_inc_path() a bit here to make something a bit better (hopefully) than the last patch I pushed.
Here's a quick summary of what I'm attempting here:
I'm hoping that by putting the path search all in the one place, it becomes a bit easier to maintain (as well as fixing the issue raised here) :)
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedUpdate: I've done some testing for that previous patch by building a platform in Aegir and creating a bunch of new sites with this profile and doing a basic test with nested styles in my .less file to see that it is working ok after installation.
With Libraries, lessphp is in:
* /profiles/profilename/libraries - works
* the less module's directory - works
* sites/all - works
Without Libraries, lessphp is in:
* /profiles/profilename/libraries - works
* the less module's directory - works
* sites/all - works
Wasn't sure how to test putting the library in the site's folder at install time with a profile, so I couldn't test that it was working at install time.
Hope that helps get this committed :)
Comment #6
radimklaskaJust tested #4 on BOA. Works fine! Thanks!
Comment #7
TinaRey CreditAttribution: TinaRey commentedThanks for patch #4, works for me :) (lessphp in profiles/profilename/libraries)
Comment #8
corey.aufang CreditAttribution: corey.aufang commentedOk, I like most of the work in #1536582-4: Drush site-install and sites using an installation profile cannot work with less.module as it's too strict about finding lessphp but I'm wondering about the "looking harder" part.
Since the latest version of LESS now has Libraries marked as a dependency, isn't it redundant to do the same work that the Libraries module does, again?
Comment #9
thedavidmeister CreditAttribution: thedavidmeister commentedThis issue is that including this module in an install profile currently makes it impossible to install sites on that profile. No module should cause a whole profile to fail installation simply by enabling it without a stellar reason.
If you're going to cause installation of a whole site to fail when the LESS module can't find it's library, then you should be doing everything you can to ensure that if the lessphp library is discoverable you do discover it.
I didn't actually realize that Libraries was added as a dependency when I was testing my code, which is why I added that "try harder" bit. Removing that aspect of my patch is probably fine if you've also added the dependency for the Library. That said, it looks like installation of modules is subtly different during site installation to standalone post-installation so if you're going to remove the "safety" part of my patch please test the shit out of your changes with the Libraries module absent so that profiles aren't needlessly broken again.
Thanks for reviewing the patch btw.
Comment #10
rupertj CreditAttribution: rupertj commentedRelying on libraries API by itself won't work for fresh installs. This is because the requirements are checked before any modules are installed (and, hence, libraries API is not available to help you with the check).
Either the requirements code needs to be better (which patch 4 provides) or this module needs to stop blocking the installation process (which sounds like a much better option to me).
Comment #11
rupertj CreditAttribution: rupertj commentedIf you're stuck until this patch is committed, the following in your makefile will let your site install:
projects[less][version] = 2.5
projects[less][patch][] = "http://drupal.org/files/1536582-look-harder-for-library-4.patch"
libraries[lessphp][download][type] = "file"
libraries[lessphp][download][url] = "http://github.com/leafo/lessphp/tarball/master"
Comment #12
thedavidmeister CreditAttribution: thedavidmeister commented@ruperj - actually, in the patch in #4 because I'm using module_load_include('module', 'libraries'); just before I call the libraries API, we can use it even in fresh installs because we're manually including the relevant files to get access to the functions we need.
#4 will leverage Libraries if you have it, and simulate it if you don't and will do both in either a fresh site install, or at a later date.
Thanks for the makefile example, I'd only suggest that you lock your lessphp download to a specific revision rather than rely on "master"; I've personally had some... interesting experiences with bug regressions and newly introduced syntax changes across different versions of lessphp.
Obviously replace that revision hash as required, that's just the one that is current today :)
Comment #13
corey.aufang CreditAttribution: corey.aufang commentedWhen including a pull directly from a repository like this, I think you can specify a tag:
This allows you to make it a little more "official" if you prefer.
Comment #14
thedavidmeister CreditAttribution: thedavidmeister commentedlol, we're drifting off topic now, talking about best way to write a make file.. can we get anything committed to fix the original issue? the "looking harder" bit is only one array and one (small) function so surely you could drop it in as-is because we know it works and is never even fired if Libraries API is present.
We can always open a separate issue to "rely on libraries API exclusively to scan file paths" and link to this thread so we remember what needs to be tested in order to be comfortable that we are indeed always attempting to do something redundant here and it is safe to crop out that extra step.
To be honest, not sure when I'm next going to feel like doing a round of testing for this thread, and nobody else looks like they're jumping at the chance to help out so I feel kinda bad if we're holding back a working fix for a legitimate problem because everyone is waiting on me to watch spinny wheel in Aegir for an hour or so.
Comment #15
rupertj CreditAttribution: rupertj commented@thedavidmeister I had spotted you were loading the include manually, I just wrongly assumed that because the libraries module isn't enabled yet, the include wouldn't load. That's pretty cunning.
I'm in total agreement with commiting the patch in #4 and opening a new issue for libraries. Given how 3 people have said it fixes their issue, can't we call it RTBC now?
Comment #16
thedavidmeister CreditAttribution: thedavidmeister commentedsure, why not
Comment #17
corey.aufang CreditAttribution: corey.aufang commentedCouple of updates
Install doesn't block on absence of lessphp library.
If library is missing, files will be output to the page without modification, meaning with their .less extension.
This works fine in install profiles, but I don't have proof about Drush Make, tho it should work fine.
I'm also committing this, so you should be able to grab a dev of this soon.
Comment #18
lotyrin CreditAttribution: lotyrin commentedComment #19
thedavidmeister CreditAttribution: thedavidmeister commentedHey Corey, is this in dev yet? I like the work that I see in that latest patch.
Also, totally a technicality but Drush Make doesn't actually do anything with regard to installing sites, it's just a tool for downloading Drupal projects and applying patches to code so nothing we've discussed here can cause it to fail ever. The name of this issue is wrong really so I'll update it to make it more google-able. Drush site-install is the bit that actually tries to fire up a new site with a database and if that fails then developers using Aegir/Hostmaster will see things failing too.
I really think the crux of the problem was to do with install profiles so I think we're in the clear here if that is fixed. I also saw the bit in that patch about downgrading the severity of the requirements warning being thrown, which is nice.
Comment #20
opiTrying to apply these patches within a drush.make file. (Using projects[less][patch][] = URL).
- #4 works fine, installation doesn't break anymore
- #17 gives error on drush.make ( "Unable to patch less with less.patch.")
Comment #21
RobLoachComposer support would be neat. Has no issues installing using that.
Comment #22
corey.aufang CreditAttribution: corey.aufang commentedFix for this should be in the latest dev.
Will be pushing new version soon.
The reason I think that #1536582-17: Drush site-install and sites using an installation profile cannot work with less.module as it's too strict about finding lessphp was not applying is that it was based of a version of dev, rather than release.
Also it was not intended to be used, but purely for review.
Comment #23
corey.aufang CreditAttribution: corey.aufang commentedForgot to mark as mixed.
Comment #25
anilnaut111 CreditAttribution: anilnaut111 commentedI am tying to use lesscss module for drupal5 (installation has been sucesfull) but not working/not compiling less files for me can any one help me out.
NOTE: I have added less file as drupal_add_css('myfile.css.less'). Also I am not getting any error on page.
LESS CSS Preprocessor version: 2.6
Comment #26
thedavidmeister CreditAttribution: thedavidmeister commented@anilnaut111 - that question has nothing to do with this thread. Please open your own ticket, as this thread isn't even open atm..