-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[internal] Add infrastructure to support deprecating field names #13666
Conversation
Signed-off-by: Andreas Stenius <andreas.stenius@svenskaspel.se> # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
EDIT: Done. |
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
It works! :D With a dummy deprecation, this is what it looks like..
diff --git a/helloworld/BUILD b/helloworld/BUILD
index 47cfc3d..3042a68 100644
--- a/helloworld/BUILD
+++ b/helloworld/BUILD
@@ -22,7 +22,7 @@ resources(
# https://www.pantsbuild.org/docs/python-run-goal.
pex_binary(
name="pex_binary",
- entry_point="main.py",
+ foo_blarg="main.py",
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woohoo, this is awesome! Pardon the delayed review.
request.path, | ||
tuple(updated_text_lines), | ||
change_descriptions=tuple( | ||
f"Rename `{request.red(deprecated)}` to `{request.green(new)}`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this? (Still using colors)
Rename the field
deprecated
tonew
for target typetgt_type
request: RenameDeprecatedFieldsRequest, | ||
renamed_field_types: RenamedFieldTypes, | ||
) -> RewrittenBuildFile: | ||
target = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this pants_target
. I wasn't sure until reading this for a few minutes if "target" meant some generic parsing term.
class RenamedFieldTypes(FrozenDict[Tuple[str, str], str]): | ||
"""Deprecated field type names for target to new names.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about FrozenDict[str, FrozenDict[str, str]]
, which maps target types to field renames. Then you can rewrite the implementation I think to more eagerly exit if the target type is not a match?
I'm not sure I followed the level code correctly...the level should be 1. A nested target should not exist - targets are always top-level.
At this point, might also be worth switching to a frozen dataclass rather than subclassing FrozenDict so that you can give a name to the variable like target_types_to_field_renames
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about FrozenDict[str, FrozenDict[str, str]], which maps target types to field renames. Then you can rewrite the implementation I think to more eagerly exit if the target type is not a match?
I think you're referring to eagerly exit out of should_be_renamed
, correct?
OK, will try it out.. see what it'll look like (not convinced it will win much, but perhaps the data structure will be easier to comprehend?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I followed the level code correctly...the level should be 1. A nested target should not exist - targets are always top-level.
Agreed, there's a check that we only ever operate when level==1
.
This is to protect against constructs, such as this, as an example:
python_distribution(
provides=setup_py(my_field="value"),
)
As we do not want to change my_field
here... The level code might be overkill, but it plugs a potential hole.
And, as I write this, I realize I don't only look at the field name, but the enclosing target name as well (setup_py
in this example) and as such, it would be safe to ignore the level all together.. thanks for the nudge, will get rid of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait, no, the level is important for this reason..
python_distribution(
name="dist",
provides=setup_py(....),
old_field="value",
)
We must keep track of when we're seeing fields in setup_py
, which we should ignore, and when we're back in python_distritbution
, so we know that old_field
is deprecated and should be replaced.
It's hard to make this distinction unless I keep track of when I enter and exit constructs, such as setup_py
there..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some refactorings that will hopefully be easier to follow now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Internal changes: * [internal] Remove superfluous f-string specifiers ([#13821](#13821)) * [internal] scala: extract annotations as consumed types ([#13810](#13810)) * [jvm] Split nailgun digest from input file digests ([#13813](#13813)) * [internal] jvm: add jre_major_version and use stderr to properly extract version ([#13812](#13812)) * [internal] Clean up Go `embed` support's handling of dependencies ([#13801](#13801)) * [internal] scala: handle package object syntax in parser ([#13809](#13809)) * [internal] java: fix junit sentinel rule setup ([#13815](#13815)) * [internal] upgrade to rust v1.57.0 ([#13807](#13807)) * [internal] add failing test for FrozenDict equality issue ([#13389](#13389)) * [internal] Use `PyObject` instead of `Value` in more places ([#13802](#13802)) * Remove MultiPlatform Process abstractions ([#12725](#12725)) * [internal] add `JvmToolBase` for lockfile handling for JVM tools ([#13777](#13777)) * [internal] Port `MergeDigests` to Rust ([#13773](#13773)) * [jvm] Spawn nailgun servers outside the pool lock ([#13796](#13796)) * [internal] DRY loading internal Go binaries ([#13800](#13800)) * [internal] Convert unit tests to use pytest ([#13798](#13798)) * [internal] remove dead code - socket util. ([#13797](#13797)) * [internal] Reorganize Go parser scripts ([#13791](#13791)) * Adds Jackson core/datatype to `JVM_ARTIFACT_MAPPINGS` ([#13792](#13792)) * [internal] go: initial support for embedding resources ([#13743](#13743)) * [internal] Refer to `go.mod` path when downloading packages ([#13786](#13786)) * [internal] More robust Go dependency inference tests ([#13785](#13785)) * [internal] `tailor` doesn't add `go_package` for `testdata` folder ([#13783](#13783)) * [internal] Add Scala backend to dryrun for wheel builds. ([#13772](#13772)) * [internal] Unify JVM thirdparty resolves ([#13771](#13771)) * [internal] scala: infer dependencies from consumed symbols and intermediate scopes ([#13758](#13758)) * [internal] java: infer scala encoded symbols ([#13739](#13739)) * [internal] scala: parse and report package scopes ([#13738](#13738)) * [internal] go: configure included env vars for `GoSdkProcess` ([#13734](#13734)) * Fix some `./cargo audit` vulnerabilities. ([#13728](#13728)) * [internal] fix non-empty __init__.py ([#13730](#13730)) * Compute RepositoryPex directly from addresses. ([#13716](#13716)) * Upgrade to cargo-audit 0.16.0. ([#13729](#13729)) * Simplify `NativeHandler`. ([#13727](#13727)) * [internal] Switch to a maintained fork of the `fuse` crate for `brfs`. ([#13679](#13679)) * [internal] Add infrastructure to support deprecating field names ([#13666](#13666)) * [internal] Introduce OptionalPex/OptionalPexRequest. ([#13712](#13712)) * [internal] tailor adds go_package targets ([#13703](#13703)) * [internal] Remove unused testproject for pants-plugin ([#13704](#13704)) * [internal] Rename ambiguous `subpath` variable for Go code ([#13701](#13701)) * [internal] scala: generate the JVM names seen by Java code for Scala code ([#13696](#13696)) * Use RequirementsPexRequest in run_pex_binary.py. ([#13693](#13693)) * [internal] Refactor finding owning `go_mod` for first-party packages ([#13695](#13695)) * [internal] repl: add append_only_caches / run_in_workspace attributes to ReplRequest ([#13599](#13599)) * [internal] switch back to official `cargo-ensure-prefix` crate ([#13692](#13692)) * [internal] scala: extract type names from all Type.* AST nodes ([#13685](#13685)) * [internal] Convert unit tests to use pytest ([#13652](#13652)) * Unblock codegen support for java export analysis (#13645) ([#13675](#13675)) * [internal] upgrade to Rust 2021 Edition ([#13644](#13644)) * [internal] Don't store derived values on `go_first_party_package` targets ([#13676](#13676)) * Upgrade to py03 0.15.1. ([#13725](#13725)) * Add PyPDF2 to module mapping ([#13717](#13717)) * Upgrade console and indacatif. ([#13726](#13726))
Inspired by #13164
Pre-work for renaming the
pypi_repositories
field torepositories
forpython_distribution
targets.