Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
fix #157: catch pydoc.ErrorDuringImport
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 22, 2019
1 parent e03ccdc commit dd27835
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions collectfast/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import hashlib
import logging
import mimetypes
import pydoc
import warnings
from functools import lru_cache
from io import BytesIO
from pydoc import locate
from typing import ClassVar
from typing import Generic
from typing import Optional
Expand Down Expand Up @@ -140,7 +140,7 @@ def get_gzipped_local_file_hash(self, uncompressed_file_hash, path, contents):

def load_strategy(klass: Union[str, type, object]) -> Type[Strategy[Storage]]:
if isinstance(klass, str):
klass = locate(klass)
klass = pydoc.locate(klass)
if not isinstance(klass, type) or not issubclass(klass, Strategy):
raise ImproperlyConfigured(
"Configured strategies must be subclasses of %s.%s"
Expand All @@ -157,11 +157,11 @@ def load_strategy(klass: Union[str, type, object]) -> Type[Strategy[Storage]]:

def _resolves_to_subclass(subclass_ref: str, superclass_ref: str) -> bool:
try:
subclass = locate(subclass_ref)
subclass = pydoc.locate(subclass_ref)
assert isinstance(subclass, type)
superclass = locate(superclass_ref)
superclass = pydoc.locate(superclass_ref)
assert isinstance(superclass, type)
except (ImportError, AssertionError) as e:
except (ImportError, AssertionError, pydoc.ErrorDuringImport) as e:
logger.debug("Failed to import %s: %s" % (superclass_ref, e))
return False
return issubclass(subclass, superclass)
Expand Down
10 changes: 6 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os
import shutil
from functools import partial

import pytest
from django.conf import settings


@pytest.fixture(autouse=True)
def create_test_directories():
paths = (settings.STATICFILES_DIRS[0], settings.STATIC_ROOT)
map(partial(os.makedirs, exist_ok=True), paths)
paths = (settings.STATICFILES_DIRS[0], settings.STATIC_ROOT, settings.MEDIA_ROOT)
for path in paths:
if not os.path.exists(path):
os.makedirs(path)
try:
yield
finally:
map(shutil.rmtree, paths)
for path in paths:
shutil.rmtree(path)

0 comments on commit dd27835

Please sign in to comment.