skip css:styleguide when python2 is not available

refs FOO-966

pygments.rb, a dependency of dress_code, requires a python 2 interpreter
and will look for it in PATH (under the name of "python2"). This patch
makes the requirement more graceful in development where we skip the
task when python2 is unavailable, and issue a warning with instructions
on how to make it work.

|
| TEST PLAN
|

I used pyenv[1] to install python3, but you can use virtualenv too or
whatever your system has; all you need is access to both python2 and
python3 interpreters.

- with python2 available in PATH, verify the task works fine:

    bundle exec rake css:styleguide

- with python != 2, verify the task is skipped and a warning is issued
  but the process exits with 0 (success):

    PYGMENTS_RB_PYTHON=python3 \
      bundle exec rake css:styleguide

    echo $? # => 0

[1]: https://github.com/pyenv/pyenv

Change-Id: Icfdcfa6a17a879f05e0528b97e8202c5a2db986d
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/248436
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Simon Williams <simon@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Ahmad Amireh 2020-09-24 10:26:07 -06:00
parent f1f481b1b6
commit 76771ce53d
1 changed files with 21 additions and 1 deletions

View File

@ -1,9 +1,29 @@
namespace :css do
desc "Generate styleguide"
task :styleguide do
if ENV.fetch('RAILS_ENV', 'development') == 'development'
# python2 --version outputs to stderr, while python3 to stdout.......
python_version = `#{Pygments::Popen.new.find_python_binary} --version 2>&1` rescue nil
python_version ||= '???'
unless python_version.strip =~ /^Python 2/
next warn <<~MESSAGE
Generating the CSS styleguide requires Python 2, but you have #{python_version}.
If you already have a Python 2 installation, make sure it is available
in your PATH under the name of "python2". If the name of the
interpreter is different, adjust it in the following environment
variable:
PYGMENTS_RB_PYTHON=custom-python-interpreter
MESSAGE
end
end
puts "--> creating styleguide"
system('bin/dress_code config/styleguide.yml')
raise "error running dress_code" unless $?.success?
fail "error running dress_code" unless $?.success?
end
task :compile do