Skip to content

Commit

Permalink
Remove deprecated [python].only_binary, [python].no_binary, and `…
Browse files Browse the repository at this point in the history
…[python].tailor_ignore_solitary_init_files` (pantsbuild#16638)

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Aug 25, 2022
1 parent 8b03d13 commit 5119834
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 141 deletions.
16 changes: 3 additions & 13 deletions src/python/pants/backend/python/goals/tailor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ def is_entry_point(content: bytes) -> bool:
async def _find_source_targets(
py_files_globs: PathGlobs, all_owned_sources: AllOwnedSources, python_setup: PythonSetup
) -> list[PutativeTarget]:
ignore_solitary_explicitly_set = not python_setup.options.is_default(
"tailor_ignore_solitary_init_files"
)
ignore_solitary = (
python_setup.tailor_ignore_solitary_init_files
if ignore_solitary_explicitly_set
else python_setup.tailor_ignore_empty_init_files
)

result = []
check_if_init_file_empty: dict[str, tuple[str, str]] = {} # full_path: (dirname, filename)

Expand All @@ -119,13 +110,12 @@ async def _find_source_targets(
else:
name = None
if (
ignore_solitary
python_setup.tailor_ignore_empty_init_files
and tgt_type == PythonSourcesGeneratorTarget
and filenames in ({"__init__.py"}, {"__init__.pyi"})
):
if not ignore_solitary_explicitly_set:
f = next(iter(filenames))
check_if_init_file_empty[os.path.join(dirname, f)] = (dirname, f)
f = next(iter(filenames))
check_if_init_file_empty[os.path.join(dirname, f)] = (dirname, f)
else:
result.append(
PutativeTarget.for_target_type(
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/goals/tailor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def rule_runner() -> RuleRunner:


def test_find_putative_targets(rule_runner: RuleRunner) -> None:
rule_runner.set_options(["--no-python-tailor-ignore-solitary-init-files"])
rule_runner.set_options(["--no-python-tailor-ignore-empty-init-files"])
rule_runner.write_files(
{
"3rdparty/Pipfile.lock": "{}",
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_find_putative_targets(rule_runner: RuleRunner) -> None:


def test_skip_invalid_requirements(rule_runner: RuleRunner) -> None:
rule_runner.set_options(["--no-python-tailor-ignore-solitary-init-files"])
rule_runner.set_options(["--no-python-tailor-ignore-empty-init-files"])
rule_runner.write_files(
{
"3rdparty/requirements-valid.txt": b"FooProject >= 1.2",
Expand Down
113 changes: 0 additions & 113 deletions src/python/pants/backend/python/subsystems/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,56 +400,6 @@ class PythonSetup(Subsystem):
removal_version="3.0.0.dev0",
removal_hint=__constraints_deprecation_msg,
)
no_binary = StrListOption(
help=softwrap(
"""
Do not use binary packages (i.e., wheels) for these 3rdparty projects.
Also accepts `:all:` to disable all binary packages.
Note that some packages are tricky to compile and may fail to install when this option
is used on them. See https://pip.pypa.io/en/stable/cli/pip_install/#install-no-binary
for details.
Note: Only takes effect if you use Pex lockfiles. Use the default
`[python].lockfile_generator = "pex"` and run the `generate-lockfiles` goal.
"""
),
removal_version="2.15.0.dev0",
removal_hint=softwrap(
f"""
Use `[python].resolves_to_no_binary`, which allows you to set `--no-binary` on a
per-resolve basis for more flexibility. To keep this option's behavior, set
`[python].resolves_to_no_binary` with the key `{RESOLVE_OPTION_KEY__DEFAULT}` and the
value you used on this option.
"""
),
)
only_binary = StrListOption(
help=softwrap(
"""
Do not use source packages (i.e., sdists) for these 3rdparty projects.
Also accepts `:all:` to disable all source packages.
Packages without binary distributions will fail to install when this option is used on
them. See https://pip.pypa.io/en/stable/cli/pip_install/#install-only-binary for
details.
Note: Only takes effect if you use Pex lockfiles. Use the default
`[python].lockfile_generator = "pex"` and run the `generate-lockfiles` goal.
"""
),
removal_version="2.15.0.dev0",
removal_hint=softwrap(
f"""
Use `[python].resolves_to_only_binary`, which allows you to set `--only-binary` on a
per-resolve basis for more flexibility. To keep this option's behavior, set
`[python].resolves_to_only_binary` with the key `{RESOLVE_OPTION_KEY__DEFAULT}` and the
value you used on this option.
"""
),
)
resolver_manylinux = StrOption(
default="manylinux2014",
help=softwrap(
Expand All @@ -471,27 +421,6 @@ class PythonSetup(Subsystem):
),
advanced=True,
)
tailor_ignore_solitary_init_files = BoolOption(
default=True,
help=softwrap(
"""
If true, don't add `python_sources` targets for solitary `__init__.py` files with the
`tailor` goal.
Solitary `__init__.py` files usually exist as import scaffolding rather than true
library code, so it can be noisy to add BUILD files.
Set to false if you commonly have packages containing real code in
`__init__.py` without other `.py` files in the package.
"""
),
advanced=True,
removal_version="2.15.0.dev0",
removal_hint=(
"Use `[python].tailor_ignore_empty_init_files`, which checks that the `__init__.py`"
"file is both solitary and also empty."
),
)
tailor_ignore_empty_init_files = BoolOption(
"--tailor-ignore-empty-init-files",
default=True,
Expand Down Expand Up @@ -603,27 +532,6 @@ def resolves_to_constraints_file(
def resolves_to_no_binary(
self, all_python_tool_resolve_names: tuple[str, ...]
) -> dict[str, list[PipRequirement]]:
if self.no_binary:
if self._resolves_to_no_binary:
raise ValueError(
softwrap(
"""
Conflicting options used. You used the new, preferred
`[python].resolves_to_no_binary`, but also used the deprecated
`[python].no_binary`.
Please use only one of these (preferably `[python].resolves_to_no_binary`).
"""
)
)
no_binary_opt = [
PipRequirement.parse(v, description_of_origin="the option `[python].no_binary`")
for v in self.no_binary
]
return {
resolve: no_binary_opt
for resolve in {*self.resolves, *all_python_tool_resolve_names}
}
return {
resolve: [
PipRequirement.parse(
Expand All @@ -645,27 +553,6 @@ def resolves_to_no_binary(
def resolves_to_only_binary(
self, all_python_tool_resolve_names: tuple[str, ...]
) -> dict[str, list[PipRequirement]]:
if self.only_binary:
if self._resolves_to_only_binary:
raise ValueError(
softwrap(
"""
Conflicting options used. You used the new, preferred
`[python].resolves_to_only_binary`, but also used the deprecated
`[python].only_binary`.
Please use only one of these (preferably `[python].resolves_to_only_binary`).
"""
)
)
only_binary_opt = [
PipRequirement.parse(v, description_of_origin="the option `[python].only_binary`")
for v in self.only_binary
]
return {
resolve: only_binary_opt
for resolve in {*self.resolves, *all_python_tool_resolve_names}
}
return {
resolve: [
PipRequirement.parse(
Expand Down
14 changes: 1 addition & 13 deletions src/python/pants/backend/python/subsystems/setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ def create(resolves_to_constraints_file: dict[str, str]) -> dict[str, str]:


def test_resolves_to_no_binary_and_only_binary() -> None:
def create(
resolves_to_projects: dict[str, list[str]], deprecated_options: list[str] | None = None
) -> dict[str, list[PipRequirement]]:
def create(resolves_to_projects: dict[str, list[str]]) -> dict[str, list[PipRequirement]]:
subsystem = create_subsystem(
PythonSetup,
resolves={"a": "a.lock"},
resolves_to_no_binary=resolves_to_projects,
resolves_to_only_binary=resolves_to_projects,
only_binary=deprecated_options or [],
no_binary=deprecated_options or [],
)
only_binary = subsystem.resolves_to_only_binary(
all_python_tool_resolve_names=("tool1", "tool2")
Expand All @@ -75,11 +71,3 @@ def create(
}
with pytest.raises(UnrecognizedResolveNamesError):
create({"fake": []})

assert create({}, deprecated_options=["p1"]) == {
"a": [p1_req],
"tool1": [p1_req],
"tool2": [p1_req],
}
with pytest.raises(ValueError):
create({"a": ["p1"]}, deprecated_options=["p2"])

0 comments on commit 5119834

Please sign in to comment.