Skip to content

Commit

Permalink
MAINT: Rework to check conda environments too
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Feb 26, 2023
1 parent 05ff5dc commit 78a719d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import cProfile as profile
import ctypes
import importlib.machinery
import importlib.util
import inspect
import itertools
import json
Expand Down Expand Up @@ -727,11 +728,31 @@ def import_asizeof():
asizeof_paths.add(cand_path)
for asizeof_path in cand_path.rglob("asizeof.py"):
try: # Still returns the first importable asizeof
return importlib.machinery.SourceFileLoader(
loader = importlib.machinery.SourceFileLoader(
"asizeof", str(asizeof_path)
).load_module()
)
return loader.load_module()
except ImportError:
pass

# Try conda
try:
env_path = os.environ["CONDA_PREFIX"]
except KeyError:
pass
else:
cand_path = Path(env_path) / "lib" / "python" / "site-packages"
if cand_path not in asizeof_paths:
asizeof_paths.add(cand_path)
for asizeof_path in cand_path.rglob("asizeof.py"):
try: # Still returns the first importable asizeof
loader = importlib.machinery.SourceFileLoader(
"asizeof", str(asizeof_path)
)
return loader.load_module()
except ImportError:
pass

return NotImplementedError("asizeof not found anywhere")

try:
Expand Down

0 comments on commit 78a719d

Please sign in to comment.