@@ -54,6 +54,9 @@ Please ensure that your code is well-formatted, documented and passes all the te
5454 Large pull requests are difficult to review and may take a long time to merge.
5555
5656
57+ More details on the code style and testing can be found in the `Coding Style `_ and `Unit Testing `_ sections.
58+
59+
5760Contributing Documentation
5861--------------------------
5962
@@ -237,6 +240,62 @@ For documentation, we adopt the `Google Style Guide <https://sphinxcontrib-napol
237240for docstrings. We use `Sphinx <https://www.sphinx-doc.org/en/master/ >`__ for generating the documentation.
238241Please make sure that your code is well-documented and follows the guidelines.
239242
243+ Code Structure
244+ ^^^^^^^^^^^^^^
245+
246+ We follow a specific structure for the codebase. This helps in maintaining the codebase and makes it easier to
247+ understand.
248+
249+ In a Python file, we follow the following structure:
250+
251+ .. code :: python
252+
253+ # Imports: These are sorted by the pre-commit hooks.
254+ # Constants
255+ # Functions (public)
256+ # Classes (public)
257+ # _Functions (private)
258+ # _Classes (private)
259+
260+ Imports are sorted by the pre-commit hooks. Unless there is a good reason to do otherwise, please do not
261+ import the modules inside functions or classes. To deal with circular imports, we use the
262+ :obj: `typing.TYPE_CHECKING ` variable. Please refer to the `Circular Imports `_ section for more details.
263+
264+ Python does not have a concept of private and public classes and functions. However, we follow the
265+ convention of prefixing the private functions and classes with an underscore.
266+ The public functions and classes are the ones that are intended to be used by the users. The private
267+ functions and classes are the ones that are intended to be used internally in that file.
268+ Irrespective of the public or private nature of the functions and classes, we follow the Style Guide
269+ for the code and make sure that the code and documentation are consistent.
270+
271+ Similarly, within Python classes, we follow the following structure:
272+
273+ .. code :: python
274+
275+ # Constants
276+ # Class variables (public or private): Must have the type hint ClassVar[type]
277+ # Dunder methods: __init__, __del__
278+ # Representation: __repr__, __str__
279+ # Properties: @property
280+ # Instance methods (public)
281+ # Class methods (public)
282+ # Static methods (public)
283+ # _Instance methods (private)
284+ # _Class methods (private)
285+ # _Static methods (private)
286+
287+ The rule of thumb is that the functions within the classes are ordered in the way a user would
288+ expect to use them. For instance, if the class contains the method :meth: `initialize `, :meth: `reset `,
289+ :meth: `update `, and :meth: `close `, then they should be listed in the order of their usage.
290+ The same applies for private functions in the class. Their order is based on the order of call inside the
291+ class.
292+
293+ .. dropdown :: Code skeleton
294+ :icon: code
295+
296+ .. literalinclude :: snippets/code_skeleton.py
297+ :language: python
298+
240299Circular Imports
241300^^^^^^^^^^^^^^^^
242301
@@ -414,15 +473,47 @@ We summarize the key points below:
414473
415474
416475Unit Testing
417- ^^^^^^^^^^^^
476+ ------------
418477
419478We use `pytest <https://docs.pytest.org >`__ for unit testing.
420479Good tests not only cover the basic functionality of the code but also the edge cases.
421480They should be able to catch regressions and ensure that the code is working as expected.
422481Please make sure that you add tests for your changes.
423482
483+ .. tab-set ::
484+ :sync-group: os
485+
486+ .. tab-item :: :icon:`fa-brands fa-linux` Linux
487+ :sync: linux
488+
489+ .. code-block :: bash
490+
491+ # Run all tests
492+ ./isaaclab.sh --test # or "./isaaclab.sh -t"
493+
494+ # Run all tests in a particular file
495+ ./isaaclab.sh -p -m pytest source/isaaclab/test/deps/test_torch.py
496+
497+ # Run a particular test
498+ ./isaaclab.sh -p -m pytest source/isaaclab/test/deps/test_torch.py::test_array_slicing
499+
500+ .. tab-item :: :icon:`fa-brands fa-windows` Windows
501+ :sync: windows
502+
503+ .. code-block :: bash
504+
505+ # Run all tests
506+ isaaclab.bat --test # or "isaaclab.bat -t"
507+
508+ # Run all tests in a particular file
509+ isaaclab.bat -p -m pytest source/isaaclab/test/deps/test_torch.py
510+
511+ # Run a particular test
512+ isaaclab.bat -p -m pytest source/isaaclab/test/deps/test_torch.py::test_array_slicing
513+
514+
424515 Tools
425- ^^^^^
516+ -----
426517
427518We use the following tools for maintaining code quality:
428519
@@ -435,6 +526,19 @@ Please check `here <https://pre-commit.com/#install>`__ for instructions
435526to set these up. To run over the entire repository, please execute the
436527following command in the terminal:
437528
438- .. code :: bash
529+ .. tab-set ::
530+ :sync-group: os
531+
532+ .. tab-item :: :icon:`fa-brands fa-linux` Linux
533+ :sync: linux
534+
535+ .. code-block :: bash
536+
537+ ./isaaclab.sh --format # or "./isaaclab.sh -f"
538+
539+ .. tab-item :: :icon:`fa-brands fa-windows` Windows
540+ :sync: windows
541+
542+ .. code-block :: bash
439543
440- ./ isaaclab.sh --format # or "./ isaaclab.sh -f"
544+ isaaclab.bat --format # or "isaaclab.bat -f"
0 commit comments