Skip to content

Keep build backend output off metadata stdout#2309

Open
marko1olo wants to merge 1 commit into
pypa:masterfrom
marko1olo:fix-build-backend-stdout-metadata
Open

Keep build backend output off metadata stdout#2309
marko1olo wants to merge 1 commit into
pypa:masterfrom
marko1olo:fix-build-backend-stdout-metadata

Conversation

@marko1olo

Copy link
Copy Markdown

Fixes #2069.

When Hatch reads metadata through a non-Hatchling build backend, the PEP 517 hook runs in a child process. Some backends, notably setuptools/setuptools-scm, print build progress such as running egg_info to stdout while preparing metadata. That output was forwarded directly to Hatch's stdout before Hatch printed the requested version/metadata, which makes commands like hatch version hard to use from scripts.

This redirects backend stdout to stderr for the standard frontend runner. Hatch still preserves backend diagnostics, but stdout remains reserved for Hatch's actual command result.

I verified this with a setuptools-scm sample project: after this change, hatch version stdout is only 1.2.3, while running egg_info remains visible on stderr.

Tests run:

  • python -m ruff check src/hatch/project/frontend/scripts/standard.py tests/project/test_frontend.py
  • python -m ruff format --check src/hatch/project/frontend/scripts/standard.py tests/project/test_frontend.py
  • python -m pytest tests/project/test_frontend.py tests/cli/version/test_version.py::test_other_backend_show tests/cli/project/test_metadata.py::test_other_backend -q
  • python scripts/validate_history.py
  • git diff --check

@marko1olo

Copy link
Copy Markdown
Author

Local verification on b081f534:

  • PYTHONPATH=C:\hades\oss\hatch\src;C:\hades\oss\hatch\backend\src C:\hades\oss\.venvs\hatch\Scripts\python.exe -m pytest tests\project\test_frontend.py::TestPrepareMetadata -q -> 5 passed
  • git diff --check origin/master..HEAD passed

Note: I had to set PYTHONPATH explicitly because this shared local venv was still pointing at another Hatch checkout from a different branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hatch version doesn't work on a setuptools-scm project unless hatch-vcs is installed

1 participant