Skip to content

Commit

Permalink
Speed up _notify_conda_outdated due to expensive PrefixData call. (#…
Browse files Browse the repository at this point in the history
…298)

* Manually scanning prefix data

* Cleanup of code

* Black formatting

* Check if conda-meta directory exists

* add news

* fix test (conda-meta might not exist)

* suppres IO exceptions

* pre-commit

* Update conda_libmamba_solver/solver.py

Co-authored-by: Jannis Leidel <jannis@leidel.info>

* Update conda_libmamba_solver/solver.py

Co-authored-by: Jannis Leidel <jannis@leidel.info>

* Update conda_libmamba_solver/solver.py

* fix .read() method

* pre-commit

---------

Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
Co-authored-by: Jannis Leidel <jannis@leidel.info>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent 2d218ab commit 533543d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions conda_libmamba_solver/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
import sys
from collections import defaultdict
from contextlib import suppress
from functools import lru_cache
from inspect import stack
from textwrap import dedent
Expand Down Expand Up @@ -42,7 +43,7 @@
)
from conda.models.channel import Channel
from conda.models.match_spec import MatchSpec
from conda.models.records import PackageRecord
from conda.models.records import PackageRecord, PrefixRecord
from conda.models.version import VersionOrder

from . import __version__
Expand Down Expand Up @@ -999,7 +1000,21 @@ def _notify_conda_outdated(
# This check can be silenced with a specific option in the context or in quiet mode
return

current_conda_prefix_rec = PrefixData(context.conda_prefix).get("conda", None)
# manually check base prefix since `PrefixData(...).get("conda", None) is expensive
# once prefix data is lazy this might be a different situation
current_conda_prefix_rec = None
conda_meta_prefix_directory = os.path.join(context.conda_prefix, "conda-meta")
with suppress(OSError, ValueError):
if os.path.lexists(conda_meta_prefix_directory):
for entry in os.scandir(conda_meta_prefix_directory):
if (
entry.is_file()
and entry.name.endswith(".json")
and entry.name.rsplit("-", 2)[0] == "conda"
):
with open(entry.path) as f:
current_conda_prefix_rec = PrefixRecord(**json.loads(f.read()))
break
if not current_conda_prefix_rec:
# We are checking whether conda can be found in the environment conda is
# running from. Unless something is really wrong, this should never happen.
Expand Down
19 changes: 19 additions & 0 deletions news/298-faster-outdated-notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Increase performance of `notify_conda_outdated` logic. (#298)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit 533543d

Please sign in to comment.