Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a canonical way of determining if two specifiers are mutually exclusive? #762

Closed
notatallshaw opened this issue Jan 5, 2024 · 3 comments

Comments

@notatallshaw
Copy link
Member

notatallshaw commented Jan 5, 2024

I'm working on a Pip optimization and I realize now that I misunderstand one of the expressions I had involving specifiers.

I am interested in understanding given two specifiers is there a canonical way of determining if two specifiers are mutually exclusive? e.g. SpecifierSet('==1.21.6') is mutually exclusive with SpecifierSet('>=1.22.3')

@notatallshaw
Copy link
Member Author

notatallshaw commented Jan 5, 2024

Hmmm, this works for a lot of cases:

def check_conflict(spec_set1: "SpecifierSet", spec_set2: "SpecifierSet") -> bool:
    for spec in spec_set1:
        if spec_set2.contains(spec.version):
            return True
    return False

def mutually_exclusive_specifiers(
    specifier_set1: "SpecifierSet", specifier_set2: "SpecifierSet"
) -> bool:
    return not (
        check_conflict(specifier_set1, specifier_set2)
        or check_conflict(specifier_set2, specifier_set1)
    )

@notatallshaw
Copy link
Member Author

notatallshaw commented Jan 5, 2024

I'm very unsure about boundy conditions that include >, <, or != and compared to ==. E.g. SpecifierSet('>1.21.6') and SpecifierSet('==1.21.6')? Or SpecifierSet('<2.0.0') and SpecifierSet('==2.0.0')? Or SpecifierSet('==3.0.0') and SpecifierSet('!=3.0.0')? Or SpecifierSet('==3.0') and SpecifierSet('!=3.0.0')?

Python package versions are very complex, and with the various, pre, post, dev, alpha, beta, and rc versions, it's not clear to me the correct answer for these boundry conditions.

My objective means for mutually_exclusive_specifiers it's far more important there are no incorrect True results, if there are rare edge cases for incorrect False results that is somewhat acceptable.

@notatallshaw
Copy link
Member Author

notatallshaw commented Jan 6, 2024

It occurs to me that it may not be statically possible to determine if 3 or more specifiers are mutually exclusive, at least in a reasonable amount of time, even if it's possible to determine if 2 specifiers are mutually exclusive.

Firstly even if all 3 pairs of 3 specifiers are not mutually exclusive it does not proove that the 3 specifiers are not mutually exclusive, taking the example of the integers and normal mathematical operators: >0, <>1, <2.

Every pair of this triplet is not mutually exclusive, but the three of them together are mutually exclusive. It's going to have to be enough to say either that a SpecifierSet is "mutually exclusive", is "not mutually exclusive", or "don't know".

Given how much more complex this is than I thought it was, I am going to close this issue as there almost certainly isn't a "canonical" way of handeling this. I will raise specific issues like #766 as I find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant