Skip to content

Commit

Permalink
Add back ignore for --files-not-found-behavior (pantsbuild#9175)
Browse files Browse the repository at this point in the history
### Problem

1.25.x already made a big breaking change by deprecating `globs()`. When paired with this, it proved too difficult for some users to upgrade. We will eventually deprecate `--ignore`, but only after `globs()` is removed.

### Solution

- Add back the `'ignore'` case to `--files-not-found-behavior`, which is converted into a `GlobMatchErrorBehavior` before being injected into the v2 rule graph as a singleton.
  • Loading branch information
cosmicexplorer authored Feb 27, 2020
1 parent a8b4998 commit 2f4e7bf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/python/pants/base/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def deprecated_conditional(
removal_version: str,
entity_description: str,
hint_message: Optional[str] = None,
deprecation_start_version: Optional[str] = None,
stacklevel: int = 4,
) -> None:
"""Marks a certain configuration as deprecated.
Expand All @@ -211,7 +212,13 @@ def deprecated_conditional(
"""
validate_deprecation_semver(removal_version, "removal version")
if predicate():
warn_or_error(removal_version, entity_description, hint_message, stacklevel=stacklevel)
warn_or_error(
removal_version,
entity_description,
hint_message,
deprecation_start_version=deprecation_start_version,
stacklevel=stacklevel,
)


def deprecated(
Expand Down
10 changes: 5 additions & 5 deletions src/python/pants/engine/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class PathGlobs:
The syntax supported is roughly Git's glob syntax.
NB: this object is interpreted from within Snapshot::lift_path_globs() -- that method will need to
be aware of any changes to this object's definition.
NB: this object is interpreted from within Snapshot::lift_path_globs() -- that method will need
to be aware of any changes to this object's definition.
"""

globs: Tuple[str, ...]
Expand All @@ -76,9 +76,9 @@ def __init__(
with `!`, e.g. `!ignore.py`.
:param glob_match_error_behavior: whether to warn or error upon match failures
:param conjunction: whether all `include`s must match or only at least one must match
:param description_of_origin: a human-friendly description of where this PathGlobs request is
coming from, used to improve the error message for unmatched
globs. For example, this might be
:param description_of_origin: a human-friendly description of where this PathGlobs request
is coming from, used to improve the error message for
unmatched globs. For example, this might be the text string
"the option `--isort-config`".
"""
self.globs = tuple(globs)
Expand Down
12 changes: 10 additions & 2 deletions src/python/pants/engine/legacy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,11 @@ async def hydrate_sources(
glob_match_error_behavior=glob_match_error_behavior,
# TODO(#9012): add line number referring to the sources field. When doing this, we'll likely
# need to `await Get[BuildFileAddress](Address)`.
description_of_origin=f"{address}'s `{sources_field.arg}` field",
description_of_origin=(
f"{address}'s `{sources_field.arg}` field"
if glob_match_error_behavior != GlobMatchErrorBehavior.ignore
else None
),
)
snapshot = await Get[Snapshot](PathGlobs, path_globs)
fileset_with_spec = _eager_fileset_with_spec(
Expand All @@ -740,7 +744,11 @@ async def hydrate_bundles(
glob_match_error_behavior=glob_match_error_behavior,
# TODO(#9012): add line number referring to the bundles field. When doing this, we'll likely
# need to `await Get[BuildFileAddress](Address)`.
description_of_origin=f"{address}'s `bundles` field",
description_of_origin=(
f"{address}'s `bundles` field"
if glob_match_error_behavior != GlobMatchErrorBehavior.ignore
else None
),
)
for pg in bundles_field.path_globs_list
]
Expand Down
20 changes: 15 additions & 5 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_pants_configdir,
pants_version,
)
from pants.base.deprecated import deprecated_conditional
from pants.option.custom_types import dir_option, file_option
from pants.option.errors import OptionsError
from pants.option.option_value_container import OptionValueContainer
Expand Down Expand Up @@ -46,10 +47,23 @@ class GlobMatchErrorBehavior(Enum):
class FileNotFoundBehavior(Enum):
"""What to do when globs do not match in BUILD files."""

ignore = "ignore"
warn = "warn"
error = "error"

def to_glob_match_error_behavior(self) -> GlobMatchErrorBehavior:
deprecated_conditional(
lambda: self == type(self).ignore,
removal_version="1.29.0.dev2",
entity_description="--files-not-found-behavior-option=ignore",
hint_message=(
"If you currently set `--files-not-found-behavior=ignore`, you will "
"need to instead either set `--files-not-found-behavior=warn` (the "
"default) or `--files-not-found-behavior=error`. Ignoring when files are "
"not found often results in subtle bugs, so we are removing the option."
),
deprecation_start_version="1.27.0.dev0",
)
return GlobMatchErrorBehavior(self.value)


Expand Down Expand Up @@ -491,11 +505,7 @@ def register_bootstrap_options(cls, register):
default=GlobMatchErrorBehavior.warn,
removal_version="1.27.0.dev0",
removal_hint="If you currently set `--glob-expansion-failure=error`, instead set "
"`--files-not-found-behavior=error`.\n\n"
"If you currently set `--glob-expansion-failure=ignore`, you will "
"need to instead either set `--files-not-found-behavior=warn` (the "
"default) or `--files-not-found-behavior=error`. Ignoring when files are "
"not found often results in subtle bugs, so we are removing the option.",
"`--files-not-found-behavior=error`.",
help="What to do when files and globs specified in BUILD files, such as in the "
"`sources` field, cannot be found. This happens when the files do not exist on "
"your machine or when they are ignored by the `--pants-ignore` option.",
Expand Down

0 comments on commit 2f4e7bf

Please sign in to comment.