state to cleanly check for pip.installed on a package in a git repo

239 views
Skip to first unread message

Nick Davis

unread,
Nov 14, 2012, 5:24:38 PM11/14/12
to salt-...@googlegroups.com
Hello Saltiers,
 I'm trying to ensure the python module django-orm-extensions is installed. It is coming from a git repo. I thought the best way to do this would be with a pip.installed state, but that seems to have a slight issue. Let me explain:

Here was my first try:

django-orm-extensions:
  pip.installed:
    - require:
      - pip: django-orm
      - pkg: git

This returned an error:
2012-11-14 21:28:05,065 [salt.loaded.int.module.cmdmod               ][ERROR   ] Command '/usr/bin/pip install django-orm-extensions  --editable=git+git://github.com/niwibe/django-orm-extensions.git@master#egg=django-orm-extensions ' failed with return code: 1
2012-11-14 21:28:05,066 [salt.loaded.int.module.cmdmod               ][ERROR   ] stdout: Double requirement given: django-orm-extensions from git+git://github.com/niwibe/django-orm-extensions.git@master#egg=django-orm-extensions (aready in django-orm-extensions, name='django-orm-extensions')

So my next attempt was this:

django-orm-extensions:
  pip.installed:
    - require:
      - pip: django-orm
      - pkg: git

This installed the package correctly, but there is a returned comment from salt that implies something isn't right:

    State: - pip
    Function:  installed
        Result:    True
        Comment:   There was no error installing package 'git+git://github.com/niwibe/django-orm-extensions.git@master#egg=django-orm-extensions' although it does not show when calling 'pip.freeze'.
  
If I run pip freeze manually, it shows that the module was installed:

django-orm-extensions==3.0b3

It seems that the salt state is trying to equate this string:

django-orm-extensions==3.0b3

to this string:


The side-effect of this inability to do a proper comparison is that every time I run state.highstate, it will re-install that python module.


Is there a better way to do this?

Thanks,
Nick

Nick Davis

unread,
Nov 14, 2012, 8:13:20 PM11/14/12
to salt-...@googlegroups.com
Looking into this some more, I think that pip.installed will need an additional parameter.

It is perfectly legal to do this:


The direct salt state would be similar to:

django-orm-extensions:
  pip.installed:
    - require:
      - pip: django-orm
      - pkg: git

Unfortunately, that salt state will not work. When a package is installed from a repo, it is installed as the actual package name, not the path to the package in the repo. So, when pip.installed uses pip.freeze and pip.list to determine if the package is already installed, it has no standard method by which it would know what the name of the package actually is. The current design will compare the value in the 'name' param to those returned by pip.freeze and never succeed.

I propose adding another param to pip.installed. We could call it 'repo'.

The salt state would look like this:

django-orm-extensions:
  pip.installed:
    - require:
      - pip: django-orm
      - pkg: git

In this case the important parts are:

name=django-orm-extensions

Then, the name param can be used in the comparisons in pip.freeze and pip.list. And the repo value can be passed as the 'name' param to pip.install.

This would include 2 small changes to pip.installed.

1. add "repo=None," to the definition
2. on line 83, add this:
if repo:
  name = repo

If this seems reasonable, I'll happily code up the change and send in a Pull Request.

Nick
Reply all
Reply to author
Forward
0 new messages