File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7575
7676import logging
7777import os
78+ import time
7879from dataclasses import dataclass
7980from functools import partial
8081from pathlib import Path
8182from typing import TYPE_CHECKING
8283
8384from conda .base .constants import KNOWN_SUBDIRS , REPODATA_FN , ChannelPriority
8485from conda .base .context import context
86+ from conda .cli .helpers import parse_duration_to_seconds
8587from conda .common .compat import on_win
8688from conda .common .io import DummyExecutor , ThreadLimitedThreadPoolExecutor , time_recorder
8789from 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 ,
Original file line number Diff line number Diff line change 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>
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments