Skip to content

pip.installed does not work with ancient pip versions #33393

Closed

Description

@wwentland

Summary

Salt 2015.8.4 included 9cb1733 which does not work with ancient pip versions such as 1.1 which is shipped on Debian wheezy.

Analysis

The aforementioned commit contains the following change:

 commit 9cb17332fa0d708c9262ee2b357e0f608fa0749a
Author: justinta89 <[email protected]>
Date:   Wed Jan 20 14:43:50 2016 -0700

    Updated pip_state to work with pip 8.0 on 2015.8

diff --git a/salt/states/pip_state.py b/salt/states/pip_state.py
index 4796406..91b80a1 100644
--- a/salt/states/pip_state.py
+++ b/salt/states/pip_state.py
@@ -47,6 +47,14 @@ if HAS_PIP is True:
         del pip
         if 'pip' in sys.modules:
             del sys.modules['pip']
+
+    ver = pip.__version__.split('.')
+    pip_ver = tuple([int(x) for x in ver if x.isdigit()])
+    if pip_ver >= (8, 0, 0):
+        from pip.exceptions import InstallationError
+    else:
+        InstallationError = ValueError
+
 # pylint: enable=import-error

 logger = logging.getLogger(__name__)
@@ -135,7 +143,7 @@ def _check_pkg_version_format(pkg):
                         break
             else:
                 install_req = pip.req.InstallRequirement.from_line(pkg)
-    except ValueError as exc:
+    except (ValueError, InstallationError) as exc:
         ret['result'] = False
         if not from_vcs and '=' in pkg and '==' not in pkg:
             ret['comment'] = (

which refers to pip.__version__ which is not present in old pip versions.

# pip --version
pip 1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
# python
>>> import pip
>>> pip.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'

That variable was added in pypa/pip@d9599ec and released with pip 1.2.

There have been other pip related problems such as #33376 which was addressed by @thatch45 in #33383, but this one is likely to be different. It would be much appreciated if this issue could get addressed soon also.

Just realised that cf20f48 was also never backported to 2015.8.

Additonal information

I have the following state:

python-pip:
  pkg.installed

flake8:
  pip.installed

Behaviour on 2015.8.10

# salt-master --version
salt-master 2015.8.10 (Beryllium)
# salt-call state.highstate
[...]
[ERROR   ] Failed to import states pip_state, this is due most likely to a syntax error:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1136, in _load_module
    ), fn_, fpath, desc)
  File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 52, in <module>
    ver = pip.__version__.split('.')
AttributeError: 'module' object has no attribute '__version__'
[INFO    ] Executing command ['git', '--version'] in directory '/root'
[INFO    ] Running state [flake8] at time 18:02:20.063532
[ERROR   ] State 'pip.installed' was not found in SLS 'pip_bug'
Reason: 'pip.installed' is not available.

local:
----------
          ID: python-pip
    Function: pkg.installed
      Result: True
     Comment: Package python-pip is already installed
     Started: 18:02:19.826958
    Duration: 171.38 ms
     Changes:   
----------
          ID: flake8
    Function: pip.installed
      Result: False
     Comment: State 'pip.installed' was not found in SLS 'pip_bug'
              Reason: 'pip.installed' is not available.
     Started: 
    Duration: 
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    1
------------
Total states run:     2

Behaviour on 2015.8.10 with my changes from #33396:

# salt-call state.highstate
[...]
[INFO    ] Completed state [python-pip] at time 18:06:51.932863
[INFO    ] Running state [flake8] at time 18:06:51.948307
[INFO    ] Executing state pip.installed for flake8
[INFO    ] Executing command ['/usr/bin/pip', 'freeze'] in directory '/root'
[INFO    ] Executing command ['/usr/bin/pip', 'install', 'flake8'] in directory '/root'
[INFO    ] Executing command ['/usr/bin/pip', 'freeze'] in directory '/root'
[INFO    ] {'flake8==2.5.4': 'Installed'}
[INFO    ] Completed state [flake8] at time 18:06:53.582907
local:
----------
          ID: python-pip
    Function: pkg.installed
      Result: True
     Comment: Package python-pip is already installed
     Started: 18:06:51.743888
    Duration: 188.975 ms
     Changes:   
----------
          ID: flake8
    Function: pip.installed
      Result: True
     Comment: All packages were successfully installed
     Started: 18:06:51.948307
    Duration: 1634.6 ms
     Changes:   
              ----------
              flake8==2.5.4:
                  Installed

Summary for local
------------
Succeeded: 2 (changed=1)
Failed:    0
------------
Total states run:     2

Thank you!

Activity

  1. Ch3LL commented on May 20, 2016

    @Ch3LL
    Contributor

    @BABILEN thanks for the PR! Its really appreciated. We will keep this open until the PR is merged 👍

  2. added
    bug
    severity-medium
    P4
    Platform
    on May 20, 2016
  3. added this to the Approved milestone on May 20, 2016
  4. added
    fixed-pls-verify
    on May 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4PlatformState-Modulebugfixed-pls-verifyseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions