Skip to content

[Cherry Pick] move PATH_MANAGER to OSS #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/unittest/linux/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
- pip
- pip:
- dataclasses
- iopath
- nltk
- requests
- revtok
Expand Down
1 change: 1 addition & 0 deletions .circleci/unittest/windows/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- spacy
- pip:
- dataclasses
- iopath
- nltk
- requests
- revtok
Expand Down
1 change: 1 addition & 0 deletions packaging/torchtext/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ requirements:
- python
- requests
- tqdm
- iopath
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}

build:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ tqdm

# Downloading data and other files
requests
iopath

# Optional NLP tools
nltk
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run(self):
description="Text utilities and datasets for PyTorch",
long_description=read("README.rst"),
license="BSD",
install_requires=["tqdm", "requests", pytorch_package_dep, "numpy"],
install_requires=["tqdm", "requests", pytorch_package_dep, "numpy", "iopath"],
python_requires=">=3.7",
classifiers=[
"Programming Language :: Python :: 3.7",
Expand Down
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()
"""