Skip to content

Commit

Permalink
move PATH_MANAGER to OSS
Browse files Browse the repository at this point in the history
Summary:
## Problem:
pytext got "No module named 'pytorch'" in issue facebookresearch/pytext#1706

It's due to `from pytorch.text.fb.utils import PATH_MANAGER` is internal only but imported in pytext. Actually, `pytorch/text/fb/utils/__init__.py` should be open sourced.

## Solution:
This diff moved it to OSS as `from torchtext.utils import PATH_MANAGER` and updated all the references

Reviewed By: Nayef211

Differential Revision: D39292896

fbshipit-source-id: c0046d62e64145b60ad9a5298b366f0f1a348369
  • Loading branch information
hudeven authored and facebook-github-bot committed Sep 7, 2022
1 parent 3d1c635 commit 60737d9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions torchtext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zipfile

import torch
from iopath.common.file_io import PathManager
from torchtext import _CACHE_DIR

from ._download_hooks import _DATASET_DOWNLOAD_MANAGER
Expand Down Expand Up @@ -228,3 +229,16 @@ def get_asset_local_path(asset_path: str, overwite=False) -> str:
else:
local_path = download_from_url(url=asset_path, root=_CACHE_DIR, overwrite=overwite)
return local_path


PATH_MANAGER = PathManager()
'''
We use iopath to handle local files, remote files with http/https urls, etc.
This global instance is registered with all the required handlers with the best
defaults. Learn more about iopath: https://github.com/facebookresearch/iopath
Examples:
>>> from torchtext.utils import PATH_MANAGER
>>> with PATH_MANAGER.open(FILE_PATH) as f:
>>> f.read()
'''

0 comments on commit 60737d9

Please sign in to comment.