Skip to content

Commit 19d6814

Browse files
committed
Pass context.exclude_newer to libmambapy Database
Convert the exclude_newer duration/timestamp from conda's config into a Unix timestamp cutoff and pass it to libmambapy's Database constructor as exclude_newer_timestamp. This enables native --exclude-newer filtering in the libmamba solver backend. Depends on: - conda/conda#15761 (exclude_newer config + parse_duration_to_seconds) - mamba-org/mamba#4228 (exclude_newer_timestamp in Database::Settings)
1 parent 14207f7 commit 19d6814

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

conda_libmamba_solver/index.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@
7575

7676
import logging
7777
import os
78+
import time
7879
from dataclasses import dataclass
7980
from functools import partial
8081
from pathlib import Path
8182
from typing import TYPE_CHECKING
8283

8384
from conda.base.constants import KNOWN_SUBDIRS, REPODATA_FN, ChannelPriority
8485
from conda.base.context import context
86+
from conda.cli.helpers import parse_duration_to_seconds
8587
from conda.common.compat import on_win
8688
from conda.common.io import DummyExecutor, ThreadLimitedThreadPoolExecutor, time_recorder
8789
from conda.common.url import path_to_url, remove_auth, split_anaconda_token
@@ -347,10 +349,21 @@ def _init_db(self) -> Database:
347349
home_dir=str(Path.home()),
348350
current_working_dir=os.getcwd(),
349351
)
350-
db = Database(params)
352+
db = Database(
353+
params,
354+
exclude_newer_timestamp=self._exclude_newer_timestamp(),
355+
)
351356
db.set_logger(logger_callback)
352357
return db
353358

359+
@staticmethod
360+
def _exclude_newer_timestamp():
361+
"""Convert context.exclude_newer to a Unix timestamp for libmambapy."""
362+
value = context.exclude_newer
363+
if not value:
364+
return None
365+
return int(time.time() - parse_duration_to_seconds(value))
366+
354367
def _load_channels(
355368
self,
356369
urls_to_channel: dict[str, Channel] | None = None,

news/exclude-newer

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Enhancements
2+
3+
* Pass `context.exclude_newer` to libmambapy's `Database` as
4+
`exclude_newer_timestamp`, enabling native `--exclude-newer` support
5+
when the upstream mamba PR lands. (#15759)
6+
7+
### Bug fixes
8+
9+
* <news item>
10+
11+
### Deprecations
12+
13+
* <news item>
14+
15+
### Docs
16+
17+
* <news item>
18+
19+
### Other
20+
21+
* <news item>

tests/test_index.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,23 @@ def test_load_channels_order(shard_factory):
208208
assert [
209209
repo.channel.canonical_name for repo in shard_enabled_index.repos
210210
] == expected_output_channels
211+
212+
213+
def test_exclude_newer_timestamp_unset(monkeypatch: pytest.MonkeyPatch):
214+
monkeypatch.setattr(context, "exclude_newer", "")
215+
assert LibMambaIndexHelper._exclude_newer_timestamp() is None
216+
217+
218+
def test_exclude_newer_timestamp_duration(monkeypatch: pytest.MonkeyPatch):
219+
monkeypatch.setattr(context, "exclude_newer", "7d")
220+
result = LibMambaIndexHelper._exclude_newer_timestamp()
221+
assert result is not None
222+
expected = int(time.time() - 7 * 86400)
223+
assert abs(result - expected) < 2
224+
225+
226+
def test_exclude_newer_timestamp_zero_duration(monkeypatch: pytest.MonkeyPatch):
227+
monkeypatch.setattr(context, "exclude_newer", "0d")
228+
result = LibMambaIndexHelper._exclude_newer_timestamp()
229+
assert result is not None
230+
assert abs(result - int(time.time())) < 2

0 commit comments

Comments
 (0)