Skip to content

Commit c32158f

Browse files
authored
Merge pull request #1234 from HaoZeke/noExternal
MAINT: Fixup and remove bundled dependencies
2 parents 6c49b2e + 4ea96eb commit c32158f

File tree

8 files changed

+79
-3101
lines changed

8 files changed

+79
-3101
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ install:
2323

2424
# Install the build and runtime dependencies of the project.
2525
- conda update conda -y
26-
- conda install -q --yes python=%PYTHON_VERSION% conda pip pytest pytest-xdist pytest-timeout filelock selenium conda-build bzip2
26+
- conda install -q --yes python=%PYTHON_VERSION% conda pip pytest pytest-xdist pytest-timeout filelock selenium conda-build bzip2 pympler
2727
- python -m pip install -U pip
28-
- python -m pip install pytest-rerunfailures
28+
- python -m pip install pytest-rerunfailures json5 pympler
2929

3030
# Check that we have the expected version of Python
3131
- python --version

asv/benchmark.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import cProfile as profile
4343
import ctypes
4444
import importlib.machinery
45+
import importlib.util
4546
import inspect
4647
import itertools
4748
import json
@@ -58,13 +59,15 @@
5859
import traceback
5960
import contextlib
6061
import math
62+
from pathlib import Path
6163
from hashlib import sha256
6264
from importlib import import_module
6365
from collections import Counter
6466
from time import process_time
6567

6668
wall_timer = timeit.default_timer
6769

70+
ON_PYPY = hasattr(sys, 'pypy_version_info')
6871

6972
if sys.platform.startswith('win'):
7073
import ctypes.wintypes
@@ -704,16 +707,64 @@ def __init__(self, name, func, attr_sources):
704707
self.unit = "bytes"
705708

706709
def run(self, *param):
707-
# We can't import asizeof directly, because we haven't loaded
708-
# the asv package in the benchmarking process.
709-
path = os.path.join(
710-
os.path.dirname(__file__), 'extern', 'asizeof.py')
711-
asizeof = importlib.machinery.SourceFileLoader('asizeof', path).load_module()
710+
if ON_PYPY:
711+
raise NotImplementedError("asizeof doesn't work on pypy")
712+
return
713+
714+
def import_asizeof():
715+
"""Import asizeof, searching system Pythons in PATH."""
716+
path_dirs = os.environ.get("PATH", "").split(os.pathsep)
717+
718+
# On Windows, append the directories containing the Python executables
719+
if os.name == "nt":
720+
path_dirs += [sys.base_exec_prefix, sys.base_exec_prefix + "/Scripts"]
721+
722+
asizeof_paths = set()
723+
for path in path_dirs:
724+
python_path = os.path.join(path, "python")
725+
if os.path.isfile(python_path) and os.access(python_path, os.X_OK):
726+
cand_path = Path(python_path).parent.parent / "lib"
727+
if cand_path not in asizeof_paths:
728+
asizeof_paths.add(cand_path)
729+
for asizeof_path in cand_path.rglob("asizeof.py"):
730+
try: # Still returns the first importable asizeof
731+
loader = importlib.machinery.SourceFileLoader(
732+
"asizeof", str(asizeof_path)
733+
)
734+
return loader.load_module()
735+
except ImportError:
736+
pass
737+
738+
# Try conda, mamba explicitly, needed on Windows
739+
try:
740+
env_path = os.environ["CONDA_PREFIX"]
741+
except KeyError:
742+
pass
743+
else:
744+
cand_path = Path(env_path) / "lib"
745+
if cand_path not in asizeof_paths:
746+
asizeof_paths.add(cand_path)
747+
for asizeof_path in cand_path.rglob("asizeof.py"):
748+
try: # Still returns the first importable asizeof
749+
loader = importlib.machinery.SourceFileLoader(
750+
"asizeof", str(asizeof_path)
751+
)
752+
return loader.load_module()
753+
except ImportError:
754+
pass
755+
756+
return NotImplementedError("asizeof not found anywhere")
757+
758+
try:
759+
from pympler.asizeof import asizeof
760+
except ImportError:
761+
asizeof = import_asizeof()
762+
from asizeof import asizeof
712763

713764
obj = self.func(*param)
714765

715-
sizeof2 = asizeof.asizeof([obj, obj])
716-
sizeofcopy = asizeof.asizeof([obj, copy.copy(obj)])
766+
sizeof2 = asizeof([obj, obj])
767+
sizeofcopy = asizeof([obj, copy.copy(obj)])
717768

718769
return sizeofcopy - sizeof2
719770

asv/extern/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)