Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 4bf6b30

Browse files
authored
Add removeable warnings indicating this is the last release (#2248)
1 parent cee0243 commit 4bf6b30

File tree

11 files changed

+64
-2
lines changed

11 files changed

+64
-2
lines changed

torchtext/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
from torch.hub import _get_torch_home
44

5+
_WARN = True
6+
_TORCHTEXT_DEPRECATION_MSG = (
7+
"\n/!\ IMPORTANT WARNING ABOUT TORCHTEXT STATUS /!\ \n"
8+
"Torchtext is deprecated and the last released version will be 0.18 (this one). "
9+
"You can silence this warning by calling the following at the beginnign of your scripts: "
10+
"`import torchtext; torchtext.disable_torchtext_deprecation_warning()`"
11+
)
12+
13+
def disable_torchtext_deprecation_warning():
14+
global _WARN
15+
_WARN = False
16+
517
# the following import has to happen first in order to load the torchtext C++ library
618
from torchtext import _extension # noqa: F401
719

820
_TEXT_BUCKET = "https://download.pytorch.org/models/text/"
921

1022
_CACHE_DIR = os.path.expanduser(os.path.join(_get_torch_home(), "text"))
1123

12-
from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental
13-
1424
try:
1525
from .version import __version__, git_version # noqa: F401
1626
except ImportError:

torchtext/data/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
from .functional import (
28
custom_replace,
39
filter_wikipedia_xml,

torchtext/datasets/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
import importlib
28

39
from .ag_news import AG_NEWS

torchtext/experimental/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

torchtext/functional.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from typing import Any, List, Optional
27

38
import torch

torchtext/models/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from .roberta import * # noqa: F401, F403
27
from .t5 import * # noqa: F401, F403

torchtext/nn/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from .modules import * # noqa: F401,F403

torchtext/prototype/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from . import transforms
27

38
__all__ = ["transforms"]

torchtext/transforms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
import json
28
import re
39
from copy import deepcopy

torchtext/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
import gzip
27
import hashlib
38
import logging

0 commit comments

Comments
 (0)