-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
make Platform class serializable for workunit-logger #21792
base: main
Are you sure you want to change the base?
Conversation
As described in pantsbuild#21773, having the Helm backend lint with the workunit-logger results in json serialization errors. Giving `Platform` a string representation resolves this (and anywhere else we may want to "print" it. Example workunit: ``` {"name": "pants.backend.helm.util_rules.tool.download_external_helm_plugin", "span_id": "bdaa19a5cd1ef797", "level": "DEBUG", "parent_id": "c8c137a5b78f02ea", "start_secs": 1734722271, "start_nanos": 296631921, "duration_secs": 0, "duration_nanos": 51846519, "description": "Download external Helm plugin", "metadata": {"name": "unittest", "version": "0.3.3", "platform": "linux_x86_64"}} ``` NOTE: I think this is a totally safe one line change, but admit it is to a rather core class.
@@ -39,7 +39,9 @@ def current_platform( | |||
if env_tgt.val.has_field(DockerPlatformField): | |||
return Platform(env_tgt.val[DockerPlatformField].normalized_value) | |||
if env_tgt.val.has_field(RemotePlatformField): | |||
return Platform(env_tgt.val[RemotePlatformField].value) | |||
remote_platform = env_tgt.val[RemotePlatformField].value |
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 am very confused:
- Why mypy was satisfied with this before since I think
Enum
behaves the same way. - Why it neede dso much extra help with the
remote_platform
var callout instead of just a check on.value
.
This is to resolve:
Partition #2 - python-default, ['CPython==3.11.*']:
src/python/pants/engine/internals/platform_rules.py: note: In function "current_platform":
src/python/pants/engine/internals/platform_rules.py:42:29: error: Argument 1 to "Platform" has incompatible type "str | None"; expected "str" [arg-type]
return Platform(env_tgt.val[RemotePlatformField].value)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 don't understand it either, but I have seen mypy get confused about this sort of thing elsewhere at times.
(Removing 2.24.x as I woke up this morning remembering that |
As described in #21773, having the Helm backend lint with the workunit-logger results in json serialization errors. Giving
Platform
a string representation resolves this (and anywhere else we may want to "print" it.Example workunit:
NOTE: I think this is a totally safe ~one line change, but admit it is to a rather core class.
fixes #21773