|
18 | 18 |
|
19 | 19 | try:
|
20 | 20 | import portalocker
|
21 |
| -except ImportError as e: |
22 |
| - if os.name == "nt" and str(e).startswith("DLL load failed while importing"): |
23 |
| - print( |
24 |
| - "Please take a look at FAQ in https://github.com/pytorch/data#frequently-asked-questions-faq" |
25 |
| - "for the solution of this Error." |
26 |
| - ) |
27 |
| - raise |
28 |
| - |
| 21 | +except ImportError: |
| 22 | + protalocker = None |
29 | 23 |
|
30 | 24 | from torch.utils.data.datapipes.utils.common import _check_unpickable_fn, DILL_AVAILABLE
|
31 | 25 |
|
|
38 | 32 |
|
39 | 33 | dill.extend(use_dill=False)
|
40 | 34 |
|
| 35 | + |
| 36 | +def _assert_portalocker() -> None: |
| 37 | + try: |
| 38 | + import portalocker # noqa: F401 |
| 39 | + except ImportError as e: |
| 40 | + if os.name == "nt" and str(e).startswith("DLL load failed while importing"): |
| 41 | + print( |
| 42 | + "Please take a look at FAQ in https://github.com/pytorch/data#frequently-asked-questions-faq" |
| 43 | + "for the solution of this Error." |
| 44 | + ) |
| 45 | + raise |
| 46 | + else: |
| 47 | + raise ModuleNotFoundError( |
| 48 | + "Package `portalocker` is required to be installed to use this datapipe." |
| 49 | + "Please use `pip install 'portalocker>=2.0.0'` or" |
| 50 | + "`conda install -c conda-forge 'portalocker>=2/0.0'`" |
| 51 | + "to install the package" |
| 52 | + ) |
| 53 | + |
| 54 | + |
41 | 55 | T_co = TypeVar("T_co", covariant=True)
|
42 | 56 |
|
43 | 57 | PROMISE_FILE_DELETE_TIMEOUT = 30
|
@@ -190,6 +204,8 @@ def __init__(
|
190 | 204 | hash_type: str = "sha256",
|
191 | 205 | extra_check_fn: Optional[Callable[[str], bool]] = None,
|
192 | 206 | ):
|
| 207 | + _assert_portalocker() |
| 208 | + |
193 | 209 | self.source_datapipe = source_datapipe
|
194 | 210 |
|
195 | 211 | if filepath_fn is not None:
|
|
0 commit comments