Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Warning/Error messages when using build #1034

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions testing/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pprint
import subprocess
import sys
import textwrap

from dataclasses import replace
from importlib.metadata import EntryPoint
Expand All @@ -17,6 +18,8 @@
from setuptools_scm.integration import data_from_mime
from setuptools_scm.version import meta

from .wd_wrapper import WorkDir


def test_data_from_mime_ignores_body() -> None:
assert data_from_mime(
Expand Down Expand Up @@ -97,6 +100,52 @@ def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
assert res is not None


def test_fallback_message(wd: WorkDir, monkeypatch: pytest.MonkeyPatch) -> None:
"""Check that no warning/error messages are normally outputted"""
# setup a basic project that would not trigger any (other) warning/errors
pyproject = """\
LecrisUT marked this conversation as resolved.
Show resolved Hide resolved
[build-system]
requires = ["setuptools", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[project]
name = "example"
dynamic = ["version"]

[tool.setuptools_scm]
"""
git_archival = """\
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
"""
wd.write("pyproject.toml", textwrap.dedent(pyproject))
wd.write(".git_archival.txt", textwrap.dedent(git_archival))
wd.write(".gitattributes", ".git_archival.txt export-subst")
wd.write("README.md", "")
wd("git init")
wd("git config user.email user@host")
wd("git config user.name user")
wd.add_command = "git add ."
wd.commit_command = "git commit -m test-{reason}"
wd.add_and_commit()
wd("git tag v0.1.0")
version = wd.get_version()
assert version == "0.1.0"

# Run build and check messages
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
# with caplog.at_level(logging.WARN):
res_build = subprocess.run(
[sys.executable, "-m", "build", "-nx"],
cwd=wd.cwd,
capture_output=True,
)
assert res_build.returncode == 0
# Maybe there is a cleaner way to use caplog?
assert not res_build.stderr
Comment on lines +139 to +146
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to run and check this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hack that might be reasonable would be a fake object directly passed to the integration function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean instead of python3 -m build? I don't think that will end up well because what we want to test here is how build creates the sdist and from the sdist creates the wheel, and in both steps setuptools-scm is called with different "sources".

Another option I was thinking is calling build.__main__.main directly? Then all of the context should be preserved and the caplog should in principle work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i remember, build has to start sub-processes for a build
so currently have no idea for a clean solution



def test_entrypoints_load() -> None:
d = distribution("setuptools-scm")

Expand Down
Loading