We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ray] Build failure when installing from source
<!--Please include [tune], [rllib], [autoscaler] etc. in the issue title if relevant-->

### What is the problem?
I am trying to install ray from source. However, I receive the following error during the install process:
```
HEAD is now at 8ffe41c apply cpython patch bpo-39492 for the reference count issue
+ /usr/bin/python setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'
Traceback (most recent call last):
  File "setup.py", line 178, in <module>
    setup(
  File "/usr/lib/python3.8/site-packages/setuptools/__init__.py", line 144, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.8/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 107, in run
    subprocess.check_call(command)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['../build.sh', '-p', '/usr/bin/python']' returned non-zero exit status 1.
```

Note: `error invalid command 'bdist_wheel'`

*Ray version and other system information (Python version, TensorFlow version, OS):*
ray: 0.8.4
python: 3.8.2
os: Arch Linux

### Reproduction (REQUIRED)
Please provide a script that can be run to reproduce the issue. The script should have **no external library dependencies** (i.e., use fake or mock data / environments):

If we cannot run your script, we cannot fix your issue.

- [ ] I have verified my script runs in a clean environment and reproduces the issue.
- [ ] I have verified the issue also occurs with the [latest wheels](https://ray.readthedocs.io/en/latest/installation.html).

The above does not apply since this is a build issue.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/setup.py`
Content:
```
1 from itertools import chain
2 import os
3 import re
4 import shutil
5 import subprocess
6 import sys
7 
8 from setuptools import setup, find_packages, Distribution
9 import setuptools.command.build_ext as _build_ext
10 
11 # Ideally, we could include these files by putting them in a
12 # MANIFEST.in or using the package_data argument to setup, but the
13 # MANIFEST.in gets applied at the very beginning when setup.py runs
14 # before these files have been created, so we have to move the files
15 # manually.
16 
17 # NOTE: The lists below must be kept in sync with ray/BUILD.bazel.
18 ray_files = [
19     "ray/core/src/ray/thirdparty/redis/src/redis-server",
20     "ray/core/src/ray/gcs/redis_module/libray_redis_module.so",
21     "ray/core/src/plasma/plasma_store_server",
22     "ray/_raylet.so",
23     "ray/core/src/ray/raylet/raylet_monitor",
24     "ray/core/src/ray/gcs/gcs_server",
25     "ray/core/src/ray/raylet/raylet",
26     "ray/streaming/_streaming.so",
27 ]
28 
29 build_java = os.getenv("RAY_INSTALL_JAVA") == "1"
30 if build_java:
31     ray_files.append("ray/jars/ray_dist.jar")
32 
33 # These are the directories where automatically generated Python protobuf
34 # bindings are created.
35 generated_python_directories = [
36     "ray/core/generated",
37     "ray/streaming/generated",
38 ]
39 
40 optional_ray_files = []
41 
42 ray_autoscaler_files = [
43     "ray/autoscaler/aws/example-full.yaml",
44     "ray/autoscaler/azure/example-full.yaml",
45     "ray/autoscaler/gcp/example-full.yaml",
46     "ray/autoscaler/local/example-full.yaml",
47     "ray/autoscaler/kubernetes/example-full.yaml",
48     "ray/autoscaler/kubernetes/kubectl-rsync.sh",
49     "ray/autoscaler/ray-schema.json"
50 ]
51 
52 ray_project_files = [
53     "ray/projects/schema.json", "ray/projects/templates/cluster_template.yaml",
54     "ray/projects/templates/project_template.yaml",
55     "ray/projects/templates/requirements.txt"
56 ]
57 
58 ray_dashboard_files = [
59     os.path.join(dirpath, filename)
60     for dirpath, dirnames, filenames in os.walk("ray/dashboard/client/build")
61     for filename in filenames
62 ]
63 
64 optional_ray_files += ray_autoscaler_files
65 optional_ray_files += ray_project_files
66 optional_ray_files += ray_dashboard_files
67 
68 if "RAY_USE_NEW_GCS" in os.environ and os.environ["RAY_USE_NEW_GCS"] == "on":
69     ray_files += [
70         "ray/core/src/credis/build/src/libmember.so",
71         "ray/core/src/credis/build/src/libmaster.so",
72         "ray/core/src/credis/redis/src/redis-server"
73     ]
74 
75 extras = {
76     "debug": [],
77     "dashboard": ["requests"],
78     "serve": ["uvicorn", "pygments", "werkzeug", "flask", "pandas", "blist"],
79     "tune": ["tabulate", "tensorboardX", "pandas"]
80 }
81 
82 extras["rllib"] = extras["tune"] + [
83     "atari_py",
84     "dm_tree",
85     "gym[atari]",
86     "lz4",
87     "opencv-python-headless",
88     "pyyaml",
89     "scipy",
90 ]
91 
92 extras["streaming"] = ["msgpack >= 0.6.2"]
93 
94 extras["all"] = list(set(chain.from_iterable(extras.values())))
95 
96 
97 class build_ext(_build_ext.build_ext):
98     def run(self):
99         # Note: We are passing in sys.executable so that we use the same
100         # version of Python to build packages inside the build.sh script. Note
101         # that certain flags will not be passed along such as --user or sudo.
102         # TODO(rkn): Fix this.
103         command = ["../build.sh", "-p", sys.executable]
104         if build_java:
105             # Also build binaries for Java if the above env variable exists.
106             command += ["-l", "python,java"]
107         subprocess.check_call(command)
108 
109         # We also need to install pickle5 along with Ray, so make sure that the
110         # relevant non-Python pickle5 files get copied.
111         pickle5_files = self.walk_directory("./ray/pickle5_files/pickle5")
112 
113         thirdparty_files = self.walk_directory("./ray/thirdparty_files")
114 
115         files_to_include = ray_files + pickle5_files + thirdparty_files
116 
117         # Copy over the autogenerated protobuf Python bindings.
118         for directory in generated_python_directories:
119             for filename in os.listdir(directory):
120                 if filename[-3:] == ".py":
121                     files_to_include.append(os.path.join(directory, filename))
122 
123         for filename in files_to_include:
124             self.move_file(filename)
125 
126         # Try to copy over the optional files.
127         for filename in optional_ray_files:
128             try:
129                 self.move_file(filename)
130             except Exception:
131                 print("Failed to copy optional file {}. This is ok."
132                       .format(filename))
133 
134     def walk_directory(self, directory):
135         file_list = []
136         for (root, dirs, filenames) in os.walk(directory):
137             for name in filenames:
138                 file_list.append(os.path.join(root, name))
139         return file_list
140 
141     def move_file(self, filename):
142         # TODO(rkn): This feels very brittle. It may not handle all cases. See
143         # https://github.com/apache/arrow/blob/master/python/setup.py for an
144         # example.
145         source = filename
146         destination = os.path.join(self.build_lib, filename)
147         # Create the target directory if it doesn't already exist.
148         parent_directory = os.path.dirname(destination)
149         if not os.path.exists(parent_directory):
150             os.makedirs(parent_directory)
151         if not os.path.exists(destination):
152             print("Copying {} to {}.".format(source, destination))
153             shutil.copy(source, destination, follow_symlinks=True)
154 
155 
156 class BinaryDistribution(Distribution):
157     def has_ext_modules(self):
158         return True
159 
160 
161 def find_version(*filepath):
162     # Extract version information from filepath
163     here = os.path.abspath(os.path.dirname(__file__))
164     with open(os.path.join(here, *filepath)) as fp:
165         version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
166                                   fp.read(), re.M)
167         if version_match:
168             return version_match.group(1)
169         raise RuntimeError("Unable to find version string.")
170 
171 
172 requires = [
173     "numpy >= 1.16", "filelock", "jsonschema", "click", "colorama", "pyyaml",
174     "redis >= 3.3.2", "protobuf >= 3.8.0", "py-spy >= 0.2.0", "aiohttp",
175     "google", "grpcio"
176 ]
177 
178 setup(
179     name="ray",
180     version=find_version("ray", "__init__.py"),
181     author="Ray Team",
182     author_email="ray-dev@googlegroups.com",
183     description=("A system for parallel and distributed Python that unifies "
184                  "the ML ecosystem."),
185     long_description=open("../README.rst").read(),
186     url="https://github.com/ray-project/ray",
187     keywords=("ray distributed parallel machine-learning "
188               "reinforcement-learning deep-learning python"),
189     packages=find_packages(),
190     cmdclass={"build_ext": build_ext},
191     # The BinaryDistribution argument triggers build_ext.
192     distclass=BinaryDistribution,
193     install_requires=requires,
194     setup_requires=["cython >= 0.29.14"],
195     extras_require=extras,
196     entry_points={
197         "console_scripts": [
198             "ray=ray.scripts.scripts:main",
199             "rllib=ray.rllib.scripts:cli [rllib]", "tune=ray.tune.scripts:cli"
200         ]
201     },
202     include_package_data=True,
203     zip_safe=False,
204     license="Apache 2.0")
205
```
--- 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/python/setup.py b/python/setup.py
--- a/python/setup.py
+++ b/python/setup.py
@@ -191,7 +191,7 @@
     # The BinaryDistribution argument triggers build_ext.
     distclass=BinaryDistribution,
     install_requires=requires,
-    setup_requires=["cython >= 0.29.14"],
+    setup_requires=["cython >= 0.29.14", "wheel"],
     extras_require=extras,
     entry_points={
         "console_scripts": [

{"golden_diff": "diff --git a/python/setup.py b/python/setup.py\n--- a/python/setup.py\n+++ b/python/setup.py\n@@ -191,7 +191,7 @@\n     # The BinaryDistribution argument triggers build_ext.\n     distclass=BinaryDistribution,\n     install_requires=requires,\n-    setup_requires=[\"cython >= 0.29.14\"],\n+    setup_requires=[\"cython >= 0.29.14\", \"wheel\"],\n     extras_require=extras,\n     entry_points={\n         \"console_scripts\": [\n", "issue": "[ray] Build failure when installing from source\n<!--Please include [tune], [rllib], [autoscaler] etc. in the issue title if relevant-->\r\n\r\n### What is the problem?\r\nI am trying to install ray from source. However, I receive the following error during the install process:\r\n```\r\nHEAD is now at 8ffe41c apply cpython patch bpo-39492 for the reference count issue\r\n+ /usr/bin/python setup.py bdist_wheel\r\nusage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]\r\n   or: setup.py --help [cmd1 cmd2 ...]\r\n   or: setup.py --help-commands\r\n   or: setup.py cmd --help\r\n\r\nerror: invalid command 'bdist_wheel'\r\nTraceback (most recent call last):\r\n  File \"setup.py\", line 178, in <module>\r\n    setup(\r\n  File \"/usr/lib/python3.8/site-packages/setuptools/__init__.py\", line 144, in setup\r\n    return distutils.core.setup(**attrs)\r\n  File \"/usr/lib/python3.8/distutils/core.py\", line 148, in setup\r\n    dist.run_commands()\r\n  File \"/usr/lib/python3.8/distutils/dist.py\", line 966, in run_commands\r\n    self.run_command(cmd)\r\n  File \"/usr/lib/python3.8/distutils/dist.py\", line 985, in run_command\r\n    cmd_obj.run()\r\n  File \"/usr/lib/python3.8/distutils/command/build.py\", line 135, in run\r\n    self.run_command(cmd_name)\r\n  File \"/usr/lib/python3.8/distutils/cmd.py\", line 313, in run_command\r\n    self.distribution.run_command(command)\r\n  File \"/usr/lib/python3.8/distutils/dist.py\", line 985, in run_command\r\n    cmd_obj.run()\r\n  File \"setup.py\", line 107, in run\r\n    subprocess.check_call(command)\r\n  File \"/usr/lib/python3.8/subprocess.py\", line 364, in check_call\r\n    raise CalledProcessError(retcode, cmd)\r\nsubprocess.CalledProcessError: Command '['../build.sh', '-p', '/usr/bin/python']' returned non-zero exit status 1.\r\n```\r\n\r\nNote: `error invalid command 'bdist_wheel'`\r\n\r\n*Ray version and other system information (Python version, TensorFlow version, OS):*\r\nray: 0.8.4\r\npython: 3.8.2\r\nos: Arch Linux\r\n\r\n### Reproduction (REQUIRED)\r\nPlease provide a script that can be run to reproduce the issue. The script should have **no external library dependencies** (i.e., use fake or mock data / environments):\r\n\r\nIf we cannot run your script, we cannot fix your issue.\r\n\r\n- [ ] I have verified my script runs in a clean environment and reproduces the issue.\r\n- [ ] I have verified the issue also occurs with the [latest wheels](https://ray.readthedocs.io/en/latest/installation.html).\r\n\r\nThe above does not apply since this is a build issue.\r\n\n", "before_files": [{"content": "from itertools import chain\nimport os\nimport re\nimport shutil\nimport subprocess\nimport sys\n\nfrom setuptools import setup, find_packages, Distribution\nimport setuptools.command.build_ext as _build_ext\n\n# Ideally, we could include these files by putting them in a\n# MANIFEST.in or using the package_data argument to setup, but the\n# MANIFEST.in gets applied at the very beginning when setup.py runs\n# before these files have been created, so we have to move the files\n# manually.\n\n# NOTE: The lists below must be kept in sync with ray/BUILD.bazel.\nray_files = [\n    \"ray/core/src/ray/thirdparty/redis/src/redis-server\",\n    \"ray/core/src/ray/gcs/redis_module/libray_redis_module.so\",\n    \"ray/core/src/plasma/plasma_store_server\",\n    \"ray/_raylet.so\",\n    \"ray/core/src/ray/raylet/raylet_monitor\",\n    \"ray/core/src/ray/gcs/gcs_server\",\n    \"ray/core/src/ray/raylet/raylet\",\n    \"ray/streaming/_streaming.so\",\n]\n\nbuild_java = os.getenv(\"RAY_INSTALL_JAVA\") == \"1\"\nif build_java:\n    ray_files.append(\"ray/jars/ray_dist.jar\")\n\n# These are the directories where automatically generated Python protobuf\n# bindings are created.\ngenerated_python_directories = [\n    \"ray/core/generated\",\n    \"ray/streaming/generated\",\n]\n\noptional_ray_files = []\n\nray_autoscaler_files = [\n    \"ray/autoscaler/aws/example-full.yaml\",\n    \"ray/autoscaler/azure/example-full.yaml\",\n    \"ray/autoscaler/gcp/example-full.yaml\",\n    \"ray/autoscaler/local/example-full.yaml\",\n    \"ray/autoscaler/kubernetes/example-full.yaml\",\n    \"ray/autoscaler/kubernetes/kubectl-rsync.sh\",\n    \"ray/autoscaler/ray-schema.json\"\n]\n\nray_project_files = [\n    \"ray/projects/schema.json\", \"ray/projects/templates/cluster_template.yaml\",\n    \"ray/projects/templates/project_template.yaml\",\n    \"ray/projects/templates/requirements.txt\"\n]\n\nray_dashboard_files = [\n    os.path.join(dirpath, filename)\n    for dirpath, dirnames, filenames in os.walk(\"ray/dashboard/client/build\")\n    for filename in filenames\n]\n\noptional_ray_files += ray_autoscaler_files\noptional_ray_files += ray_project_files\noptional_ray_files += ray_dashboard_files\n\nif \"RAY_USE_NEW_GCS\" in os.environ and os.environ[\"RAY_USE_NEW_GCS\"] == \"on\":\n    ray_files += [\n        \"ray/core/src/credis/build/src/libmember.so\",\n        \"ray/core/src/credis/build/src/libmaster.so\",\n        \"ray/core/src/credis/redis/src/redis-server\"\n    ]\n\nextras = {\n    \"debug\": [],\n    \"dashboard\": [\"requests\"],\n    \"serve\": [\"uvicorn\", \"pygments\", \"werkzeug\", \"flask\", \"pandas\", \"blist\"],\n    \"tune\": [\"tabulate\", \"tensorboardX\", \"pandas\"]\n}\n\nextras[\"rllib\"] = extras[\"tune\"] + [\n    \"atari_py\",\n    \"dm_tree\",\n    \"gym[atari]\",\n    \"lz4\",\n    \"opencv-python-headless\",\n    \"pyyaml\",\n    \"scipy\",\n]\n\nextras[\"streaming\"] = [\"msgpack >= 0.6.2\"]\n\nextras[\"all\"] = list(set(chain.from_iterable(extras.values())))\n\n\nclass build_ext(_build_ext.build_ext):\n    def run(self):\n        # Note: We are passing in sys.executable so that we use the same\n        # version of Python to build packages inside the build.sh script. Note\n        # that certain flags will not be passed along such as --user or sudo.\n        # TODO(rkn): Fix this.\n        command = [\"../build.sh\", \"-p\", sys.executable]\n        if build_java:\n            # Also build binaries for Java if the above env variable exists.\n            command += [\"-l\", \"python,java\"]\n        subprocess.check_call(command)\n\n        # We also need to install pickle5 along with Ray, so make sure that the\n        # relevant non-Python pickle5 files get copied.\n        pickle5_files = self.walk_directory(\"./ray/pickle5_files/pickle5\")\n\n        thirdparty_files = self.walk_directory(\"./ray/thirdparty_files\")\n\n        files_to_include = ray_files + pickle5_files + thirdparty_files\n\n        # Copy over the autogenerated protobuf Python bindings.\n        for directory in generated_python_directories:\n            for filename in os.listdir(directory):\n                if filename[-3:] == \".py\":\n                    files_to_include.append(os.path.join(directory, filename))\n\n        for filename in files_to_include:\n            self.move_file(filename)\n\n        # Try to copy over the optional files.\n        for filename in optional_ray_files:\n            try:\n                self.move_file(filename)\n            except Exception:\n                print(\"Failed to copy optional file {}. This is ok.\"\n                      .format(filename))\n\n    def walk_directory(self, directory):\n        file_list = []\n        for (root, dirs, filenames) in os.walk(directory):\n            for name in filenames:\n                file_list.append(os.path.join(root, name))\n        return file_list\n\n    def move_file(self, filename):\n        # TODO(rkn): This feels very brittle. It may not handle all cases. See\n        # https://github.com/apache/arrow/blob/master/python/setup.py for an\n        # example.\n        source = filename\n        destination = os.path.join(self.build_lib, filename)\n        # Create the target directory if it doesn't already exist.\n        parent_directory = os.path.dirname(destination)\n        if not os.path.exists(parent_directory):\n            os.makedirs(parent_directory)\n        if not os.path.exists(destination):\n            print(\"Copying {} to {}.\".format(source, destination))\n            shutil.copy(source, destination, follow_symlinks=True)\n\n\nclass BinaryDistribution(Distribution):\n    def has_ext_modules(self):\n        return True\n\n\ndef find_version(*filepath):\n    # Extract version information from filepath\n    here = os.path.abspath(os.path.dirname(__file__))\n    with open(os.path.join(here, *filepath)) as fp:\n        version_match = re.search(r\"^__version__ = ['\\\"]([^'\\\"]*)['\\\"]\",\n                                  fp.read(), re.M)\n        if version_match:\n            return version_match.group(1)\n        raise RuntimeError(\"Unable to find version string.\")\n\n\nrequires = [\n    \"numpy >= 1.16\", \"filelock\", \"jsonschema\", \"click\", \"colorama\", \"pyyaml\",\n    \"redis >= 3.3.2\", \"protobuf >= 3.8.0\", \"py-spy >= 0.2.0\", \"aiohttp\",\n    \"google\", \"grpcio\"\n]\n\nsetup(\n    name=\"ray\",\n    version=find_version(\"ray\", \"__init__.py\"),\n    author=\"Ray Team\",\n    author_email=\"ray-dev@googlegroups.com\",\n    description=(\"A system for parallel and distributed Python that unifies \"\n                 \"the ML ecosystem.\"),\n    long_description=open(\"../README.rst\").read(),\n    url=\"https://github.com/ray-project/ray\",\n    keywords=(\"ray distributed parallel machine-learning \"\n              \"reinforcement-learning deep-learning python\"),\n    packages=find_packages(),\n    cmdclass={\"build_ext\": build_ext},\n    # The BinaryDistribution argument triggers build_ext.\n    distclass=BinaryDistribution,\n    install_requires=requires,\n    setup_requires=[\"cython >= 0.29.14\"],\n    extras_require=extras,\n    entry_points={\n        \"console_scripts\": [\n            \"ray=ray.scripts.scripts:main\",\n            \"rllib=ray.rllib.scripts:cli [rllib]\", \"tune=ray.tune.scripts:cli\"\n        ]\n    },\n    include_package_data=True,\n    zip_safe=False,\n    license=\"Apache 2.0\")\n", "path": "python/setup.py"}], "after_files": [{"content": "from itertools import chain\nimport os\nimport re\nimport shutil\nimport subprocess\nimport sys\n\nfrom setuptools import setup, find_packages, Distribution\nimport setuptools.command.build_ext as _build_ext\n\n# Ideally, we could include these files by putting them in a\n# MANIFEST.in or using the package_data argument to setup, but the\n# MANIFEST.in gets applied at the very beginning when setup.py runs\n# before these files have been created, so we have to move the files\n# manually.\n\n# NOTE: The lists below must be kept in sync with ray/BUILD.bazel.\nray_files = [\n    \"ray/core/src/ray/thirdparty/redis/src/redis-server\",\n    \"ray/core/src/ray/gcs/redis_module/libray_redis_module.so\",\n    \"ray/core/src/plasma/plasma_store_server\",\n    \"ray/_raylet.so\",\n    \"ray/core/src/ray/raylet/raylet_monitor\",\n    \"ray/core/src/ray/gcs/gcs_server\",\n    \"ray/core/src/ray/raylet/raylet\",\n    \"ray/streaming/_streaming.so\",\n]\n\nbuild_java = os.getenv(\"RAY_INSTALL_JAVA\") == \"1\"\nif build_java:\n    ray_files.append(\"ray/jars/ray_dist.jar\")\n\n# These are the directories where automatically generated Python protobuf\n# bindings are created.\ngenerated_python_directories = [\n    \"ray/core/generated\",\n    \"ray/streaming/generated\",\n]\n\noptional_ray_files = []\n\nray_autoscaler_files = [\n    \"ray/autoscaler/aws/example-full.yaml\",\n    \"ray/autoscaler/azure/example-full.yaml\",\n    \"ray/autoscaler/gcp/example-full.yaml\",\n    \"ray/autoscaler/local/example-full.yaml\",\n    \"ray/autoscaler/kubernetes/example-full.yaml\",\n    \"ray/autoscaler/kubernetes/kubectl-rsync.sh\",\n    \"ray/autoscaler/ray-schema.json\"\n]\n\nray_project_files = [\n    \"ray/projects/schema.json\", \"ray/projects/templates/cluster_template.yaml\",\n    \"ray/projects/templates/project_template.yaml\",\n    \"ray/projects/templates/requirements.txt\"\n]\n\nray_dashboard_files = [\n    os.path.join(dirpath, filename)\n    for dirpath, dirnames, filenames in os.walk(\"ray/dashboard/client/build\")\n    for filename in filenames\n]\n\noptional_ray_files += ray_autoscaler_files\noptional_ray_files += ray_project_files\noptional_ray_files += ray_dashboard_files\n\nif \"RAY_USE_NEW_GCS\" in os.environ and os.environ[\"RAY_USE_NEW_GCS\"] == \"on\":\n    ray_files += [\n        \"ray/core/src/credis/build/src/libmember.so\",\n        \"ray/core/src/credis/build/src/libmaster.so\",\n        \"ray/core/src/credis/redis/src/redis-server\"\n    ]\n\nextras = {\n    \"debug\": [],\n    \"dashboard\": [\"requests\"],\n    \"serve\": [\"uvicorn\", \"pygments\", \"werkzeug\", \"flask\", \"pandas\", \"blist\"],\n    \"tune\": [\"tabulate\", \"tensorboardX\", \"pandas\"]\n}\n\nextras[\"rllib\"] = extras[\"tune\"] + [\n    \"atari_py\",\n    \"dm_tree\",\n    \"gym[atari]\",\n    \"lz4\",\n    \"opencv-python-headless\",\n    \"pyyaml\",\n    \"scipy\",\n]\n\nextras[\"streaming\"] = [\"msgpack >= 0.6.2\"]\n\nextras[\"all\"] = list(set(chain.from_iterable(extras.values())))\n\n\nclass build_ext(_build_ext.build_ext):\n    def run(self):\n        # Note: We are passing in sys.executable so that we use the same\n        # version of Python to build packages inside the build.sh script. Note\n        # that certain flags will not be passed along such as --user or sudo.\n        # TODO(rkn): Fix this.\n        command = [\"../build.sh\", \"-p\", sys.executable]\n        if build_java:\n            # Also build binaries for Java if the above env variable exists.\n            command += [\"-l\", \"python,java\"]\n        subprocess.check_call(command)\n\n        # We also need to install pickle5 along with Ray, so make sure that the\n        # relevant non-Python pickle5 files get copied.\n        pickle5_files = self.walk_directory(\"./ray/pickle5_files/pickle5\")\n\n        thirdparty_files = self.walk_directory(\"./ray/thirdparty_files\")\n\n        files_to_include = ray_files + pickle5_files + thirdparty_files\n\n        # Copy over the autogenerated protobuf Python bindings.\n        for directory in generated_python_directories:\n            for filename in os.listdir(directory):\n                if filename[-3:] == \".py\":\n                    files_to_include.append(os.path.join(directory, filename))\n\n        for filename in files_to_include:\n            self.move_file(filename)\n\n        # Try to copy over the optional files.\n        for filename in optional_ray_files:\n            try:\n                self.move_file(filename)\n            except Exception:\n                print(\"Failed to copy optional file {}. This is ok.\"\n                      .format(filename))\n\n    def walk_directory(self, directory):\n        file_list = []\n        for (root, dirs, filenames) in os.walk(directory):\n            for name in filenames:\n                file_list.append(os.path.join(root, name))\n        return file_list\n\n    def move_file(self, filename):\n        # TODO(rkn): This feels very brittle. It may not handle all cases. See\n        # https://github.com/apache/arrow/blob/master/python/setup.py for an\n        # example.\n        source = filename\n        destination = os.path.join(self.build_lib, filename)\n        # Create the target directory if it doesn't already exist.\n        parent_directory = os.path.dirname(destination)\n        if not os.path.exists(parent_directory):\n            os.makedirs(parent_directory)\n        if not os.path.exists(destination):\n            print(\"Copying {} to {}.\".format(source, destination))\n            shutil.copy(source, destination, follow_symlinks=True)\n\n\nclass BinaryDistribution(Distribution):\n    def has_ext_modules(self):\n        return True\n\n\ndef find_version(*filepath):\n    # Extract version information from filepath\n    here = os.path.abspath(os.path.dirname(__file__))\n    with open(os.path.join(here, *filepath)) as fp:\n        version_match = re.search(r\"^__version__ = ['\\\"]([^'\\\"]*)['\\\"]\",\n                                  fp.read(), re.M)\n        if version_match:\n            return version_match.group(1)\n        raise RuntimeError(\"Unable to find version string.\")\n\n\nrequires = [\n    \"numpy >= 1.16\", \"filelock\", \"jsonschema\", \"click\", \"colorama\", \"pyyaml\",\n    \"redis >= 3.3.2\", \"protobuf >= 3.8.0\", \"py-spy >= 0.2.0\", \"aiohttp\",\n    \"google\", \"grpcio\"\n]\n\nsetup(\n    name=\"ray\",\n    version=find_version(\"ray\", \"__init__.py\"),\n    author=\"Ray Team\",\n    author_email=\"ray-dev@googlegroups.com\",\n    description=(\"A system for parallel and distributed Python that unifies \"\n                 \"the ML ecosystem.\"),\n    long_description=open(\"../README.rst\").read(),\n    url=\"https://github.com/ray-project/ray\",\n    keywords=(\"ray distributed parallel machine-learning \"\n              \"reinforcement-learning deep-learning python\"),\n    packages=find_packages(),\n    cmdclass={\"build_ext\": build_ext},\n    # The BinaryDistribution argument triggers build_ext.\n    distclass=BinaryDistribution,\n    install_requires=requires,\n    setup_requires=[\"cython >= 0.29.14\", \"wheel\"],\n    extras_require=extras,\n    entry_points={\n        \"console_scripts\": [\n            \"ray=ray.scripts.scripts:main\",\n            \"rllib=ray.rllib.scripts:cli [rllib]\", \"tune=ray.tune.scripts:cli\"\n        ]\n    },\n    include_package_data=True,\n    zip_safe=False,\n    license=\"Apache 2.0\")\n", "path": "python/setup.py"}]}