@@ -538,36 +538,30 @@ which takes the following parameters:
538538
539539.. _onbuild :
540540
541- The ``[tool.versioningit.onbuild] `` Subtable
542- --------------------------------------------
543-
544- .. attention ::
545-
546- Currently, the ``onbuild `` step is not supported when using
547- ``versioningit `` with Hatch. See `issue #54 `__ for more information.
548-
549- __ https://github.com/jwodder/versioningit/issues/54
541+ Enabling & Configuring the ``onbuild `` Step
542+ -------------------------------------------
550543
551544.. versionadded :: 1.1.0
552545
553- .. versionadded :: 2.2.0
546+ ``versioningit `` provides custom setuptools and Hatch hooks for enabling an
547+ optional feature (called the "``onbuild `` step") in which your project's
548+ version and/or other fields are inserted into a file in sdists & wheels at
549+ build time while leaving your local project directory alone.
554550
555- ``sdist `` and ``build_py `` classes added for use in :file: `setup.cfg ` and
556- :file: `pyproject.toml `
551+ The steps for enabling the ``onbuild `` step differ depending on whether you're
552+ using setuptools or Hatch as your build backend. The configuration options for
553+ the step are the same between the backends, but where you put the configuration
554+ and how you tell the backend to enable the hooks differs.
557555
558- The ``onbuild `` subtable configures an optional feature, inserting the project
559- version and/or other fields into built project trees when building an sdist or
560- wheel. Specifically, this feature allows you to create sdists & wheels in
561- which some file has been modified to contain the line ``__version__ = "<project
562- version>" `` or similar while leaving your repository alone.
556+ Using ``onbuild `` with setuptools
557+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
563558
564- Enabling ``onbuild ``
565- ~~~~~~~~~~~~~~~~~~~~
566-
567- In order to use this feature, in addition to filling out the subtable, you must
568- configure setuptools to use ``versioningit ``'s custom command classes. How to
569- do this depends on what file you've placed your project's setuptools
570- configuration in.
559+ There are two steps to enabling the ``onbuild `` step with setuptools. First,
560+ add a ``[tool.versioningit.onbuild] `` table to your :file: `pyproject.toml `
561+ containing your desired configuration for the step (`see below
562+ <onbuild_opts_> `_). Second, you need to tell setuptools to use
563+ ``versioningit ``'s custom command classes. How to do this depends on what file
564+ you've placed your project's setuptools configuration in.
571565
572566- If you're configuring setuptools via :file: `setup.cfg `, you can simply add
573567 the following field to its ``[options] `` table:
@@ -611,8 +605,44 @@ may have to manually modify or subclass your command classes and add a call to
611605`run_onbuild() ` at the appropriate location; see the function's documentation
612606for more information, but you'll largely be on your own at this point.
613607
614- Configuring ``onbuild ``
615- ~~~~~~~~~~~~~~~~~~~~~~~
608+ .. versionadded :: 2.2.0
609+
610+ ``sdist `` and ``build_py `` classes added for use in :file: `setup.cfg ` and
611+ :file: `pyproject.toml `
612+
613+ Using ``onbuild `` with Hatch
614+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
615+
616+ .. versionadded :: 3.0.0
617+
618+ Support for using the ``onbuild `` step with Hatch
619+
620+ In order to enable & configure the ``onbuild `` step when using ``versioningit ``
621+ with Hatch, simply place all of your desired configuration for the step under a
622+ ``[tool.hatch.build.hooks.versioningit-onbuild] `` table. Do not use the
623+ ``[tool.versioningit.onbuild] `` table with Hatch; it will be ignored, and its
624+ presence will generate a warning.
625+
626+ .. note ::
627+
628+ The ``versioningit-onbuild `` build hook is only usable when also using
629+ ``versioningit `` as a Hatch version source. Trying to use the build hook
630+ with a different version source will result in an error.
631+
632+ .. note ::
633+
634+ The ``versioningit-onbuild `` build hook is only supported when building an
635+ sdist or wheel. Using other Hatch builders (such as `the application
636+ builder `__) with ``versioningit-onbuild `` is not supported or endorsed in
637+ any way.
638+
639+ __ https://hatch.pypa.io/latest/plugins/builder/app/
640+
641+
642+ .. _onbuild_opts :
643+
644+ ``onbuild `` Configuration Options
645+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
616646
617647``versioningit `` provides one ``onbuild `` method, ``"replace-version" `` (the
618648default). It scans a given file for a line matching a given regex and inserts
0 commit comments