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

pantsbuild / pants / 18517631058

15 Oct 2025 04:18AM UTC coverage: 69.207% (-11.1%) from 80.267%
18517631058

Pull #22745

github

web-flow
Merge 642a76ca1 into 99919310e
Pull Request #22745: [windows] Add windows support in the stdio crate.

53815 of 77759 relevant lines covered (69.21%)

2.42 hits per line

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

52.73
/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✔
36
    wheels = os.listdir(dist_dir)
2✔
37
    assert len(wheels) == 1
2✔
38
    wheel = os.path.join(dist_dir, wheels[0])
2✔
39

40
    with TemporaryDirectory() as venvdir:
2✔
41
        venv.create(venvdir, with_pip=True, clear=True, symlinks=True)
2✔
42
        subprocess.run([os.path.join(venvdir, "bin", "pip"), "install", wheel], check=True)
2✔
43
        proc = subprocess.run(
2✔
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
        )
52
        assert proc.stdout == b"Professor Native\n"
2✔
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]:
×
59
        d = hashlib.sha256(Path(path).read_bytes()).hexdigest()
×
60
        return path, d
×
61

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

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

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

82

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

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