getting-involved.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. .. include:: /_includes/_latest_contribution_doc.rst
  2. .. _getting-involved:
  3. Getting Involved / Contributing
  4. ===============================
  5. Ray is more than a framework for distributed applications but also an active community of developers,
  6. researchers, and folks that love machine learning.
  7. .. tip:: Ask questions on `our forum <https://discuss.ray.io/>`_! The
  8. community is extremely active in helping people succeed in building their
  9. Ray applications.
  10. You can join (and Star!) us on `on GitHub`_.
  11. .. _`on GitHub`: https://github.com/ray-project/ray
  12. Contributing to Ray
  13. -------------------
  14. We welcome (and encourage!) all forms of contributions to Ray, including and not limited to:
  15. - Code reviewing of patches and PRs.
  16. - Pushing patches.
  17. - Documentation and examples.
  18. - Community participation in forums and issues.
  19. - Code readability and code comments to improve readability.
  20. - Test cases to make the codebase more robust.
  21. - Tutorials, blog posts, talks that promote the project.
  22. - Features and major changes via Ray Enhancement Proposals (REP): https://github.com/ray-project/enhancements
  23. What can I work on?
  24. -------------------
  25. We use Github to track issues, feature requests, and bugs. Take a look at the
  26. ones labeled `"good first issue" <https://github.com/ray-project/ray/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22>`__ for a place to start.
  27. Setting up your development environment
  28. ---------------------------------------
  29. To edit the Ray source code, you'll want to checkout the repository and also build Ray from source. Follow :ref:`these instructions for building <building-ray>` a local copy of Ray to easily make changes.
  30. Submitting and Merging a Contribution
  31. -------------------------------------
  32. There are a couple steps to merge a contribution.
  33. 1. First merge the most recent version of master into your development branch.
  34. .. code:: bash
  35. git remote add upstream https://github.com/ray-project/ray.git
  36. git pull . upstream/master
  37. 2. Make sure all existing `tests <getting-involved.html#testing>`__ and `linters <getting-involved.html#lint-and-formatting>`__ pass.
  38. Run ``setup_hooks.sh`` to create a git hook that will run the linter before you push your changes.
  39. 3. If introducing a new feature or patching a bug, be sure to add new test cases
  40. in the relevant file in ``ray/python/ray/tests/``.
  41. 4. Document the code. Public functions need to be documented, and remember to provide an usage
  42. example if applicable. See ``doc/README.md`` for instructions on editing and building public documentation.
  43. 5. Address comments on your PR. During the review
  44. process you may need to address merge conflicts with other changes. To resolve merge conflicts,
  45. run ``git pull . upstream/master`` on your branch (please do not use rebase, as it is less
  46. friendly to the GitHub review tool. All commits will be squashed on merge.)
  47. 6. Reviewers will merge and approve the pull request; be sure to ping them if
  48. the pull request is getting stale.
  49. PR Review Process
  50. -----------------
  51. For contributors who are in the ``ray-project`` organization:
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. - When you first create a PR, add an reviewer to the `assignee` section.
  54. - Assignees will review your PR and add the `@author-action-required` label if further actions are required.
  55. - Address their comments and remove the `@author-action-required` label from the PR.
  56. - Repeat this process until assignees approve your PR.
  57. - Once the PR is approved, the author is in charge of ensuring the PR passes the build. Add the `test-ok` label if the build succeeds.
  58. - Committers will merge the PR once the build is passing.
  59. For contributors who are not in the ``ray-project`` organization:
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. - Your PRs will have assignees shortly. Assignees of PRs will be actively engaging with contributors to merge the PR.
  62. - Please actively ping assignees after you address your comments!
  63. Testing
  64. -------
  65. Even though we have hooks to run unit tests automatically for each pull request,
  66. we recommend you to run unit tests locally beforehand to reduce reviewers’
  67. burden and speedup review process.
  68. If you are running tests for the first time, you can install the required dependencies with:
  69. .. code-block:: shell
  70. pip install -c python/requirements.txt -r python/requirements_test.txt
  71. Testing for Python development
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. The full suite of tests is too large to run on a single machine. However, you can run individual relevant Python test files. Suppose that one of the tests in a file of tests, e.g., ``python/ray/tests/test_basic.py``, is failing. You can run just that test file locally as follows:
  74. .. code-block:: shell
  75. # Directly calling `pytest -v ...` may lose import paths.
  76. python -m pytest -v -s python/ray/tests/test_basic.py
  77. This will run all of the tests in the file. To run a specific test, use the following:
  78. .. code-block:: shell
  79. # Directly calling `pytest -v ...` may lose import paths.
  80. python -m pytest -v -s test_file.py::name_of_the_test
  81. Testing for C++ development
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. To compile and run all C++ tests, you can run:
  84. .. code-block:: shell
  85. bazel test $(bazel query 'kind(cc_test, ...)')
  86. Alternatively, you can also run one specific C++ test. You can use:
  87. .. code-block:: shell
  88. bazel test $(bazel query 'kind(cc_test, ...)') --test_filter=ClientConnectionTest --test_output=streamed
  89. Code Style
  90. ----------
  91. In general, we follow the `Google style guide <https://google.github.io/styleguide/>`__ for C++ code and the `Black code style <https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html>`__ for Python code. Python imports follow `PEP8 style <https://peps.python.org/pep-0008/#imports>`__. However, it is more important for code to be in a locally consistent style than to strictly follow guidelines. Whenever in doubt, follow the local code style of the component.
  92. For Python documentation, we follow a subset of the `Google pydoc format <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html>`__. The following code snippets demonstrate the canonical Ray pydoc formatting:
  93. .. testcode::
  94. def ray_canonical_doc_style(param1: int, param2: str) -> bool:
  95. """First sentence MUST be inline with the quotes and fit on one line.
  96. Additional explanatory text can be added in paragraphs such as this one.
  97. Do not introduce multi-line first sentences.
  98. Examples:
  99. .. doctest::
  100. >>> # Provide code examples for key use cases, as possible.
  101. >>> ray_canonical_doc_style(41, "hello")
  102. True
  103. >>> # A second example.
  104. >>> ray_canonical_doc_style(72, "goodbye")
  105. False
  106. Args:
  107. param1: The first parameter. Do not include the types in the
  108. docstring. They should be defined only in the signature.
  109. Multi-line parameter docs should be indented by four spaces.
  110. param2: The second parameter.
  111. Returns:
  112. The return value. Do not include types here.
  113. """
  114. .. testcode::
  115. class RayClass:
  116. """The summary line for a class docstring should fit on one line.
  117. Additional explanatory text can be added in paragraphs such as this one.
  118. Do not introduce multi-line first sentences.
  119. The __init__ method is documented here in the class level docstring.
  120. All the public methods and attributes should have docstrings.
  121. Examples:
  122. .. testcode::
  123. obj = RayClass(12, "world")
  124. obj.increment_attr1()
  125. Args:
  126. param1: The first parameter. Do not include the types in the
  127. docstring. They should be defined only in the signature.
  128. Multi-line parameter docs should be indented by four spaces.
  129. param2: The second parameter.
  130. """
  131. def __init__(self, param1: int, param2: str):
  132. #: Public attribute is documented here.
  133. self.attr1 = param1
  134. #: Public attribute is documented here.
  135. self.attr2 = param2
  136. @property
  137. def attr3(self) -> str:
  138. """Public property of the class.
  139. Properties created with the @property decorator
  140. should be documented here.
  141. """
  142. return "hello"
  143. def increment_attr1(self) -> None:
  144. """Class methods are similar to regular functions.
  145. See above about how to document functions.
  146. """
  147. self.attr1 = self.attr1 + 1
  148. See :ref:`this <writing-code-snippets_ref>` for more details about how to write code snippets in docstrings.
  149. Lint and Formatting
  150. ~~~~~~~~~~~~~~~~~~~
  151. We also have tests for code formatting and linting that need to pass before merge.
  152. * For Python formatting, install the `required dependencies <https://github.com/ray-project/ray/blob/master/python/requirements_linters.txt>`_ first with:
  153. .. code-block:: shell
  154. pip install -r python/requirements_linters.txt
  155. * If developing for C++, you will need `clang-format <https://www.kernel.org/doc/html/latest/process/clang-format.html>`_ version ``12`` (download this version of Clang from `here <http://releases.llvm.org/download.html>`_)
  156. You can run the following locally:
  157. .. code-block:: shell
  158. scripts/format.sh
  159. An output like the following indicates failure:
  160. .. code-block:: shell
  161. WARNING: clang-format is not installed! # This is harmless
  162. From https://github.com/ray-project/ray
  163. * branch master -> FETCH_HEAD
  164. python/ray/util/sgd/tf/tf_runner.py:4:1: F401 'numpy as np' imported but unused # Below is the failure
  165. In addition, there are other formatting and semantic checkers for components like the following (not included in ``scripts/format.sh``):
  166. * Python README format:
  167. .. code-block:: shell
  168. cd python
  169. python setup.py check --restructuredtext --strict --metadata
  170. * Python & Docs banned words check
  171. .. code-block:: shell
  172. ./ci/lint/check-banned-words.sh
  173. * Bazel format:
  174. .. code-block:: shell
  175. ./ci/lint/bazel-format.sh
  176. * clang-tidy for C++ lint, requires ``clang`` and ``clang-tidy`` version 12 to be installed:
  177. .. code-block:: shell
  178. ./ci/lint/check-git-clang-tidy-output.sh
  179. You can run ``setup_hooks.sh`` to create a git hook that will run the linter before you push your changes.
  180. Understanding CI test jobs
  181. --------------------------
  182. The Ray project automatically runs continuous integration (CI) tests once a PR
  183. is opened using `Buildkite <https://buildkite.com/ray-project/>`_ with
  184. multiple CI test jobs.
  185. The `CI`_ test folder contains all integration test scripts and they
  186. invoke other test scripts via ``pytest``, ``bazel``-based test or other bash
  187. scripts. Some of the examples include:
  188. * Raylet integration tests commands:
  189. * ``bazel test //:core_worker_test``
  190. * Bazel test command:
  191. * ``bazel test --build_tests_only //:all``
  192. * Ray serving test commands:
  193. * ``pytest python/ray/serve/tests``
  194. * ``python python/ray/serve/examples/echo_full.py``
  195. If a CI build exception doesn't appear to be related to your change,
  196. please visit `this link <https://flakey-tests.ray.io/>`_ to
  197. check recent tests known to be flaky.
  198. .. _`CI`: https://github.com/ray-project/ray/tree/master/ci
  199. API compatibility style guide
  200. -----------------------------
  201. Ray provides stability guarantees for its public APIs in Ray core and libraries, which are described in the :ref:`API Stability guide <api-stability>`.
  202. It's hard to fully capture the semantics of API compatibility into a single annotation (for example, public APIs may have "experimental" arguments). For more granular stability contracts, those can be noted in the pydoc (e.g., "the ``random_shuffle`` option is experimental"). When possible, experimental arguments should also be prefixed by underscores in Python (e.g., `_owner=`).
  203. **Other recommendations**:
  204. In Python APIs, consider forcing the use of kwargs instead of positional arguments (with the ``*`` operator). Kwargs are easier to keep backwards compatible than positional arguments, e.g. imagine if you needed to deprecate "opt1" below, it's easier with forced kwargs:
  205. .. code-block:: python
  206. def foo_bar(file, *, opt1=x, opt2=y)
  207. pass
  208. For callback APIs, consider adding a ``**kwargs`` placeholder as a "forward compatibility placeholder" in case more args need to be passed to the callback in the future, e.g.:
  209. .. code-block:: python
  210. def tune_user_callback(model, score, **future_kwargs):
  211. pass
  212. Becoming a Reviewer
  213. -------------------
  214. We identify reviewers from active contributors. Reviewers are individuals who
  215. not only actively contribute to the project and are also willing
  216. to participate in the code review of new contributions.
  217. A pull request to the project has to be reviewed by at least one reviewer in order to be merged.
  218. There is currently no formal process, but active contributors to Ray will be
  219. solicited by current reviewers.
  220. More Resources for Getting Involved
  221. -----------------------------------
  222. .. include:: ../ray-contribute/involvement.rst
  223. .. note::
  224. These tips are based off of the TVM `contributor guide <https://github.com/dmlc/tvm>`__.