|
20 | 20 | _check_wheel_package_path, |
21 | 21 | _get_wheel_packages, |
22 | 22 | _create_dist_info, |
| 23 | + _write_entry_points, |
23 | 24 | _build_wheel_with_tags, |
24 | 25 | _copy_license_files_from_paths, |
25 | 26 | _validate_version_config, |
@@ -358,6 +359,56 @@ def test_prepare_metadata_dynamic_version_from_file(tmp_path, monkeypatch): |
358 | 359 | assert "Version: 0.5.0" in (tmp_path / "meta" / name / "METADATA").read_text(encoding="utf-8") |
359 | 360 |
|
360 | 361 |
|
| 362 | +def test_write_entry_points_omits_file_when_no_entries(tmp_path): |
| 363 | + dist_info = tmp_path / "pkg-1.0.0.dist-info" |
| 364 | + dist_info.mkdir() |
| 365 | + _write_entry_points(dist_info, {"name": "pkg", "version": "1.0.0"}, tmp_path) |
| 366 | + assert not (dist_info / "entry_points.txt").exists() |
| 367 | + |
| 368 | + |
| 369 | +def test_write_entry_points_emits_all_section_kinds(tmp_path): |
| 370 | + """scripts -> [console_scripts], gui-scripts -> [gui_scripts], |
| 371 | + entry-points."group" -> [group], all coexisting in the same file.""" |
| 372 | + dist_info = tmp_path / "pkg-1.0.0.dist-info" |
| 373 | + dist_info.mkdir() |
| 374 | + metadata = { |
| 375 | + "name": "pkg", |
| 376 | + "version": "1.0.0", |
| 377 | + "scripts": {"mytool": "pkg.cli:main"}, |
| 378 | + "gui-scripts": {"mygui": "pkg.gui:run"}, |
| 379 | + "entry-points": {"rasterio.rio_commands": {"info": "pkg.info:info"}}, |
| 380 | + } |
| 381 | + _write_entry_points(dist_info, metadata, tmp_path) |
| 382 | + content = (dist_info / "entry_points.txt").read_text(encoding="utf-8") |
| 383 | + assert "[console_scripts]\nmytool = pkg.cli:main" in content |
| 384 | + assert "[gui_scripts]\nmygui = pkg.gui:run" in content |
| 385 | + assert "[rasterio.rio_commands]\ninfo = pkg.info:info" in content |
| 386 | + |
| 387 | + |
| 388 | +def test_write_entry_points_reserved_group_in_entry_points_raises(tmp_path): |
| 389 | + """Reserved group ('console_scripts') under [project.entry-points] is forbidden by PEP 621.""" |
| 390 | + dist_info = tmp_path / "pkg-1.0.0.dist-info" |
| 391 | + dist_info.mkdir() |
| 392 | + metadata = { |
| 393 | + "name": "pkg", |
| 394 | + "version": "1.0.0", |
| 395 | + "scripts": {"cli": "pkg.cli:main"}, |
| 396 | + "entry-points": {"console_scripts": {"other": "pkg.cli:other"}}, |
| 397 | + } |
| 398 | + with pytest.raises(Exception): |
| 399 | + _write_entry_points(dist_info, metadata, tmp_path) |
| 400 | + |
| 401 | + |
| 402 | +def test_create_dist_info_writes_entry_points_when_scripts_declared(tmp_path): |
| 403 | + """End-to-end: _create_dist_info emits entry_points.txt alongside METADATA.""" |
| 404 | + staging = tmp_path / "staging" |
| 405 | + staging.mkdir() |
| 406 | + metadata = {"name": "pkg", "version": "1.0.0", "scripts": {"mytool": "pkg.cli:main"}} |
| 407 | + dist_info = _create_dist_info(staging, metadata, tmp_path) |
| 408 | + assert (dist_info / "METADATA").is_file() |
| 409 | + assert (dist_info / "entry_points.txt").is_file() |
| 410 | + |
| 411 | + |
361 | 412 | def test_prepare_metadata_with_license_file(tmp_path, monkeypatch): |
362 | 413 | """License file declared in pyproject.toml is copied into .dist-info/licenses/.""" |
363 | 414 | (tmp_path / "pyproject.toml").write_text("""\ |
|
0 commit comments