Skip to content

Commit

Permalink
Switch from deprecated conda.core.index.get_index to `conda.core.in…
Browse files Browse the repository at this point in the history
…dex.Index` (#5488)

Co-authored-by: Ken Odegard <kodegard@anaconda.com>
  • Loading branch information
zklaus and kenodegard authored Oct 2, 2024
1 parent 6f20ff7 commit 0ef3749
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 45 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
if: github.event_name != 'pull_request'

- name: Filter Changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
Expand Down Expand Up @@ -111,13 +111,13 @@ jobs:
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-type }}-$(date -u "+%Y%m")" >> $GITHUB_ENV

- name: Cache Conda
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/conda_pkgs_dir
key: cache-${{ env.HASH }}

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
condarc-file: .github/condarc
run-post: false # skip post cleanup
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:

- name: Upload Test Results
if: '!cancelled()'
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.4.0
with:
name: test-results-${{ env.HASH }}
path: |
Expand Down Expand Up @@ -191,13 +191,13 @@ jobs:
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-benchmark-$(date -u "+%Y%m")" >> $GITHUB_ENV

- name: Cache Conda
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/conda_pkgs_dir
key: cache-${{ env.HASH }}

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
condarc-file: .github/condarc
run-post: false # skip post cleanup
Expand All @@ -210,7 +210,6 @@ jobs:
--file tests/requirements-${{ runner.os }}.txt
--file tests/requirements-ci.txt
python=${{ matrix.python-version }}
conda=24.7
- name: Install CodSpeed
run: pip install git+https://github.com/kenodegard/pytest-codspeed.git@fix-outerr-redirects#egg=pytest-codspeed
Expand Down Expand Up @@ -272,13 +271,13 @@ jobs:
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-type }}-$(date -u "+%Y%m")" >> $GITHUB_ENV

- name: Cache Conda
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/conda_pkgs_dir
key: cache-${{ env.HASH }}

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
condarc-file: .github\condarc
run-post: false # skip post cleanup
Expand Down Expand Up @@ -324,7 +323,7 @@ jobs:

- name: Upload Test Results
if: '!cancelled()'
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.4.0
with:
name: test-results-${{ env.HASH }}
path: |
Expand Down Expand Up @@ -374,15 +373,15 @@ jobs:
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-${{ matrix.conda-version }}-${{ matrix.test-type }}-$(date -u "+%Y%m")" >> $GITHUB_ENV

- name: Cache Conda
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
~/conda_pkgs_dir
~/macosx_sdks
key: cache-${{ env.HASH }}

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
condarc-file: .github/condarc
run-post: false # skip post cleanup
Expand Down Expand Up @@ -442,7 +441,7 @@ jobs:

- name: Upload Test Results
if: '!cancelled()'
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.4.0
with:
name: test-results-${{ env.HASH }}
path: |
Expand All @@ -468,13 +467,13 @@ jobs:

- name: Upload Combined Test Results
# provides one downloadable archive of all matrix run test results for further analysis
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.4.0
with:
name: test-results-${{ github.sha }}-all
path: test-results-*

- name: Test Summary
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
with:
paths: test-results-*/test-report.xml

Expand All @@ -486,7 +485,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Determine Success
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
# permit jobs to be skipped if there are no code changes (see changes job)
allowed-skips: ${{ toJSON(needs) }}
Expand Down
35 changes: 24 additions & 11 deletions conda_build/index.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

import logging
import os
from functools import partial
from os.path import dirname
from typing import TYPE_CHECKING

from conda.base.context import context
from conda.core.index import get_index
from conda.exceptions import CondaHTTPError
from conda.utils import url_path
from conda_index.index import update_index as _update_index
Expand All @@ -17,6 +19,19 @@
get_logger,
)

if TYPE_CHECKING:
from conda.models.channels import Channel

try:
from conda.core.index import Index
except ImportError:
# FUTURE: remove for `conda >=24.9`
from conda.core.index import get_index

def Index(channels: tuple[str | Channel, ...] = (), *args, **kwargs) -> dict: # type: ignore[no-redef]
return get_index(channel_urls=channels, *args, **kwargs)


log = get_logger(__name__)


