Skip to content

Commit

Permalink
Fix missing __unix virtual package in 22.11 (conda#12148)
Browse files Browse the repository at this point in the history
* Add test for default virtual system packages

* Restore default virtual package specs as in 22.9.0

* Add news/12148-restore-default-virtual-packages

* Properly skip virtual packages with no name

* Avoid empty -> "0" build string for __archspec

Overlooked before; this just restores <22.11.0 behavior.
  • Loading branch information
mbargull authored Dec 5, 2022
1 parent 3163cba commit 1ce87c3
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 16 deletions.
12 changes: 6 additions & 6 deletions conda/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def _supplement_index_with_cache(index):
index[pcrec] = pcrec


def _make_virtual_package(name, version=None, build_string='0'):
def _make_virtual_package(name, version=None, build_string=None):
return PackageRecord(
package_type=PackageType.VIRTUAL_SYSTEM,
name=name,
version=version or '0',
build_string=build_string,
build_string=build_string or '0',
channel='@',
subdir=context.subdir,
md5="12345678901234567890123456789012",
Expand All @@ -174,6 +174,8 @@ def _supplement_index_with_system(index):
registered_names = []
packages = context.plugin_manager.get_hook_results("virtual_packages")
for package in packages:
if package.name is None:
continue
if package.name in registered_names:
raise PluginError(
"Conflicting virtual package entries found for the "
Expand All @@ -184,10 +186,8 @@ def _supplement_index_with_system(index):
)
registered_names.append(package.name)

rec = _make_virtual_package(f"__{package.name}", package.version)

if package.version is not None:
index[rec] = rec
rec = _make_virtual_package(f"__{package.name}", package.version, package.build)
index[rec] = rec


def get_archspec_name():
Expand Down
1 change: 1 addition & 0 deletions conda/plugins/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def conda_virtual_packages():
yield plugins.CondaVirtualPackage(
name="my_custom_os",
version="1.2.3",
build="x86_64",
)
"""
2 changes: 2 additions & 0 deletions conda/plugins/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class CondaVirtualPackage(NamedTuple):
:param name: Virtual package name (e.g., ``my_custom_os``).
:param version: Virtual package version (e.g., ``1.2.3``).
:param version: Virtual package build string (e.g., ``x86_64``).
"""

name: str
version: str | None
build: str | None


class CondaSolver(NamedTuple):
Expand Down
4 changes: 3 additions & 1 deletion conda/plugins/virtual_packages/archspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
def conda_virtual_packages():
from ...core.index import get_archspec_name

yield CondaVirtualPackage("archspec", get_archspec_name())
archspec_name = get_archspec_name()
if archspec_name:
yield CondaVirtualPackage("archspec", "1", archspec_name)
4 changes: 3 additions & 1 deletion conda/plugins/virtual_packages/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ def cached_cuda_version():

@hookimpl
def conda_virtual_packages():
yield CondaVirtualPackage("cuda", cached_cuda_version())
cuda_version = cached_cuda_version()
if cuda_version is not None:
yield CondaVirtualPackage("cuda", cuda_version, None)
6 changes: 3 additions & 3 deletions conda/plugins/virtual_packages/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def conda_virtual_packages():
if platform.system() != "Linux":
return

yield CondaVirtualPackage("unix", None)
yield CondaVirtualPackage("unix", None, None)

# By convention, the kernel release string should be three or four
# numeric components, separated by dots, followed by vendor-specific
Expand All @@ -23,11 +23,11 @@ def conda_virtual_packages():
# development (`-rcN`) kernels, but that can be a TODO for later.
dist_version = os.environ.get("CONDA_OVERRIDE_LINUX", platform.release())
m = re.match(r"\d+\.\d+(\.\d+)?(\.\d+)?", dist_version)
yield CondaVirtualPackage("linux", m.group() if m else "0")
yield CondaVirtualPackage("linux", m.group() if m else "0", None)

libc_family, libc_version = linux_get_libc_version()
if not (libc_family and libc_version):
# Default to glibc when using CONDA_SUBDIR var
libc_family = "glibc"
libc_version = os.getenv(f"CONDA_OVERRIDE_{libc_family.upper()}", libc_version)
yield CondaVirtualPackage(libc_family, libc_version)
yield CondaVirtualPackage(libc_family, libc_version, None)
4 changes: 2 additions & 2 deletions conda/plugins/virtual_packages/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def conda_virtual_packages():
if platform.system() != "Darwin":
return

yield CondaVirtualPackage("unix", None)
yield CondaVirtualPackage("unix", None, None)

dist_version = os.environ.get("CONDA_OVERRIDE_OSX", platform.mac_ver()[0])
yield CondaVirtualPackage("osx", dist_version)
yield CondaVirtualPackage("osx", dist_version, None)
2 changes: 1 addition & 1 deletion conda/plugins/virtual_packages/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def conda_virtual_packages():
if platform.system() != "Windows":
return

yield CondaVirtualPackage("win", None)
yield CondaVirtualPackage("win", None, None)
21 changes: 21 additions & 0 deletions news/12148-restore-default-virtual-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Enhancements

* <news item>

### Bug fixes

* Restore default virtual package specs as in 22.9.0 (#12148)
- re-add `__unix`/`__win` packages
- restore `__archspec` version/build string composition

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
32 changes: 31 additions & 1 deletion tests/core/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest

from conda.base.constants import DEFAULT_CHANNELS
from conda.base.context import context, Context, conda_tests_ctxt_mgmt_def_pol
from conda.base.context import context, Context, conda_tests_ctxt_mgmt_def_pol, non_x86_machines
from conda.common.compat import on_win, on_mac, on_linux
from conda.common.io import env_vars
from conda.core.index import check_allowlist, get_index, get_reduced_index, _supplement_index_with_system
Expand Down Expand Up @@ -42,6 +42,36 @@ def test_check_allowlist():
check_allowlist(("conda-canary",))


def test_supplement_index_with_system():
index = {}
_supplement_index_with_system(index)

has_virtual_pkgs = {
rec.name
for rec in index
if rec.package_type == PackageType.VIRTUAL_SYSTEM
}.issuperset
if on_win:
assert has_virtual_pkgs({"__win"})
elif on_mac:
assert has_virtual_pkgs({"__osx", "__unix"})
elif on_linux:
assert has_virtual_pkgs({"__glibc", "__linux", "__unix"})


@pytest.mark.skipif(
context.subdir.split("-", 1)[1] not in {"32", "64", *non_x86_machines},
reason=f"archspec not available for subdir {context.subdir}",
)
def test_supplement_index_with_system_archspec():
index = {}
_supplement_index_with_system(index)
assert any(
rec.package_type == PackageType.VIRTUAL_SYSTEM and rec.name == "__archspec"
for rec in index
)


def test_supplement_index_with_system_cuda(clear_cuda_version):
index = {}
with env_vars({'CONDA_OVERRIDE_CUDA': '3.2'}):
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_get_hook_results(plugin_manager):
class SecondArchspec:
@plugins.hookimpl
def conda_virtual_packages():
yield plugins.CondaVirtualPackage("archspec", "")
yield plugins.CondaVirtualPackage("archspec", "", None)

plugin_manager.register(SecondArchspec)
with pytest.raises(
Expand Down
4 changes: 4 additions & 0 deletions tests/plugins/test_virtual_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ def conda_virtual_packages(self):
yield CondaVirtualPackage(
name="abc",
version="123",
build=None,
)
yield CondaVirtualPackage(
name="def",
version="456",
build=None,
)
yield CondaVirtualPackage(
name="ghi",
version="789",
build="xyz",
)


Expand All @@ -52,6 +55,7 @@ def test_invoked(plugin):
assert packages["__abc"].version == "123"
assert packages["__def"].version == "456"
assert packages["__ghi"].version == "789"
assert packages["__ghi"].build == "xyz"


def test_duplicated(plugin_manager):
Expand Down

0 comments on commit 1ce87c3

Please sign in to comment.