The initial version of setuptools is the one copied from the base Python site-packages by venv when it creates the environment, which the steps above uninstall. setuptools is then downloaded and installed in the isolated PEP 517 build environment by pip, because it is listed in pyproject.toml, or assumed by default if one is not present, to be a build-time dependency of the package you are installing, just like any other build backend that the package you’re trying to install might use instead–flit, poetry, etc. Then, this isolated set of build-time dependencies is used to build and install the package you’re requesting in your own virtual environment.
The prepare-metadata-for-build-wheel PEP 517 hook runs:
Per PEP 621, which you linked above, the above can be represented as
[project.scripts]
package = "package.command:cli"
in the pyproject.toml, as can the various other options, either metadata under the [project] table or tool-specific config under the [tool] table.
Most other build backends (flit, pdm, hatch, etc) support this already, and support for all this was just added to Setuptools and should be released soon:
However, a setup.py has not been required for some time, unless you want to retain support for legacy pre-PEP 517 builds. Instead, you can, and should, specify your config declaratively in setup.cfg, and only retain a stub setup.py if you need compatibility for legacy tooling. See, also: