prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error running unit tests when building with setup.py install
  ## 🐛 Bug
  
  **Describe the bug** A clear and concise description of what the bug is.
  When building with python setup.py install, running pytest from either the project root directory or the test/ directory causes the error `ImportError: torchtext C++ Extension is not found`. This can be worked-around by renaming the torchtext subdirectory, or by instead using python setup.py develop like the CI does (see .circleci/unittest/linux/scripts/install.sh#L36).
  
  **To Reproduce** Steps to reproduce the behavior:
  
  1. Follow the build steps like normal, running python setup.py install
  2. Run pytest
  3. Every test fails with the error `ImportError: torchtext C++ Extension is not found`.
  
  **Expected behavior** A clear and concise description of what you expected to happen.
  
  The tests should succeed even when installing with setup.py install, either running pytest from the project root or the test/ directory (this is the case in pytorch) without having to rename the torchtext subdirectory.
  
  **Screenshots** If applicable, add screenshots to help explain your problem.
  
  **Environment**
  
  Please copy and paste the output from our
  [environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py) (or
  fill out the checklist below manually).
  
  You can get the script and run it with:
  
  ```
  wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
  # For security purposes, please check the contents of collect_env.py before running it.
  python collect_env.py
  python -c "import torchtext; print(\"torchtext version is \", torchtext.__version__)"
  ```
  
  - PyTorch Version (e.g., 1.0): 1.12
  - OS (e.g., Linux): Linux
  - How you installed PyTorch (`conda`, `pip`, source): Compiled from source
  - Build command you used (if compiling from source): python3 ./setup.py install
  - Python version: 3.7.13
  - CUDA/cuDNN version: ROCm version 5.2
  - GPU models and configuration: N/A
  - Any other relevant information:
  
  **Additional context** Add any other context about the problem here.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `tools/setup_helpers/extension.py`
  Content:
  ```
  1 import distutils.sysconfig
  2 import os
  3 import platform
  4 import subprocess
  5 from pathlib import Path
  6 
  7 import torch
  8 from setuptools import Extension
  9 from setuptools.command.build_ext import build_ext
  10 
  11 
  12 __all__ = [
  13     "get_ext_modules",
  14     "CMakeBuild",
  15 ]
  16 
  17 
  18 _LIBTORCHTEXT_NAME = "torchtext.lib.libtorchtext"
  19 _EXT_NAME = "torchtext._torchtext"
  20 _THIS_DIR = Path(__file__).parent.resolve()
  21 _ROOT_DIR = _THIS_DIR.parent.parent.resolve()
  22 
  23 
  24 def get_ext_modules():
  25     modules = [
  26         Extension(name=_LIBTORCHTEXT_NAME, sources=[]),
  27         Extension(name=_EXT_NAME, sources=[]),
  28     ]
  29     return modules
  30 
  31 
  32 # Based off of
  33 # https://github.com/pybind/cmake_example/blob/580c5fd29d4651db99d8874714b07c0c49a53f8a/setup.py
  34 
  35 
  36 class CMakeBuild(build_ext):
  37     def run(self):
  38         try:
  39             subprocess.check_output(["cmake", "--version"])
  40         except OSError:
  41             raise RuntimeError("CMake is not available.") from None
  42         super().run()
  43 
  44     def build_extension(self, ext):
  45         # Since two library files (libtorchaudio and _torchaudio) need to be
  46         # recognized by setuptools, we instantiate `Extension` twice. (see `get_ext_modules`)
  47         # This leads to the situation where this `build_extension` method is called twice.
  48         # However, the following `cmake` command will build all of them at the same time,
  49         # so, we do not need to perform `cmake` twice.
  50         # Therefore we call `cmake` only for `torchaudio._torchaudio`.
  51         if ext.name != "torchtext._torchtext":
  52             return
  53 
  54         extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  55 
  56         # required for auto-detection of auxiliary "native" libs
  57         if not extdir.endswith(os.path.sep):
  58             extdir += os.path.sep
  59 
  60         cfg = "Debug" if self.debug else "Release"
  61 
  62         cmake_args = [
  63             f"-DCMAKE_BUILD_TYPE={cfg}",
  64             f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}",
  65             f"-DCMAKE_INSTALL_PREFIX={extdir}",
  66             "-DCMAKE_VERBOSE_MAKEFILE=ON",
  67             f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
  68             f"-DTORCH_INSTALL_PREFIX:STRING={os.path.dirname(torch.__file__)}",
  69             "-DBUILD_TORCHTEXT_PYTHON_EXTENSION:BOOL=ON",
  70             "-DRE2_BUILD_TESTING:BOOL=OFF",
  71             "-DBUILD_TESTING:BOOL=OFF",
  72             "-DBUILD_SHARED_LIBS=OFF",
  73             "-DCMAKE_POLICY_DEFAULT_CMP0063=NEW",
  74             "-DSPM_ENABLE_SHARED=OFF",
  75         ]
  76         build_args = ["--target", "install"]
  77 
  78         # Default to Ninja
  79         if "CMAKE_GENERATOR" not in os.environ or platform.system() == "Windows":
  80             cmake_args += ["-GNinja"]
  81         if platform.system() == "Windows":
  82             import sys
  83 
  84             python_version = sys.version_info
  85             cmake_args += [
  86                 "-DCMAKE_C_COMPILER=cl",
  87                 "-DCMAKE_CXX_COMPILER=cl",
  88                 f"-DPYTHON_VERSION={python_version.major}.{python_version.minor}",
  89             ]
  90 
  91         # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
  92         # across all generators.
  93         if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
  94             # self.parallel is a Python 3 only way to set parallel jobs by hand
  95             # using -j in the build_ext call, not supported by pip or PyPA-build.
  96             if hasattr(self, "parallel") and self.parallel:
  97                 # CMake 3.12+ only.
  98                 build_args += ["-j{}".format(self.parallel)]
  99 
  100         if not os.path.exists(self.build_temp):
  101             os.makedirs(self.build_temp)
  102 
  103         subprocess.check_call(["cmake", str(_ROOT_DIR)] + cmake_args, cwd=self.build_temp)
  104         subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp)
  105 
  106     def get_ext_filename(self, fullname):
  107         ext_filename = super().get_ext_filename(fullname)
  108         ext_filename_parts = ext_filename.split(".")
  109         without_abi = ext_filename_parts[:-2] + ext_filename_parts[-1:]
  110         ext_filename = ".".join(without_abi)
  111         return ext_filename
  112
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/tools/setup_helpers/extension.py b/tools/setup_helpers/extension.py
  --- a/tools/setup_helpers/extension.py
  +++ b/tools/setup_helpers/extension.py
  @@ -21,6 +21,10 @@
   _ROOT_DIR = _THIS_DIR.parent.parent.resolve()
   
   
  +def _get_cxx11_abi():
  +    return "-D_GLIBCXX_USE_CXX11_ABI=" + str(int(torch.compiled_with_cxx11_abi()))
  +
  +
   def get_ext_modules():
       modules = [
           Extension(name=_LIBTORCHTEXT_NAME, sources=[]),
  @@ -72,6 +76,7 @@
               "-DBUILD_SHARED_LIBS=OFF",
               "-DCMAKE_POLICY_DEFAULT_CMP0063=NEW",
               "-DSPM_ENABLE_SHARED=OFF",
  +            f"-DTORCH_COMPILED_WITH_CXX_ABI={_get_cxx11_abi()}",
           ]
           build_args = ["--target", "install"]
  
verification_info: {"golden_diff": "diff --git a/tools/setup_helpers/extension.py b/tools/setup_helpers/extension.py\n--- a/tools/setup_helpers/extension.py\n+++ b/tools/setup_helpers/extension.py\n@@ -21,6 +21,10 @@\n _ROOT_DIR = _THIS_DIR.parent.parent.resolve()\n \n \n+def _get_cxx11_abi():\n+    return \"-D_GLIBCXX_USE_CXX11_ABI=\" + str(int(torch.compiled_with_cxx11_abi()))\n+\n+\n def get_ext_modules():\n     modules = [\n         Extension(name=_LIBTORCHTEXT_NAME, sources=[]),\n@@ -72,6 +76,7 @@\n             \"-DBUILD_SHARED_LIBS=OFF\",\n             \"-DCMAKE_POLICY_DEFAULT_CMP0063=NEW\",\n             \"-DSPM_ENABLE_SHARED=OFF\",\n+            f\"-DTORCH_COMPILED_WITH_CXX_ABI={_get_cxx11_abi()}\",\n         ]\n         build_args = [\"--target\", \"install\"]\n", "issue": "Error running unit tests when building with setup.py install\n## \ud83d\udc1b Bug\r\n\r\n**Describe the bug** A clear and concise description of what the bug is.\r\nWhen building with python setup.py install, running pytest from either the project root directory or the test/ directory causes the error `ImportError: torchtext C++ Extension is not found`. This can be worked-around by renaming the torchtext subdirectory, or by instead using python setup.py develop like the CI does (see .circleci/unittest/linux/scripts/install.sh#L36).\r\n\r\n**To Reproduce** Steps to reproduce the behavior:\r\n\r\n1. Follow the build steps like normal, running python setup.py install\r\n2. Run pytest\r\n3. Every test fails with the error `ImportError: torchtext C++ Extension is not found`.\r\n\r\n**Expected behavior** A clear and concise description of what you expected to happen.\r\n\r\nThe tests should succeed even when installing with setup.py install, either running pytest from the project root or the test/ directory (this is the case in pytorch) without having to rename the torchtext subdirectory.\r\n\r\n**Screenshots** If applicable, add screenshots to help explain your problem.\r\n\r\n**Environment**\r\n\r\nPlease copy and paste the output from our\r\n[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py) (or\r\nfill out the checklist below manually).\r\n\r\nYou can get the script and run it with:\r\n\r\n```\r\nwget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py\r\n# For security purposes, please check the contents of collect_env.py before running it.\r\npython collect_env.py\r\npython -c \"import torchtext; print(\\\"torchtext version is \\\", torchtext.__version__)\"\r\n```\r\n\r\n- PyTorch Version (e.g., 1.0): 1.12\r\n- OS (e.g., Linux): Linux\r\n- How you installed PyTorch (`conda`, `pip`, source): Compiled from source\r\n- Build command you used (if compiling from source): python3 ./setup.py install\r\n- Python version: 3.7.13\r\n- CUDA/cuDNN version: ROCm version 5.2\r\n- GPU models and configuration: N/A\r\n- Any other relevant information:\r\n\r\n**Additional context** Add any other context about the problem here.\r\n\n", "before_files": [{"content": "import distutils.sysconfig\nimport os\nimport platform\nimport subprocess\nfrom pathlib import Path\n\nimport torch\nfrom setuptools import Extension\nfrom setuptools.command.build_ext import build_ext\n\n\n__all__ = [\n    \"get_ext_modules\",\n    \"CMakeBuild\",\n]\n\n\n_LIBTORCHTEXT_NAME = \"torchtext.lib.libtorchtext\"\n_EXT_NAME = \"torchtext._torchtext\"\n_THIS_DIR = Path(__file__).parent.resolve()\n_ROOT_DIR = _THIS_DIR.parent.parent.resolve()\n\n\ndef get_ext_modules():\n    modules = [\n        Extension(name=_LIBTORCHTEXT_NAME, sources=[]),\n        Extension(name=_EXT_NAME, sources=[]),\n    ]\n    return modules\n\n\n# Based off of\n# https://github.com/pybind/cmake_example/blob/580c5fd29d4651db99d8874714b07c0c49a53f8a/setup.py\n\n\nclass CMakeBuild(build_ext):\n    def run(self):\n        try:\n            subprocess.check_output([\"cmake\", \"--version\"])\n        except OSError:\n            raise RuntimeError(\"CMake is not available.\") from None\n        super().run()\n\n    def build_extension(self, ext):\n        # Since two library files (libtorchaudio and _torchaudio) need to be\n        # recognized by setuptools, we instantiate `Extension` twice. (see `get_ext_modules`)\n        # This leads to the situation where this `build_extension` method is called twice.\n        # However, the following `cmake` command will build all of them at the same time,\n        # so, we do not need to perform `cmake` twice.\n        # Therefore we call `cmake` only for `torchaudio._torchaudio`.\n        if ext.name != \"torchtext._torchtext\":\n            return\n\n        extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))\n\n        # required for auto-detection of auxiliary \"native\" libs\n        if not extdir.endswith(os.path.sep):\n            extdir += os.path.sep\n\n        cfg = \"Debug\" if self.debug else \"Release\"\n\n        cmake_args = [\n            f\"-DCMAKE_BUILD_TYPE={cfg}\",\n            f\"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}\",\n            f\"-DCMAKE_INSTALL_PREFIX={extdir}\",\n            \"-DCMAKE_VERBOSE_MAKEFILE=ON\",\n            f\"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}\",\n            f\"-DTORCH_INSTALL_PREFIX:STRING={os.path.dirname(torch.__file__)}\",\n            \"-DBUILD_TORCHTEXT_PYTHON_EXTENSION:BOOL=ON\",\n            \"-DRE2_BUILD_TESTING:BOOL=OFF\",\n            \"-DBUILD_TESTING:BOOL=OFF\",\n            \"-DBUILD_SHARED_LIBS=OFF\",\n            \"-DCMAKE_POLICY_DEFAULT_CMP0063=NEW\",\n            \"-DSPM_ENABLE_SHARED=OFF\",\n        ]\n        build_args = [\"--target\", \"install\"]\n\n        # Default to Ninja\n        if \"CMAKE_GENERATOR\" not in os.environ or platform.system() == \"Windows\":\n            cmake_args += [\"-GNinja\"]\n        if platform.system() == \"Windows\":\n            import sys\n\n            python_version = sys.version_info\n            cmake_args += [\n                \"-DCMAKE_C_COMPILER=cl\",\n                \"-DCMAKE_CXX_COMPILER=cl\",\n                f\"-DPYTHON_VERSION={python_version.major}.{python_version.minor}\",\n            ]\n\n        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level\n        # across all generators.\n        if \"CMAKE_BUILD_PARALLEL_LEVEL\" not in os.environ:\n            # self.parallel is a Python 3 only way to set parallel jobs by hand\n            # using -j in the build_ext call, not supported by pip or PyPA-build.\n            if hasattr(self, \"parallel\") and self.parallel:\n                # CMake 3.12+ only.\n                build_args += [\"-j{}\".format(self.parallel)]\n\n        if not os.path.exists(self.build_temp):\n            os.makedirs(self.build_temp)\n\n        subprocess.check_call([\"cmake\", str(_ROOT_DIR)] + cmake_args, cwd=self.build_temp)\n        subprocess.check_call([\"cmake\", \"--build\", \".\"] + build_args, cwd=self.build_temp)\n\n    def get_ext_filename(self, fullname):\n        ext_filename = super().get_ext_filename(fullname)\n        ext_filename_parts = ext_filename.split(\".\")\n        without_abi = ext_filename_parts[:-2] + ext_filename_parts[-1:]\n        ext_filename = \".\".join(without_abi)\n        return ext_filename\n", "path": "tools/setup_helpers/extension.py"}], "after_files": [{"content": "import distutils.sysconfig\nimport os\nimport platform\nimport subprocess\nfrom pathlib import Path\n\nimport torch\nfrom setuptools import Extension\nfrom setuptools.command.build_ext import build_ext\n\n\n__all__ = [\n    \"get_ext_modules\",\n    \"CMakeBuild\",\n]\n\n\n_LIBTORCHTEXT_NAME = \"torchtext.lib.libtorchtext\"\n_EXT_NAME = \"torchtext._torchtext\"\n_THIS_DIR = Path(__file__).parent.resolve()\n_ROOT_DIR = _THIS_DIR.parent.parent.resolve()\n\n\ndef _get_cxx11_abi():\n    return \"-D_GLIBCXX_USE_CXX11_ABI=\" + str(int(torch.compiled_with_cxx11_abi()))\n\n\ndef get_ext_modules():\n    modules = [\n        Extension(name=_LIBTORCHTEXT_NAME, sources=[]),\n        Extension(name=_EXT_NAME, sources=[]),\n    ]\n    return modules\n\n\n# Based off of\n# https://github.com/pybind/cmake_example/blob/580c5fd29d4651db99d8874714b07c0c49a53f8a/setup.py\n\n\nclass CMakeBuild(build_ext):\n    def run(self):\n        try:\n            subprocess.check_output([\"cmake\", \"--version\"])\n        except OSError:\n            raise RuntimeError(\"CMake is not available.\") from None\n        super().run()\n\n    def build_extension(self, ext):\n        # Since two library files (libtorchaudio and _torchaudio) need to be\n        # recognized by setuptools, we instantiate `Extension` twice. (see `get_ext_modules`)\n        # This leads to the situation where this `build_extension` method is called twice.\n        # However, the following `cmake` command will build all of them at the same time,\n        # so, we do not need to perform `cmake` twice.\n        # Therefore we call `cmake` only for `torchaudio._torchaudio`.\n        if ext.name != \"torchtext._torchtext\":\n            return\n\n        extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))\n\n        # required for auto-detection of auxiliary \"native\" libs\n        if not extdir.endswith(os.path.sep):\n            extdir += os.path.sep\n\n        cfg = \"Debug\" if self.debug else \"Release\"\n\n        cmake_args = [\n            f\"-DCMAKE_BUILD_TYPE={cfg}\",\n            f\"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}\",\n            f\"-DCMAKE_INSTALL_PREFIX={extdir}\",\n            \"-DCMAKE_VERBOSE_MAKEFILE=ON\",\n            f\"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}\",\n            f\"-DTORCH_INSTALL_PREFIX:STRING={os.path.dirname(torch.__file__)}\",\n            \"-DBUILD_TORCHTEXT_PYTHON_EXTENSION:BOOL=ON\",\n            \"-DRE2_BUILD_TESTING:BOOL=OFF\",\n            \"-DBUILD_TESTING:BOOL=OFF\",\n            \"-DBUILD_SHARED_LIBS=OFF\",\n            \"-DCMAKE_POLICY_DEFAULT_CMP0063=NEW\",\n            \"-DSPM_ENABLE_SHARED=OFF\",\n            f\"-DTORCH_COMPILED_WITH_CXX_ABI={_get_cxx11_abi()}\",\n        ]\n        build_args = [\"--target\", \"install\"]\n\n        # Default to Ninja\n        if \"CMAKE_GENERATOR\" not in os.environ or platform.system() == \"Windows\":\n            cmake_args += [\"-GNinja\"]\n        if platform.system() == \"Windows\":\n            import sys\n\n            python_version = sys.version_info\n            cmake_args += [\n                \"-DCMAKE_C_COMPILER=cl\",\n                \"-DCMAKE_CXX_COMPILER=cl\",\n                f\"-DPYTHON_VERSION={python_version.major}.{python_version.minor}\",\n            ]\n\n        # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level\n        # across all generators.\n        if \"CMAKE_BUILD_PARALLEL_LEVEL\" not in os.environ:\n            # self.parallel is a Python 3 only way to set parallel jobs by hand\n            # using -j in the build_ext call, not supported by pip or PyPA-build.\n            if hasattr(self, \"parallel\") and self.parallel:\n                # CMake 3.12+ only.\n                build_args += [\"-j{}\".format(self.parallel)]\n\n        if not os.path.exists(self.build_temp):\n            os.makedirs(self.build_temp)\n\n        subprocess.check_call([\"cmake\", str(_ROOT_DIR)] + cmake_args, cwd=self.build_temp)\n        subprocess.check_call([\"cmake\", \"--build\", \".\"] + build_args, cwd=self.build_temp)\n\n    def get_ext_filename(self, fullname):\n        ext_filename = super().get_ext_filename(fullname)\n        ext_filename_parts = ext_filename.split(\".\")\n        without_abi = ext_filename_parts[:-2] + ext_filename_parts[-1:]\n        ext_filename = \".\".join(without_abi)\n        return ext_filename\n", "path": "tools/setup_helpers/extension.py"}]}