Expand Down Expand Up @@ -103,26 +118,24 @@ def get_build_index(
if subdir == "noarch":
subdir = context.subdir
try:
# get_index() is like conda reading the index, not conda_index
# Index() is like conda reading the index, not conda_index
# creating a new index.
cached_index = get_index(
channel_urls=urls,
cached_index = Index(
channels=urls,
prepend=not omit_defaults,
use_local=False,
use_cache=context.offline,
platform=subdir,
use_local=False,
)
# HACK: defaults does not have the many subfolders we support. Omit it and
# try again.
except CondaHTTPError:
if "defaults" in urls:
urls.remove("defaults")
cached_index = get_index(
channel_urls=urls,
prepend=omit_defaults,
use_local=False,
use_cache=context.offline,
cached_index = Index(
channels=urls,
prepend=not omit_defaults,
platform=subdir,
use_local=False,
)

local_index_timestamp = os.path.getmtime(index_file)
Expand Down
9 changes: 7 additions & 2 deletions conda_build/inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from conda.api import Solver
from conda.base.context import context
from conda.cli.common import specs_from_args
from conda.core.index import get_index
from conda.core.prefix_data import PrefixData
from conda.models.records import PrefixRecord

Expand All @@ -38,6 +37,12 @@
package_has_file,
)

try:
from conda.core.index import Index
except ImportError:
# FUTURE: remove for `conda >=24.9`
from conda_build.index import Index

if TYPE_CHECKING:
from typing import Iterable, Literal

Expand Down Expand Up @@ -173,7 +178,7 @@ def test_installable(channel: str = "defaults") -> bool:
success = True
for subdir in ["osx-64", "linux-32", "linux-64", "win-32", "win-64"]:
log.info("######## Testing subdir %s ########", subdir)
for prec in get_index(channel_urls=[channel], prepend=False, platform=subdir):
for prec in Index(channels=[channel], prepend=False, platform=subdir):
name = prec["name"]
if name in {"conda", "conda-build"}:
# conda can only be installed in the root environment
Expand Down
9 changes: 7 additions & 2 deletions conda_build/skeletons/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from os.path import basename, dirname, exists, join

import requests
from conda.core.index import get_index
from conda.exceptions import CondaError, CondaHTTPError
from conda.gateways.connection.download import TmpDownload, download
from conda.gateways.disk.create import TemporaryDirectory
Expand All @@ -34,6 +33,12 @@
from ..variants import get_default_variant
from ..version import _parse as parse_version

try:
from conda.core.index import Index
except ImportError:
# FUTURE: remove for `conda >=24.9`
from conda_build.index import Index

CPAN_META = """\
{{% set name = "{packagename}" %}}
{{% set version = "{version}" %}}
Expand Down Expand Up @@ -695,7 +700,7 @@ def latest_pkg_version(pkg):
"""
:returns: the latest version of the specified conda package available
"""
r = Resolve(get_index())
r = Resolve(Index())
try:
pkg_list = sorted(r.get_pkgs(MatchSpec(pkg)))
except:
Expand Down
33 changes: 19 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,31 @@ doctest_optionflags = [
"ALLOW_UNICODE",
"ELLIPSIS",
]
# filterwarnings = [
# # elevate conda's deprecated warning to an error
# "error::PendingDeprecationWarning:conda",
# "error::DeprecationWarning:conda",
# # elevate conda-build's deprecated warning to an error
# "error::PendingDeprecationWarning:conda_build",
# "error::DeprecationWarning:conda_build",
# # ignore numpy.distutils error
# 'ignore:\s+`numpy.distutils` is deprecated:DeprecationWarning:conda_build._load_setup_py_data',
# # ignore conda-index error
# "ignore::PendingDeprecationWarning:conda_index",
# "ignore::DeprecationWarning:conda_index",
# "ignore:Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata:DeprecationWarning",
# ]
filterwarnings = [
# elevate conda's deprecated warning to an error
"error::PendingDeprecationWarning:conda",
"error::DeprecationWarning:conda",
# elevate conda-build's deprecated warning to an error
"error::PendingDeprecationWarning:conda_build",
"error::DeprecationWarning:conda_build",
# ignore numpy.distutils error
'ignore:\s+`numpy.distutils` is deprecated:DeprecationWarning:conda_build._load_setup_py_data',
# ignore conda-index error
"ignore::PendingDeprecationWarning:conda_index",
"ignore::DeprecationWarning:conda_index",
# ignore conda-package-streaming error
"ignore:conda.core.index._supplement_index_with_system is pending deprecation:PendingDeprecationWarning:conda",
"ignore:conda.core.index._make_virtual_package is pending deprecation:PendingDeprecationWarning:conda",
# ignore tarfile
"ignore:Python 3.14 will, by default, filter extracted tar archives:DeprecationWarning",
]
markers = [
"serial: execute test serially (to avoid race conditions)",
"slow: execute the slow tests if active",
"sanity: execute the sanity tests",
"no_default_testing_config: used internally to disable monkeypatching for testing_config",
"benchmark: execute the benchmark tests",
"memray: memory use tests",
]
minversion = 3.0
norecursedirs = ["tests/test-recipes/*"]
Expand Down

0 comments on commit 0ef3749

Please sign in to comment.