Inline dependency-versions syntax (#2122)
* Write docs for inline dependency-versions * Change the `inline` keyword to `packages` for better readability * Implement inline package constraints * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add schema for TOML properties * Change the parsing of the option to parse filenames as-is * Add a unit test for table-parsing of the option * Remove unneeded shlex.quote on the dependency-version test * Tidy-ups, comments, docs fixes * Add test for empty packages option value * Fix empty packages scenario And, remove some optionals to reduce the problem space --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent
f5e502aa88
commit
25f2d3f313
@@ -1,21 +1,55 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from cibuildwheel.util.packaging import DependencyConstraints
|
||||
|
||||
|
||||
def test_defaults():
|
||||
dependency_constraints = DependencyConstraints.with_defaults()
|
||||
def test_defaults(tmp_path: Path) -> None:
|
||||
dependency_constraints = DependencyConstraints.pinned()
|
||||
|
||||
project_root = Path(__file__).parents[1]
|
||||
resources_dir = project_root / "cibuildwheel" / "resources"
|
||||
|
||||
assert dependency_constraints.base_file_path
|
||||
assert dependency_constraints.base_file_path.samefile(resources_dir / "constraints.txt")
|
||||
assert dependency_constraints.get_for_python_version("3.99").samefile(
|
||||
resources_dir / "constraints.txt"
|
||||
|
||||
constraints_file = dependency_constraints.get_for_python_version(
|
||||
version="3.99", tmp_dir=tmp_path
|
||||
)
|
||||
assert dependency_constraints.get_for_python_version("3.9").samefile(
|
||||
resources_dir / "constraints-python39.txt"
|
||||
assert constraints_file
|
||||
assert constraints_file.samefile(resources_dir / "constraints.txt")
|
||||
|
||||
constraints_file = dependency_constraints.get_for_python_version(
|
||||
version="3.9", tmp_dir=tmp_path
|
||||
)
|
||||
assert dependency_constraints.get_for_python_version("3.13").samefile(
|
||||
resources_dir / "constraints-python313.txt"
|
||||
assert constraints_file
|
||||
assert constraints_file.samefile(resources_dir / "constraints-python39.txt")
|
||||
|
||||
constraints_file = dependency_constraints.get_for_python_version(
|
||||
version="3.13", tmp_dir=tmp_path
|
||||
)
|
||||
assert constraints_file
|
||||
assert constraints_file.samefile(resources_dir / "constraints-python313.txt")
|
||||
|
||||
|
||||
def test_inline_packages(tmp_path: Path) -> None:
|
||||
dependency_constraints = DependencyConstraints(
|
||||
base_file_path=None,
|
||||
packages=["foo==1.2.3", "bar==4.5.6"],
|
||||
)
|
||||
|
||||
constraint_file = dependency_constraints.get_for_python_version(version="x.x", tmp_dir=tmp_path)
|
||||
assert constraint_file
|
||||
constraints_file_contents = constraint_file.read_text()
|
||||
|
||||
assert constraints_file_contents == "foo==1.2.3\nbar==4.5.6"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("config_string", ["", "latest", "packages:"])
|
||||
def test_empty_constraints(config_string: str) -> None:
|
||||
dependency_constraints = DependencyConstraints.from_config_string(config_string)
|
||||
|
||||
assert not dependency_constraints.packages
|
||||
assert not dependency_constraints.base_file_path
|
||||
assert dependency_constraints == DependencyConstraints.latest()
|
||||
|
||||
Reference in New Issue
Block a user