Skip to content

Commit

Permalink
Fix error checking for python json & pkg_resources
Browse files Browse the repository at this point in the history
I forgot safesystem() raises an exception when it fails.

Now, if users have a python that is missing a feature we need in order
to have fpm build a package, you'll get an error like this:

      Your python environment is missing json support (either json or simplejson python module). I cannot continue without this.  {:error=>#<FPM::Util::ProcessFailed: /bin/bash failed (exit code 1).  Full command was:["/bin/bash", "-c", "/opt/my-py24/bin/python -c 'import simplejson'"]>, :python=>"/opt/my-py24/bin/python", :level=>:error}
      Process failed: Python (/opt/my-py24/bin/python) is missing simplejson or json modules. {:level=>:error}

This is for #664
  • Loading branch information
jordansissel committed Apr 23, 2014
1 parent a382386 commit e132cbe
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/fpm/package/python.rb
Expand Up @@ -145,18 +145,19 @@ def load_package_info(setup_py)
attributes[:python_package_name_prefix] = attributes[:python_package_prefix]
end

have_simplejson = safesystem("%{attributes[:python_bin]} -c 'import simplejson'")
have_json = safesystem("%{attributes[:python_bin]} -c 'import json'")
have_pkg_resources = safesystem("%{attributes[:python_bin]} -c 'import pkg_resources'")

if !(have_simplejson || have_json)
@logger.error("Your python environment is missing json support (either json or simplejson python module). I cannot continue without this.", :python => attributes[:python_bin])
raise "Python (#{attributes[:python_bin]}) is missing simplejson or json modules"
begin
safesystem("#{attributes[:python_bin]} -c 'import simplejson'")
safesystem("#{attributes[:python_bin]} -c 'import json'")
rescue FPM::Util::ProcessFailed => e
@logger.error("Your python environment is missing json support (either json or simplejson python module). I cannot continue without this.", :python => attributes[:python_bin], :error => e)
raise FPM::Util::ProcessFailed, "Python (#{attributes[:python_bin]}) is missing simplejson or json modules."
end

if !have_pkg_resources
@logger.error("Your python environment is missing a working setuptools module. I tried to find the 'pkg_resources' module but failed.", :python => attributes[:python_bin])
raise "Python (#{attributes[:python_bin]}) is missing pkg_resources module"
begin
safesystem("#{attributes[:python_bin]} -c 'import pkg_resources'")
rescue FPM::Util::ProcessFailed => e
@logger.error("Your python environment is missing a working setuptools module. I tried to find the 'pkg_resources' module but failed.", :python => attributes[:python_bin], :error => e)
raise FPM::Util::ProcessFailed, "Python (#{attributes[:python_bin]}) is missing pkg_resources module."
end

# Add ./pyfpm/ to the python library path
Expand Down

0 comments on commit e132cbe

Please sign in to comment.