Skip to content

Commit

Permalink
Add removeable warnings indicating this is the last release (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug authored Apr 2, 2024
1 parent cee0243 commit 4bf6b30
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 2 deletions.
14 changes: 12 additions & 2 deletions torchtext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

from torch.hub import _get_torch_home

_WARN = True
_TORCHTEXT_DEPRECATION_MSG = (
"\n/!\ IMPORTANT WARNING ABOUT TORCHTEXT STATUS /!\ \n"
"Torchtext is deprecated and the last released version will be 0.18 (this one). "
"You can silence this warning by calling the following at the beginnign of your scripts: "
"`import torchtext; torchtext.disable_torchtext_deprecation_warning()`"
)

def disable_torchtext_deprecation_warning():
global _WARN
_WARN = False

# the following import has to happen first in order to load the torchtext C++ library
from torchtext import _extension # noqa: F401

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

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

from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental

try:
from .version import __version__, git_version # noqa: F401
except ImportError:
Expand Down
6 changes: 6 additions & 0 deletions torchtext/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)


from .functional import (
custom_replace,
filter_wikipedia_xml,
Expand Down
6 changes: 6 additions & 0 deletions torchtext/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)


import importlib

from .ag_news import AG_NEWS
Expand Down
4 changes: 4 additions & 0 deletions torchtext/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5 changes: 5 additions & 0 deletions torchtext/functional.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from typing import Any, List, Optional

import torch
Expand Down
5 changes: 5 additions & 0 deletions torchtext/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from .roberta import * # noqa: F401, F403
from .t5 import * # noqa: F401, F403
5 changes: 5 additions & 0 deletions torchtext/nn/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from .modules import * # noqa: F401,F403
5 changes: 5 additions & 0 deletions torchtext/prototype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from . import transforms

__all__ = ["transforms"]
6 changes: 6 additions & 0 deletions torchtext/transforms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)


import json
import re
from copy import deepcopy
Expand Down
5 changes: 5 additions & 0 deletions torchtext/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

import gzip
import hashlib
import logging
Expand Down
5 changes: 5 additions & 0 deletions torchtext/vocab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from .vectors import CharNGram, FastText, GloVe, pretrained_aliases, Vectors
from .vocab import Vocab
from .vocab_factory import build_vocab_from_iterator, vocab
Expand Down

0 comments on commit 4bf6b30

Please sign in to comment.