• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19068377358

04 Nov 2025 12:18PM UTC coverage: 92.46% (+12.2%) from 80.3%
19068377358

Pull #22816

github

web-flow
Merge a242f1805 into 89462b7ef
Pull Request #22816: Update Pants internal Python to 3.14

13 of 14 new or added lines in 12 files covered. (92.86%)

244 existing lines in 13 files now uncovered.

89544 of 96846 relevant lines covered (92.46%)

3.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.45
/src/python/pants/backend/python/goals/package_dists_integration_test.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
import hashlib
2✔
7
import os
2✔
8
import subprocess
2✔
9
import sys
2✔
10
import venv
2✔
11
from pathlib import Path
2✔
12
from tempfile import TemporaryDirectory
2✔
13
from textwrap import dedent
2✔
14

15
import pytest
2✔
16

17
from pants.testutil.pants_integration_test import run_pants, setup_tmpdir
2✔
18
from pants.util.dirutil import safe_rmtree
2✔
19

20

21
@pytest.mark.platform_specific_behavior
2✔
22
def test_native_code() -> None:
2✔
23
    dist_dir = "dist"
2✔
24
    pyver = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
2✔
25

26
    pants_run = run_pants(
2✔
27
        [
28
            "--backend-packages=pants.backend.python",
29
            f"--python-interpreter-constraints=['=={pyver}']",
30
            "package",
31
            "testprojects/src/python/native:dist",
32
        ],
33
        extra_env={"PYTHON": sys.executable},
34
    )
35
    pants_run.assert_success()
2✔
UNCOV
36
    wheels = os.listdir(dist_dir)
×
UNCOV
37
    assert len(wheels) == 1
×
UNCOV
38
    wheel = os.path.join(dist_dir, wheels[0])
×
39

UNCOV
40
    with TemporaryDirectory() as venvdir:
×
UNCOV
41
        venv.create(venvdir, with_pip=True, clear=True, symlinks=True)
×
UNCOV
42
        subprocess.run([os.path.join(venvdir, "bin", "pip"), "install", wheel], check=True)
×
UNCOV
43
        proc = subprocess.run(
×
44
            [
45
                os.path.join(venvdir, "bin", "python"),
46
                "-c",
47
                "from native import name; print(name.get_name())",
48
            ],
49
            check=True,
50
            capture_output=True,
51
        )
UNCOV
52
        assert proc.stdout == b"Professor Native\n"
×
53

54

55
def package_determinism(expected_artifact_count: int, files: dict[str, str]) -> None:
2✔
56
    """Tests that the given sources can be `package`d reproducibly."""
57

58
    def digest(path: str) -> tuple[str, str]:
1✔
59
        d = hashlib.sha256(Path(path).read_bytes()).hexdigest()
1✔
60
        return path, d
1✔
61

62
    def run_and_digest(address: str) -> dict[str, str]:
1✔
63
        safe_rmtree("dist")
1✔
64
        pants_run = run_pants(
1✔
65
            [
66
                "--backend-packages=pants.backend.python",
67
                "--no-pantsd",
68
                "package",
69
                address,
70
            ],
71
        )
72
        pants_run.assert_success()
1✔
73
        return dict(digest(os.path.join("dist", f)) for f in os.listdir("dist"))
1✔
74

75
    with setup_tmpdir(files) as source_dir:
1✔
76
        one = run_and_digest(f"{source_dir}:dist")
1✔
77
        two = run_and_digest(f"{source_dir}:dist")
1✔
78

79
    assert len(one) == expected_artifact_count
1✔
80
    assert one == two
1✔
81

82

83
def test_deterministic_package_data() -> None:
2✔
84
    package_determinism(
1✔
85
        2,
86
        {
87
            "BUILD": dedent(
88
                """\
89
                python_distribution(
90
                    name="dist",
91
                    dependencies=["{tmpdir}/a", "{tmpdir}/b"],
92
                    provides=python_artifact(name="det", version="2.3.4"),
93
                )
94
                """
95
            ),
96
            "a/BUILD": dedent(
97
                """\
98
                python_sources(dependencies=[":resources"])
99
                resources(name="resources", sources=["*.txt"])
100
                """
101
            ),
102
            "a/source.py": "",
103
            "a/a.txt": "",
104
            "b/BUILD": dedent(
105
                """\
106
                python_sources(dependencies=[":resources"])
107
                resources(name="resources", sources=["*.txt"])
108
                """
109
            ),
110
            "b/source.py": "",
111
            "b/b.txt": "",
112
        },
113
    )
114

115

116
def test_output_path() -> None:
2✔
117
    dist_dir = "dist"
1✔
118
    output_path = os.path.join("nondefault", "output_dir")
1✔
119
    files = {
1✔
120
        "foo/BUILD": dedent(
121
            f"""\
122
            python_sources()
123

124
            python_distribution(
125
                name="dist",
126
                dependencies=[":foo"],
127
                provides=python_artifact(name="foo", version="2.3.4"),
128
                output_path="{output_path}"
129
            )
130
            """
131
        ),
132
        "foo/source.py": "",
133
    }
134
    pyver = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
1✔
135

136
    with setup_tmpdir(files) as source_dir:
1✔
137
        pants_run = run_pants(
1✔
138
            [
139
                "--backend-packages=pants.backend.python",
140
                f"--python-interpreter-constraints=['=={pyver}']",
141
                "package",
142
                f"{source_dir}/foo:dist",
143
            ],
144
            extra_env={"PYTHON": sys.executable},
145
        )
146
        pants_run.assert_success()
1✔
147
        dist_output_path = os.path.join(dist_dir, output_path)
1✔
148
        dist_entries = os.listdir(os.path.join(dist_dir, output_path))
1✔
149
        assert len(dist_entries) == 2
1✔
150
        for entry in dist_entries:
1✔
151
            assert os.path.isfile(os.path.join(dist_output_path, entry))
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc