ansible-builder icon indicating copy to clipboard operation
ansible-builder copied to clipboard

Different versions of Python modules in requirements.

Open ecchong opened this issue 2 years ago • 4 comments

When a collection requires a specific version of Python module that is already specified in user requirements.txt with a different version, it generate a requirements.txt that is not valid.

For example, collection "paloaltonetworks.panos" requires pan-os-python==1.5.1. If pan-os-python==1.7.3 is also specified in user's requirements.txt, the ansible-builder introspect command generate a requirements.txt that looks like this

pan-os-python==1.5.1,==1.7.3 # from collection paloaltonetworks.panos,user

It should complain when both are '==' and condition is impossible to meet. Running pip3 install also falied:

$ pip3 install -r new-requirements.txt ERROR: Could not find a version that satisfies the requirement pan-os-python==1.5.1,==1.7.3 (from versions: 1.0.0b1, 1.0.0b2, 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.7.2, 1.7.3) ERROR: No matching distribution found for pan-os-python==1.5.1,==1.7.3

Line 70,71 in ansible_builder/requirements.py should come up with the highest version number or display fail message instead of just joining them.

ecchong avatar Jun 24 '22 21:06 ecchong

Line 70,71 in ansible_builder/requirements.py should come up with the highest version number or display fail message instead of just joining them.

Hmm, in my opinion I think this should not be implemented.

The version specifier == means that an exact matching version should be installed. If user specified pan-os-python==1.7.3, this means that the installed version of pan-os-python MUST 1.7.3 and it can't be satisfied other than 1.7.3, like 1.5.1. Similarly, the requirement from paloaltonetworks.panos cannot be satisfied other than 1.5.1. Refer: https://peps.python.org/pep-0440/#version-specifiers

The error message ERROR: Could not find a version that satisfies the requirement pan-os-python==1.5.1,==1.7.3 you pasted is true, it's true there is no version of pan-os-python that can satisfy ==1.5.1,==1.7.3. This should be reported as error since both requirements can't be satisfied by any version, and any requirements.txt should not be ignored nor overriden by Ansible Builder.

If the user allows any versions other than 1.7.3, simply, user should not specify the version using ==. For example, use pan-os-python<=1.7.3 if the user allows any older versions than 1.7.3. This will install 1.5.1 as this is the version that can satisfy both requirements.

kurokobo avatar Jun 25 '22 00:06 kurokobo

Uh-oh, sorry, I may have misread your comment. Please ignore my comment 😭

There is no grammatical error in writing pan-os-python==1.5.1,==1.7.3, so it looks like we need to implement simple pattern matching for duplicated == (seems a bit hard way since this is also re-implementation of some sort of parser), or actually querying the package to catch the error.

kurokobo avatar Jun 25 '22 06:06 kurokobo

I've heard such requests before, to have builder start down the path of requirements conflict resolution. I don't think this is something we plan to do because pip already informs you if there is a conflict, and is MUCH more capable of determining such things. We cannot simply "pick" one version of a requirement over another for a conflict because we would almost certainly always choose a version that breaks one package but works for another.

The responsibility here is on the creator to resolve the conflicts themselves as there is simply no way to do this correctly in a programmatic fashion. If it were possible, pip would have already implemented it, I would imagine.

Shrews avatar Jun 28 '22 11:06 Shrews

I agree with @Shrews here.

Akasurde avatar Jun 28 '22 11:06 Akasurde

Closing as we do not intend to implement conflict resolution for requirements.

Shrews avatar Mar 01 '23 14:03 Shrews