-
Notifications
You must be signed in to change notification settings - Fork 1
[ABI Dependency] Best-Effort support for pip
#123
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
Open
DEKHTIARJonathan
wants to merge
10
commits into
main
Choose a base branch
from
abi_dependency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f2e494
[ABI Dependency] Best-Effort support for `pip`
DEKHTIARJonathan 9a4f968
Support Major / Minor / Micro level ABI Compatibility
DEKHTIARJonathan 4e3c685
Update variantlib/resolver/lib.py
DEKHTIARJonathan 90caea7
Fix PR comments
DEKHTIARJonathan 42e6cbe
Move abi_dependency injection into a dedicated function
mgorny 5a5bf17
Add a test for the current implementation
mgorny 276847c
Add tests for envvar overrides
mgorny 5f336fc
Make envvar override installed package versions explicitly
mgorny 6fe4a03
Import `importlib.metadata` using full name
mgorny f530dca
Normalize package names earlier
mgorny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import pytest | ||
| from variantlib.constants import VARIANT_ABI_DEPENDENCY_NAMESPACE | ||
| from variantlib.models.variant import VariantProperty | ||
| from variantlib.resolver.lib import inject_abi_dependency | ||
|
|
||
| if TYPE_CHECKING: | ||
| import pytest_mock | ||
| from variantlib.protocols import VariantNamespace | ||
|
|
||
|
|
||
| @dataclass | ||
| class MockedDistribution: | ||
| name: str | ||
| version: str | ||
|
|
||
|
|
||
| def test_inject_abi_dependency( | ||
| monkeypatch: pytest.MonkeyPatch, mocker: pytest_mock.MockerFixture | ||
| ) -> None: | ||
| monkeypatch.delenv("VARIANT_ABI_DEPENDENCY", raising=False) | ||
|
|
||
| namespace_priorities = ["foo"] | ||
| supported_vprops = [ | ||
| VariantProperty("foo", "bar", "baz"), | ||
| ] | ||
|
|
||
| mocker.patch("importlib.metadata.distributions").return_value = [ | ||
| MockedDistribution("a", "4"), | ||
| MockedDistribution("b", "4.3b1"), | ||
| MockedDistribution("c.ns", "7.2.3.post4"), | ||
| MockedDistribution("d-foo", "1.2.3.4"), | ||
| ] | ||
| inject_abi_dependency(supported_vprops, namespace_priorities) | ||
|
|
||
| assert namespace_priorities == ["foo", VARIANT_ABI_DEPENDENCY_NAMESPACE] | ||
| assert supported_vprops == [ | ||
| VariantProperty("foo", "bar", "baz"), | ||
| VariantProperty("abi_dependency", "a", "4"), | ||
| VariantProperty("abi_dependency", "a", "4.0"), | ||
| VariantProperty("abi_dependency", "a", "4.0.0"), | ||
| VariantProperty("abi_dependency", "b", "4"), | ||
| VariantProperty("abi_dependency", "b", "4.3"), | ||
| VariantProperty("abi_dependency", "b", "4.3.0"), | ||
| VariantProperty("abi_dependency", "c_ns", "7"), | ||
| VariantProperty("abi_dependency", "c_ns", "7.2"), | ||
| VariantProperty("abi_dependency", "c_ns", "7.2.3"), | ||
| VariantProperty("abi_dependency", "d_foo", "1"), | ||
| VariantProperty("abi_dependency", "d_foo", "1.2"), | ||
| VariantProperty("abi_dependency", "d_foo", "1.2.3"), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "env_value", | ||
| [ | ||
| "", | ||
| "c_ns==7.8.9b1", | ||
| "c.ns==7.8.9b1", | ||
| "d==4.9.4,c.ns==7.8.9", | ||
| "a_foo==1.2.79", | ||
| "a-foo==1.2.79,d==4.9.4", | ||
| # invalid components should be ignored (with a warning) | ||
| "no-version", | ||
| "a.foo==1.2.79,no-version", | ||
| "z>=1.2.3", | ||
| ], | ||
| ) | ||
| def test_inject_abi_dependency_envvar( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| mocker: pytest_mock.MockerFixture, | ||
| env_value: str, | ||
| ) -> None: | ||
| monkeypatch.setenv("VARIANT_ABI_DEPENDENCY", env_value) | ||
|
|
||
| namespace_priorities: list[VariantNamespace] = [] | ||
| supported_vprops: list[VariantProperty] = [] | ||
|
|
||
| mocker.patch("importlib.metadata.distributions").return_value = [ | ||
| MockedDistribution("a-foo", "1.2.3"), | ||
| MockedDistribution("b", "4.7.9"), | ||
| ] | ||
| inject_abi_dependency(supported_vprops, namespace_priorities) | ||
|
|
||
| expected = { | ||
| VariantProperty("abi_dependency", "b", "4"), | ||
| VariantProperty("abi_dependency", "b", "4.7"), | ||
| VariantProperty("abi_dependency", "b", "4.7.9"), | ||
| } | ||
| if "a" not in env_value: | ||
| expected |= { | ||
| VariantProperty("abi_dependency", "a_foo", "1"), | ||
| VariantProperty("abi_dependency", "a_foo", "1.2"), | ||
| VariantProperty("abi_dependency", "a_foo", "1.2.3"), | ||
| } | ||
| else: | ||
| expected |= { | ||
| VariantProperty("abi_dependency", "a_foo", "1"), | ||
| VariantProperty("abi_dependency", "a_foo", "1.2"), | ||
| VariantProperty("abi_dependency", "a_foo", "1.2.79"), | ||
| } | ||
| if "c" in env_value: | ||
| expected |= { | ||
| VariantProperty("abi_dependency", "c_ns", "7"), | ||
| VariantProperty("abi_dependency", "c_ns", "7.8"), | ||
| VariantProperty("abi_dependency", "c_ns", "7.8.9"), | ||
| } | ||
| if "d" in env_value: | ||
| expected |= { | ||
| VariantProperty("abi_dependency", "d", "4"), | ||
| VariantProperty("abi_dependency", "d", "4.9"), | ||
| VariantProperty("abi_dependency", "d", "4.9.4"), | ||
| } | ||
|
|
||
| assert namespace_priorities == [VARIANT_ABI_DEPENDENCY_NAMESPACE] | ||
| assert set(supported_vprops) == expected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.