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

Use lazy Index in conda-build #5363

Closed
wants to merge 12 commits into from
83 changes: 83 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ jobs:
python=${{ matrix.python-version }}
${{ env.CONDA_CHANNEL_LABEL }}${{ env.CONDA_VERSION }}

- name: Install development conda
run: pip install git+https://github.com/zklaus/conda@lazy-index && python -m conda init --install

# TODO: how can we remove this step?
- name: Install Self
run: pip install -e .
Expand Down Expand Up @@ -214,6 +217,9 @@ jobs:
- name: Install CodSpeed
run: pip install git+https://github.com/kenodegard/pytest-codspeed.git@fix-outerr-redirects#egg=pytest-codspeed

- name: Install development conda
run: pip install git+https://github.com/zklaus/conda@lazy-index && python -m conda init --install

# TODO: how can we remove this step?
- name: Install Self
run: pip install -e .
Expand All @@ -234,6 +240,77 @@ jobs:
token: ${{ secrets.CODSPEED_TOKEN }}
run: $CONDA/envs/test/bin/pytest --codspeed

# linux memray
linux-memray:
# only run test suite if there are code changes
needs: changes
if: needs.changes.outputs.code == 'true'

runs-on: ubuntu-latest
defaults:
run:
# https://github.com/conda-incubator/setup-miniconda#use-a-default-shell
shell: bash -el {0} # bash exit immediately on error + login shell
strategy:
fail-fast: false
matrix:
python-version: ['3.12']

steps:
- name: Checkout Source
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0

- name: Hash + Timestamp
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-memray-$(date -u "+%Y%m")" >> $GITHUB_ENV

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

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca
with:
condarc-file: .github/condarc
run-post: false # skip post cleanup

- name: Conda Install
run: >
conda install
--yes
--file tests/requirements.txt
--file tests/requirements-${{ runner.os }}.txt
--file tests/requirements-ci.txt
python=${{ matrix.python-version }}
${{ env.CONDA_CHANNEL_LABEL }}${{ env.CONDA_VERSION }}
pytest-memray

- name: Install CodSpeed
run: pip install git+https://github.com/kenodegard/pytest-codspeed.git@fix-outerr-redirects#egg=pytest-codspeed

- name: Install development conda
run: pip install git+https://github.com/zklaus/conda@lazy-index && python -m conda init --install

# TODO: how can we remove this step?
- name: Install Self
run: pip install -e .

- name: Conda Info
# view test env info (not base)
run: python -m conda info --verbose

- name: Conda Config
run: conda config --show-sources

- name: Conda List
run: conda list --show-channel-urls

- name: Run memray
run: python -m pytest -k memray --memray

# windows test suite
windows:
# only run test suite if there are code changes
Expand Down Expand Up @@ -295,6 +372,9 @@ jobs:
python=${{ matrix.python-version }}
${{ env.CONDA_CHANNEL_LABEL }}::conda

- name: Install development conda
run: pip install git+https://github.com/zklaus/conda@lazy-index && python -m conda init --install

# TODO: how can we remove this step?
- name: Install Self
run: pip install -e .
Expand Down Expand Up @@ -414,6 +494,9 @@ jobs:
python=${{ matrix.python-version }}
${{ env.CONDA_CHANNEL_LABEL }}::conda

- name: Install development conda
run: pip install git+https://github.com/zklaus/conda@lazy-index && python -m conda init --install

# TODO: how can we remove this step?
- name: Install Self
run: pip install -e .
Expand Down
20 changes: 9 additions & 11 deletions conda_build/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os.path import dirname

from conda.base.context import context
from conda.core.index import get_index
from conda.core.index import Index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, we won't need this during the deprecation period, right? So we can release a new conda without this PR and it should work, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

from conda.exceptions import CondaHTTPError
from conda.utils import url_path
from conda_index.index import update_index as _update_index
Expand Down Expand Up @@ -102,26 +102,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
4 changes: 2 additions & 2 deletions conda_build/inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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.index import Index
from conda.core.prefix_data import PrefixData
from conda.models.records import PrefixRecord

Expand Down Expand Up @@ -173,7 +173,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
4 changes: 2 additions & 2 deletions conda_build/skeletons/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from os.path import basename, dirname, exists, join

import requests
from conda.core.index import get_index
from conda.core.index import Index
from conda.exceptions import CondaError, CondaHTTPError
from conda.gateways.connection.download import TmpDownload, download
from conda.gateways.disk.create import TemporaryDirectory
Expand Down Expand Up @@ -695,7 +695,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
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,23 @@ filterwarnings = [
# elevate conda-build's deprecated warning to an error
"error::PendingDeprecationWarning:conda_build",
"error::DeprecationWarning:conda_build",
"ignore:Python 3.14 will, by default, filter extracted tar archives:DeprecationWarning:conda_package_streaming",
# 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",
"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",
Comment on lines +134 to +135
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix these warnings instead of ignoring them, I'd say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes, but these come from conda-libmamba-solver, so I judged that fix outside the scope of this PR.
Of course we can make the fix in a branch there and use that development version here as well.

]
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
9 changes: 6 additions & 3 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ def test_downstream_tests(testing_config):


@pytest.mark.sanity
def test_warning_on_file_clobbering(testing_config, capfd):
def test_warning_on_file_clobbering(testing_config, caplog):
recipe_dir = os.path.join(metadata_dir, "_overlapping_files_warning")

api.build(
Expand All @@ -1844,8 +1844,11 @@ def test_warning_on_file_clobbering(testing_config, capfd):
config=testing_config,
)
# The clobber warning here is raised when creating the test environment for b
out, err = capfd.readouterr()
assert "ClobberWarning" in err
clobber_warning_found = False
for record in caplog.records:
if "ClobberWarning:" in record.message:
clobber_warning_found = True
assert clobber_warning_found
with pytest.raises((ClobberError, CondaMultiError)):
with env_var("CONDA_PATH_CONFLICT", "prevent", reset_context):
api.build(os.path.join(recipe_dir, "b"), config=testing_config)
Expand Down
Loading