extension_create.rst 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. .. _extensions_create:
  2. Create your own extension
  3. -------------------------
  4. If your use case is not covered by DataLad's built-in functionality or by the
  5. variety of `available DataLad extensions <https://pypi.org/search/?q=datalad>`_,
  6. DataLad provides a mechanism for extending particular functionality or for providing
  7. entire command suites via the `DataLad extension template <https://github.com/datalad/datalad-extension-template>`_.
  8. Since DataLad extensions are proper Python packages, there can be a significant
  9. amount of boilerplate code involved in the creation of a new extension. The
  10. extension template removes this overhead from the developer by providing a
  11. standard setup for Python packaging, test suite registration, and documentation.
  12. It also contains a demo command suite that is automatically exposed via DataLad's
  13. standard command line and Python API.
  14. In this section, we provide an overview of the main content of the extension template,
  15. as well the steps to follow when creating your own extension from the template.
  16. The DataLad extension template
  17. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  18. Apart from some standard git-, GitHub, versioning-, and Python packaging-specific
  19. files, the extension template has the following core content:
  20. - ``setup.cfg``: which contains the main metadata for the extension and
  21. provides the means to specify package requirements and entry points for
  22. command and test suites.
  23. - ``datalad_helloworld/``: which contains a basic implementation of an
  24. extension command suite (in the template: ``hello_cmd``) and demonstrates
  25. how extension command classes should inherit from DataLad classes in order
  26. for them to be exposed via the DataLad command line and Python API.
  27. - ``docs/``: which contains a basic implementation of `Sphinx <https://www.sphinx-doc.org>`_
  28. for document generation.
  29. - ``.appveyor.yml``: which contains the setup for continuous integration
  30. with `Appveyor <https://www.appveyor.com>`_.
  31. - ``.codeclimate.yml``: which contains the setup for automated code review
  32. for test coverage, maintainability and more with `Code Climate <https://codeclimate.com>`_
  33. - ``requirements-devel.txt``: which lists the requirements for a pip-based
  34. development environment installation
  35. Using the extension template
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. To develop your own extension, you can follow these steps to adjust the template
  38. according to your own specifications:
  39. 1. **Create your extension repository** `from the DataLad extension template <https://github.com/datalad/datalad-extension-template/generate>`_
  40. 2. **Add your extension name**, which can be done by looking through the
  41. source code and replacing ``datalad_helloworld`` with ``datalad_<newname>``
  42. (hint: ``git grep datalad_helloworld`` should find all spots).
  43. 3. **Replace the example command implementation with your own**:
  44. - First replace the ``HelloWorld`` class with your own class implementation.
  45. - Then adjust the ``command_suite`` in ``datalad_helloworld/__init__.py`` by replacing the reference to ``HelloWorld`` with a reference to your newly implemented class.
  46. 4. **Allow automatic testing of extension installation** by replacing
  47. ``hello_cmd`` in ``datalad_helloworld/tests/test_register.py`` with
  48. the name of the new command.
  49. 5. **Update your documentation** in ``docs/source/index.rst`` by following
  50. the guidelines on documentation building, testing, and publishing provided in
  51. ``docs/README.md``.
  52. 6. **Replace the main README** content of your repository with a description of your
  53. extension, including standard information such as an overview, installation
  54. instructions, documentation, and contributing guidelines.
  55. 7. **Update** ``setup.cfg`` with appropriate metadata on the new extension,
  56. including the Python version (``python_equires``), package requirements
  57. (``install_requires``) and entry points for command or testing suites
  58. (``datalad.extensions``)
  59. 8. **Publish your extension**, e.g. on GitHub.
  60. 9. **Activate/link external services**, such as Appveyor for continuous
  61. integration, or `Read The Docs <https://readthedocs.org>`_ for documentation.
  62. 10. If you've written an extension that provides important functionality for you or your community, consider **registering your extension** at `github.com/datalad/datalad-extensions <https://github.com/datalad/datalad-extensions>`_ in order to test your extension's functionality against future DataLad releases and ensure interoperability across software versions. Ideally, `open an issue <https://github.com/datalad/datalad-extensions/issues/new>`_ to get in touch with the DataLad developers about this.