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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

38.18
/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
1✔
5

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

15
import pytest
1✔
16

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

20

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

26
    pants_run = run_pants(
1✔
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()
1✔
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:
1✔
56
    """Tests that the given sources can be `package`d reproducibly."""
57

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

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

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

UNCOV
79
    assert len(one) == expected_artifact_count
×
UNCOV
80
    assert one == two
×
81

82

83
def test_deterministic_package_data() -> None:
1✔
UNCOV
84
    package_determinism(
×
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:
1✔
UNCOV
117
    dist_dir = "dist"
×
UNCOV
118
    output_path = os.path.join("nondefault", "output_dir")
×
UNCOV
119
    files = {
×
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
    }
UNCOV
134
    pyver = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
×
135

UNCOV
136
    with setup_tmpdir(files) as source_dir:
×
UNCOV
137
        pants_run = run_pants(
×
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
        )
UNCOV
146
        pants_run.assert_success()
×
UNCOV
147
        dist_output_path = os.path.join(dist_dir, output_path)
×
UNCOV
148
        dist_entries = os.listdir(os.path.join(dist_dir, output_path))
×
UNCOV
149
        assert len(dist_entries) == 2
×
UNCOV
150
        for entry in dist_entries:
×
UNCOV
151
            assert os.path.isfile(os.path.join(dist_output_path, entry))
×
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