Skip to content

Commit

Permalink
fix pytest still getting imported
Browse files Browse the repository at this point in the history
  • Loading branch information
verbose-void committed Oct 12, 2021
1 parent 3f4dac2 commit 9fe6127
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion hub/core/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from click.testing import CliRunner
from hub.core.storage.memory import MemoryProvider
from hub.util.remove_cache import remove_memory_cache
from hub.tests.common import ray_installed
from hub.util.check_installation import ray_installed
from hub.util.exceptions import InvalidOutputDatasetError, TransformError
from hub.tests.common import parametrize_num_workers
from hub.tests.dataset_fixtures import enabled_datasets, enabled_non_gcs_datasets
Expand Down
2 changes: 1 addition & 1 deletion hub/integrations/pytorch/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DatasetUnsupportedPytorch,
ModuleNotInstalledException,
)
from hub.tests.common import pytorch_installed
from hub.util.check_installation import pytorch_installed
from hub.constants import MB
from .common import convert_fn as default_convert_fn, collate_fn as default_collate_fn

Expand Down
2 changes: 1 addition & 1 deletion hub/integrations/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SampleDecompressionError,
CorruptedSampleError,
)
from hub.tests.common import tensorflow_installed
from hub.util.check_installation import tensorflow_installed
import warnings


Expand Down
19 changes: 3 additions & 16 deletions hub/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import pytest

from hub.constants import KB, MB
from importlib.util import find_spec

from hub.util.check_installation import pytorch_installed, tensorflow_installed, tfds_installed


SESSION_ID = str(uuid4())[:4] # 4 ascii chars should be sufficient

Expand Down Expand Up @@ -88,21 +90,6 @@ def assert_images_close(img1: np.ndarray, img2: np.ndarray, eps=0.5):
assert err < eps, err


def pytorch_installed():
return find_spec("torch") != None


def tensorflow_installed():
return find_spec("tensorflow") != None


def tfds_installed():
return find_spec("tensorflow_datasets") != None


def ray_installed():
return find_spec("ray") != None


requires_torch = pytest.mark.skipif(
not pytorch_installed(), reason="requires pytorch to be installed"
Expand Down
18 changes: 18 additions & 0 deletions hub/util/check_installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from importlib.util import find_spec



def pytorch_installed():
return find_spec("torch") != None


def tensorflow_installed():
return find_spec("tensorflow") != None


def tfds_installed():
return find_spec("tensorflow_datasets") != None


def ray_installed():
return find_spec("ray") != None
2 changes: 1 addition & 1 deletion hub/util/compute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hub.util.exceptions import ModuleNotInstalledException, UnsupportedSchedulerError
from hub.tests.common import ray_installed
from hub.util.check_installation import ray_installed
from hub.core.compute.provider import ComputeProvider


Expand Down

0 comments on commit 9fe6127

Please sign in to comment.