Exemple #1
0
def reject_location_related_install_options(
        requirements: List[InstallRequirement],
        options: Optional[List[str]]) -> None:
    """If any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    """
    def format_options(option_names: Iterable[str]) -> List[str]:
        return ["--{}".format(name.replace("_", "-")) for name in option_names]

    offenders = []

    for requirement in requirements:
        install_options = requirement.install_options
        location_options = parse_distutils_args(install_options)
        if location_options:
            offenders.append("{!r} from {}".format(
                format_options(location_options.keys()), requirement))

    if options:
        location_options = parse_distutils_args(options)
        if location_options:
            offenders.append("{!r} from command line".format(
                format_options(location_options.keys())))

    if not offenders:
        return

    raise CommandError(
        "Location-changing options found in --install-option: {}."
        " This is unsupported, use pip-level options like --user,"
        " --prefix, --root, and --target instead.".format(
            "; ".join(offenders)))
Exemple #2
0
def test_multiple_invocations_do_not_keep_options() -> None:
    result = parse_distutils_args(["--prefix=hello1"])
    assert len(result) == 1
    assert result["prefix"] == "hello1"

    result = parse_distutils_args(["--root=world1"])
    assert len(result) == 1
    assert result["root"] == "world1"
def warn_deprecated_install_options(requirement_set, options):
    # type: (RequirementSet, Optional[List[str]]) -> None
    """If any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    """

    def format_options(option_names):
        # type: (Iterable[str]) -> List[str]
        return ["--{}".format(name.replace("_", "-")) for name in option_names]

    requirements = (
            requirement_set.unnamed_requirements +
            list(requirement_set.requirements.values())
    )

    offenders = []

    for requirement in requirements:
        install_options = requirement.options.get("install_options", [])
        location_options = parse_distutils_args(install_options)
        if location_options:
            offenders.append(
                "{!r} from {}".format(
                    format_options(location_options.keys()), requirement
                )
            )

    if options:
        location_options = parse_distutils_args(options)
        if location_options:
            offenders.append(
                "{!r} from command line".format(
                    format_options(location_options.keys())
                )
            )

    if not offenders:
        return

    deprecated(
        reason=(
            "Location-changing options found in --install-option: {}. "
            "This configuration may cause unexpected behavior and is "
            "unsupported.".format(
                "; ".join(offenders)
            )
        ),
        replacement=(
            "using pip-level options like --user, --prefix, --root, and "
            "--target"
        ),
        gone_in="20.2",
        issue=7309,
    )
Exemple #4
0
def test_user_option_works() -> None:
    result = parse_distutils_args(["--user"])
    assert result["user"] == 1
Exemple #5
0
def test_all_value_options_work(name: str, value: str) -> None:
    result = parse_distutils_args([f"--{name}={value}"])
    key_name = name.replace("-", "_")
    assert result[key_name] == value
Exemple #6
0
def test_unknown_option_is_ok() -> None:
    result = parse_distutils_args(["--foo"])
    assert not result
Exemple #7
0
def test_multiple_options_work() -> None:
    result = parse_distutils_args(["--prefix=hello", "--root=world"])
    assert result["prefix"] == "hello"
    assert result["root"] == "world"
Exemple #8
0
def test_options_are_clobbered() -> None:
    # Matches the current setuptools behavior that the last argument
    # wins.
    result = parse_distutils_args(["--prefix=hello", "--prefix=world"])
    assert result["prefix"] == "world"
Exemple #9
0
def test_option_is_returned() -> None:
    result = parse_distutils_args(["--prefix=hello"])
    assert result["prefix"] == "hello"

def reject_location_related_install_options(requirements, options):
    # type: (List[InstallRequirement], Optional[List[str]]) -> None
    """If any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    """
    def format_options(option_names):
        # type: (Iterable[str]) -> List[str]
        return ["--{}".format(name.replace("_", "-")) for name in option_names]

    offenders = []

    for requirement in requirements:
        install_options = requirement.install_options
        location_options = parse_distutils_args(install_options)
        if location_options:
            offenders.append(
                "{!r} from {}".format(
                    format_options(location_options.keys()), requirement
                )
            )

    if options:
        location_options = parse_distutils_args(options)
        if location_options:
            offenders.append(
                "{!r} from command line".format(
                    format_options(location_options.keys())
                )
            )
def test_all_value_options_work(name, value):
    result = parse_distutils_args(["--{}={}".format(name, value)])
    key_name = name.replace("-", "_")
    assert result[key_name] == value