We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Make TorchText installable from direct reference
In order to make `pip install https://github.com/pytorch/text` succeed
`setup.py` should have logic to initialize submodules

Add `check_submodules()` routine to setup.py to check if
'third_party/re2/CMakeLists.txt' is present on the filesystem and
attempt to initialize submodules if it is not

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 #!/usr/bin/env python
2 import distutils.command.clean
3 import io
4 import os
5 import shutil
6 import subprocess
7 from pathlib import Path
8 
9 from build_tools import setup_helpers
10 from setuptools import find_packages, setup
11 
12 ROOT_DIR = Path(__file__).parent.resolve()
13 
14 
15 def read(*names, **kwargs):
16     with io.open(ROOT_DIR.joinpath(*names), encoding=kwargs.get("encoding", "utf8")) as fp:
17         return fp.read()
18 
19 
20 def _get_version():
21     try:
22         cmd = ["git", "rev-parse", "HEAD"]
23         sha = subprocess.check_output(cmd, cwd=str(ROOT_DIR)).decode("ascii").strip()
24     except Exception:
25         sha = None
26 
27     if "BUILD_VERSION" in os.environ:
28         version = os.environ["BUILD_VERSION"]
29     else:
30         with open(os.path.join(ROOT_DIR, "version.txt"), "r") as f:
31             version = f.readline().strip()
32         if sha is not None:
33             version += "+" + sha[:7]
34 
35     if sha is None:
36         sha = "Unknown"
37     return version, sha
38 
39 
40 def _export_version(version, sha):
41     version_path = ROOT_DIR / "torchtext" / "version.py"
42     with open(version_path, "w") as fileobj:
43         fileobj.write("__version__ = '{}'\n".format(version))
44         fileobj.write("git_version = {}\n".format(repr(sha)))
45 
46 
47 VERSION, SHA = _get_version()
48 _export_version(VERSION, SHA)
49 
50 print("-- Building version " + VERSION)
51 
52 pytorch_package_version = os.getenv("PYTORCH_VERSION")
53 
54 pytorch_package_dep = "torch"
55 if pytorch_package_version is not None:
56     pytorch_package_dep += "==" + pytorch_package_version
57 
58 
59 class clean(distutils.command.clean.clean):
60     def run(self):
61         # Run default behavior first
62         distutils.command.clean.clean.run(self)
63 
64         # Remove torchtext extension
65         for path in (ROOT_DIR / "torchtext").glob("**/*.so"):
66             print(f"removing '{path}'")
67             path.unlink()
68         # Remove build directory
69         build_dirs = [
70             ROOT_DIR / "build",
71             ROOT_DIR / "third_party" / "build",
72         ]
73         for path in build_dirs:
74             if path.exists():
75                 print(f"removing '{path}' (and everything under it)")
76                 shutil.rmtree(str(path), ignore_errors=True)
77 
78 
79 setup_info = dict(
80     # Metadata
81     name="torchtext",
82     version=VERSION,
83     author="PyTorch core devs and James Bradbury",
84     author_email="jekbradbury@gmail.com",
85     url="https://github.com/pytorch/text",
86     description="Text utilities and datasets for PyTorch",
87     long_description=read("README.rst"),
88     license="BSD",
89     install_requires=["tqdm", "requests", pytorch_package_dep, "numpy"],
90     python_requires=">=3.7",
91     classifiers=[
92         "Programming Language :: Python :: 3.7",
93         "Programming Language :: Python :: 3.8",
94         "Programming Language :: Python :: 3.9",
95     ],
96     # Package info
97     packages=find_packages(exclude=("test*", "build_tools*")),
98     zip_safe=False,
99     # Extension info
100     # If you are trying to use torchtext.so and see no registered op.
101     # See here: https://github.com/pytorch/vision/issues/2134"
102     ext_modules=setup_helpers.get_ext_modules(),
103     cmdclass={
104         "build_ext": setup_helpers.CMakeBuild,
105         "clean": clean,
106     },
107 )
108 
109 setup(**setup_info)
110
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -4,6 +4,7 @@
 import os
 import shutil
 import subprocess
+import sys
 from pathlib import Path
 
 from build_tools import setup_helpers
@@ -44,6 +45,18 @@
         fileobj.write("git_version = {}\n".format(repr(sha)))
 
 
+def _init_submodule():
+    print(" --- Initializing submodules")
+    try:
+        subprocess.check_call(["git", "submodule", "init"])
+        subprocess.check_call(["git", "submodule", "update"])
+    except Exception:
+        print(" --- Submodule initalization failed")
+        print("Please run:\n\tgit submodule update --init --recursive")
+        sys.exit(1)
+    print(" --- Initialized submodule")
+
+
 VERSION, SHA = _get_version()
 _export_version(VERSION, SHA)
 
@@ -76,6 +89,7 @@
                 shutil.rmtree(str(path), ignore_errors=True)
 
 
