composer_manager_write_if_changed() bypasses the value of composer_manager_autobuild_file if invoked via the CLI SAPI. There's no indication as to why that's necessary and it causes Drush to return a non-zero exit code when enabling modules via Drush in a read-only environment.
One use case for this is being able to test site installation via continuous integration: we want to prevent the codebase from being modified during integration testing. Drush will return a non-zero exit code, indicating a failure and leading to an overall build failure, even though the rest of the installation succeeded only because Composer Manager ignored composer_manager_autobuild_file and attempted to write where it wasn't allowed.
Comments
Comment #2
mark trappAttached is a patch that removes the bypass.
Comment #3
mark trappLooks like this was originally introduced in #2000694: Rebuild the composer.json file and run composer update only when necessary while enabling a module via Drush. I agree with the sentiment in that issue, especially about being able to run it on hosted environments like Acquia Cloud which do not have write access: another use case for removing the drupal_is_cli() bypass is running Drush as part of a post-deploy hook.
Double-checked to see if 8.x-1.x needed any modifications, and it doesn't look like it: files aren't rebuilt when modules are enabled like 7.x-1.x. They are rebuilt automatically after modules are downloaded via Drush, but that can be prohibited via the SKIP_COMPOSER_UPDATE environment variable.
Comment #4
c4rl commentedI also needed this functionality, it was causing a lot of confusion.
Thanks for the patch, marking RTBC.
Comment #5
c4rl commentedI made these changes explicit in the UI.
Comment #6
c4rl commentedOops typo
Comment #7
matt2000 commented+1 and RTBC on c4rl's UI text update.
Comment #8
markhalliwellIndeed, RTBC. Quite frustrating when enabling modules with drush on remote server.
Comment #10
deviantintegral commentedThis would also be an issue with uninstalling modules. Code looks good and works as advertised. Thanks!