|
3 | 3 |
|
4 | 4 | from __future__ import absolute_import, print_function |
5 | 5 |
|
| 6 | +import filecmp |
6 | 7 | import json |
7 | 8 | import os.path |
8 | 9 | import re |
9 | 10 | import sys |
10 | 11 | from collections import defaultdict |
11 | 12 | from textwrap import dedent |
12 | 13 |
|
| 14 | +import colors # vendor:skip |
13 | 15 | import pytest |
14 | 16 |
|
15 | | -from pex.common import safe_copy, safe_mkdir, safe_open, safe_rmtree |
| 17 | +from pex.common import safe_copy, safe_mkdir, safe_open, safe_rmtree, touch |
16 | 18 | from pex.dist_metadata import ProjectNameAndVersion |
17 | 19 | from pex.pep_425 import CompatibilityTags |
18 | 20 | from pex.pep_503 import ProjectName |
@@ -299,3 +301,115 @@ def create_multiplatform_pex(*requirements): |
299 | 301 | ), |
300 | 302 | re_flags=re.DOTALL, |
301 | 303 | ) |
| 304 | + |
| 305 | + |
| 306 | +@mark_skip_if_uv_not_supported |
| 307 | +def test_uv_cache_json_ignored(tmpdir): |
| 308 | + # type: (Tempdir) -> None |
| 309 | + |
| 310 | + project = tmpdir.join("project") |
| 311 | + with safe_open(os.path.join(project, "pyproject.toml"), "w") as fp: |
| 312 | + fp.write( |
| 313 | + dedent( |
| 314 | + """\ |
| 315 | + [build-system] |
| 316 | + requires = ["uv_build>=0.13.4,<0.14"] |
| 317 | + build-backend = "uv_build" |
| 318 | +
|
| 319 | + [project] |
| 320 | + name = "blue-moo" |
| 321 | + version = "0.1.0" |
| 322 | +
|
| 323 | + dependencies = [ |
| 324 | + "ansicolors", |
| 325 | + "cowsay<6", |
| 326 | + ] |
| 327 | +
|
| 328 | + [project.scripts] |
| 329 | + blue-moo = "blue_moo:quack" |
| 330 | + """ |
| 331 | + ) |
| 332 | + ) |
| 333 | + with safe_open(os.path.join(project, "src", "blue_moo", "__init__.py"), "w") as fp: |
| 334 | + fp.write( |
| 335 | + dedent( |
| 336 | + """\ |
| 337 | + import sys |
| 338 | +
|
| 339 | + import colors |
| 340 | + import cowsay |
| 341 | +
|
| 342 | +
|
| 343 | + def quack(*message): |
| 344 | + cowsay.tux(colors.cyan(" ".join(message or sys.argv[1:]))) |
| 345 | + """ |
| 346 | + ) |
| 347 | + ) |
| 348 | + |
| 349 | + uv_cache_dir = tmpdir.join("uv-cache") |
| 350 | + |
| 351 | + def create_uv_venv(): |
| 352 | + # type: () -> str |
| 353 | + venv = tmpdir.join("venv") |
| 354 | + subprocess.check_call( |
| 355 | + args=[ |
| 356 | + "uv", |
| 357 | + "--cache-dir", |
| 358 | + uv_cache_dir, |
| 359 | + "venv", |
| 360 | + "--python", |
| 361 | + "{impl}{major}.{minor}".format( |
| 362 | + impl="pypy" if IS_PYPY else "python", |
| 363 | + major=sys.version_info[0], |
| 364 | + minor=sys.version_info[1], |
| 365 | + ), |
| 366 | + venv, |
| 367 | + ] |
| 368 | + ) |
| 369 | + subprocess.check_call( |
| 370 | + args=["uv", "--cache-dir", uv_cache_dir, "pip", "install", "--python", venv, project] |
| 371 | + ) |
| 372 | + return venv |
| 373 | + |
| 374 | + def build_blue_moo_pex( |
| 375 | + venv, # type: str |
| 376 | + name, # type: str |
| 377 | + ): |
| 378 | + # type: (...) -> str |
| 379 | + pex_root = tmpdir.join("pex-root") |
| 380 | + pex = tmpdir.join(name) |
| 381 | + run_pex_command( |
| 382 | + args=[ |
| 383 | + "--pex-root", |
| 384 | + pex_root, |
| 385 | + "--runtime-pex-root", |
| 386 | + pex_root, |
| 387 | + "--venv-repository", |
| 388 | + venv, |
| 389 | + "-c", |
| 390 | + "blue-moo", |
| 391 | + "-o", |
| 392 | + pex, |
| 393 | + ] |
| 394 | + ).assert_success() |
| 395 | + return pex |
| 396 | + |
| 397 | + venv_dir = create_uv_venv() |
| 398 | + pex1 = build_blue_moo_pex(venv_dir, "first") |
| 399 | + assert "| {message} |".format(message=colors.cyan("Moo?")) in subprocess.check_output( |
| 400 | + args=[sys.executable, pex1, "Moo?"] |
| 401 | + ).decode("utf-8") |
| 402 | + |
| 403 | + safe_rmtree(uv_cache_dir) |
| 404 | + safe_rmtree(venv_dir) |
| 405 | + |
| 406 | + # N.B.: This triggers a change to blue_moo-0.1.0.dist-info/uv_cache.json |
| 407 | + touch(os.path.join(project, "pyproject.toml")) |
| 408 | + |
| 409 | + venv_dir = create_uv_venv() |
| 410 | + pex2 = build_blue_moo_pex(venv_dir, "second") |
| 411 | + assert "| {message} |".format(message=colors.cyan("Moo?")) in subprocess.check_output( |
| 412 | + args=[sys.executable, pex2, "Moo?"] |
| 413 | + ).decode("utf-8") |
| 414 | + |
| 415 | + assert filecmp.cmp(pex1, pex2, shallow=False) |
0 commit comments