+_init_submodule()
 setup_info = dict(
     # Metadata
     name="torchtext",

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -4,6 +4,7 @@\n import os\n import shutil\n import subprocess\n+import sys\n from pathlib import Path\n \n from build_tools import setup_helpers\n@@ -44,6 +45,18 @@\n         fileobj.write(\"git_version = {}\\n\".format(repr(sha)))\n \n \n+def _init_submodule():\n+    print(\" --- Initializing submodules\")\n+    try:\n+        subprocess.check_call([\"git\", \"submodule\", \"init\"])\n+        subprocess.check_call([\"git\", \"submodule\", \"update\"])\n+    except Exception:\n+        print(\" --- Submodule initalization failed\")\n+        print(\"Please run:\\n\\tgit submodule update --init --recursive\")\n+        sys.exit(1)\n+    print(\" --- Initialized submodule\")\n+\n+\n VERSION, SHA = _get_version()\n _export_version(VERSION, SHA)\n \n@@ -76,6 +89,7 @@\n                 shutil.rmtree(str(path), ignore_errors=True)\n \n \n+_init_submodule()\n setup_info = dict(\n     # Metadata\n     name=\"torchtext\",\n", "issue": "Make TorchText installable from direct reference\nIn order to make `pip install https://github.com/pytorch/text` succeed\r\n`setup.py` should have logic to initialize submodules\r\n\r\nAdd `check_submodules()` routine to setup.py to check if\r\n'third_party/re2/CMakeLists.txt' is present on the filesystem and\r\nattempt to initialize submodules if it is not\n", "before_files": [{"content": "#!/usr/bin/env python\nimport distutils.command.clean\nimport io\nimport os\nimport shutil\nimport subprocess\nfrom pathlib import Path\n\nfrom build_tools import setup_helpers\nfrom setuptools import find_packages, setup\n\nROOT_DIR = Path(__file__).parent.resolve()\n\n\ndef read(*names, **kwargs):\n    with io.open(ROOT_DIR.joinpath(*names), encoding=kwargs.get(\"encoding\", \"utf8\")) as fp:\n        return fp.read()\n\n\ndef _get_version():\n    try:\n        cmd = [\"git\", \"rev-parse\", \"HEAD\"]\n        sha = subprocess.check_output(cmd, cwd=str(ROOT_DIR)).decode(\"ascii\").strip()\n    except Exception:\n        sha = None\n\n    if \"BUILD_VERSION\" in os.environ:\n        version = os.environ[\"BUILD_VERSION\"]\n    else:\n        with open(os.path.join(ROOT_DIR, \"version.txt\"), \"r\") as f:\n            version = f.readline().strip()\n        if sha is not None:\n            version += \"+\" + sha[:7]\n\n    if sha is None:\n        sha = \"Unknown\"\n    return version, sha\n\n\ndef _export_version(version, sha):\n    version_path = ROOT_DIR / \"torchtext\" / \"version.py\"\n    with open(version_path, \"w\") as fileobj:\n        fileobj.write(\"__version__ = '{}'\\n\".format(version))\n        fileobj.write(\"git_version = {}\\n\".format(repr(sha)))\n\n\nVERSION, SHA = _get_version()\n_export_version(VERSION, SHA)\n\nprint(\"-- Building version \" + VERSION)\n\npytorch_package_version = os.getenv(\"PYTORCH_VERSION\")\n\npytorch_package_dep = \"torch\"\nif pytorch_package_version is not None:\n    pytorch_package_dep += \"==\" + pytorch_package_version\n\n\nclass clean(distutils.command.clean.clean):\n    def run(self):\n        # Run default behavior first\n        distutils.command.clean.clean.run(self)\n\n        # Remove torchtext extension\n        for path in (ROOT_DIR / \"torchtext\").glob(\"**/*.so\"):\n            print(f\"removing '{path}'\")\n            path.unlink()\n        # Remove build directory\n        build_dirs = [\n            ROOT_DIR / \"build\",\n            ROOT_DIR / \"third_party\" / \"build\",\n        ]\n        for path in build_dirs:\n            if path.exists():\n                print(f\"removing '{path}' (and everything under it)\")\n                shutil.rmtree(str(path), ignore_errors=True)\n\n\nsetup_info = dict(\n    # Metadata\n    name=\"torchtext\",\n    version=VERSION,\n    author=\"PyTorch core devs and James Bradbury\",\n    author_email=\"jekbradbury@gmail.com\",\n    url=\"https://github.com/pytorch/text\",\n    description=\"Text utilities and datasets for PyTorch\",\n    long_description=read(\"README.rst\"),\n    license=\"BSD\",\n    install_requires=[\"tqdm\", \"requests\", pytorch_package_dep, \"numpy\"],\n    python_requires=\">=3.7\",\n    classifiers=[\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"Programming Language :: Python :: 3.9\",\n    ],\n    # Package info\n    packages=find_packages(exclude=(\"test*\", \"build_tools*\")),\n    zip_safe=False,\n    # Extension info\n    # If you are trying to use torchtext.so and see no registered op.\n    # See here: https://github.com/pytorch/vision/issues/2134\"\n    ext_modules=setup_helpers.get_ext_modules(),\n    cmdclass={\n        \"build_ext\": setup_helpers.CMakeBuild,\n        \"clean\": clean,\n    },\n)\n\nsetup(**setup_info)\n", "path": "setup.py"}], "after_files": [{"content": "#!/usr/bin/env python\nimport distutils.command.clean\nimport io\nimport os\nimport shutil\nimport subprocess\nimport sys\nfrom pathlib import Path\n\nfrom build_tools import setup_helpers\nfrom setuptools import find_packages, setup\n\nROOT_DIR = Path(__file__).parent.resolve()\n\n\ndef read(*names, **kwargs):\n    with io.open(ROOT_DIR.joinpath(*names), encoding=kwargs.get(\"encoding\", \"utf8\")) as fp:\n        return fp.read()\n\n\ndef _get_version():\n    try:\n        cmd = [\"git\", \"rev-parse\", \"HEAD\"]\n        sha = subprocess.check_output(cmd, cwd=str(ROOT_DIR)).decode(\"ascii\").strip()\n    except Exception:\n        sha = None\n\n    if \"BUILD_VERSION\" in os.environ:\n        version = os.environ[\"BUILD_VERSION\"]\n    else:\n        with open(os.path.join(ROOT_DIR, \"version.txt\"), \"r\") as f:\n            version = f.readline().strip()\n        if sha is not None:\n            version += \"+\" + sha[:7]\n\n    if sha is None:\n        sha = \"Unknown\"\n    return version, sha\n\n\ndef _export_version(version, sha):\n    version_path = ROOT_DIR / \"torchtext\" / \"version.py\"\n    with open(version_path, \"w\") as fileobj:\n        fileobj.write(\"__version__ = '{}'\\n\".format(version))\n        fileobj.write(\"git_version = {}\\n\".format(repr(sha)))\n\n\ndef _init_submodule():\n    print(\" --- Initializing submodules\")\n    try:\n        subprocess.check_call([\"git\", \"submodule\", \"init\"])\n        subprocess.check_call([\"git\", \"submodule\", \"update\"])\n    except Exception:\n        print(\" --- Submodule initalization failed\")\n        print(\"Please run:\\n\\tgit submodule update --init --recursive\")\n        sys.exit(1)\n    print(\" --- Initialized submodule\")\n\n\nVERSION, SHA = _get_version()\n_export_version(VERSION, SHA)\n\nprint(\"-- Building version \" + VERSION)\n\npytorch_package_version = os.getenv(\"PYTORCH_VERSION\")\n\npytorch_package_dep = \"torch\"\nif pytorch_package_version is not None:\n    pytorch_package_dep += \"==\" + pytorch_package_version\n\n\nclass clean(distutils.command.clean.clean):\n    def run(self):\n        # Run default behavior first\n        distutils.command.clean.clean.run(self)\n\n        # Remove torchtext extension\n        for path in (ROOT_DIR / \"torchtext\").glob(\"**/*.so\"):\n            print(f\"removing '{path}'\")\n            path.unlink()\n        # Remove build directory\n        build_dirs = [\n            ROOT_DIR / \"build\",\n            ROOT_DIR / \"third_party\" / \"build\",\n        ]\n        for path in build_dirs:\n            if path.exists():\n                print(f\"removing '{path}' (and everything under it)\")\n                shutil.rmtree(str(path), ignore_errors=True)\n\n\n_init_submodule()\nsetup_info = dict(\n    # Metadata\n    name=\"torchtext\",\n    version=VERSION,\n    author=\"PyTorch core devs and James Bradbury\",\n    author_email=\"jekbradbury@gmail.com\",\n    url=\"https://github.com/pytorch/text\",\n    description=\"Text utilities and datasets for PyTorch\",\n    long_description=read(\"README.rst\"),\n    license=\"BSD\",\n    install_requires=[\"tqdm\", \"requests\", pytorch_package_dep, \"numpy\"],\n    python_requires=\">=3.7\",\n    classifiers=[\n        \"Programming Language :: Python :: 3.7\",\n        \"Programming Language :: Python :: 3.8\",\n        \"Programming Language :: Python :: 3.9\",\n    ],\n    # Package info\n    packages=find_packages(exclude=(\"test*\", \"build_tools*\")),\n    zip_safe=False,\n    # Extension info\n    # If you are trying to use torchtext.so and see no registered op.\n    # See here: https://github.com/pytorch/vision/issues/2134\"\n    ext_modules=setup_helpers.get_ext_modules(),\n    cmdclass={\n        \"build_ext\": setup_helpers.CMakeBuild,\n        \"clean\": clean,\n    },\n)\n\nsetup(**setup_info)\n", "path": "setup.py"}]}