-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Generate jvm_artifact
targets from pom.xml
#20336
Generate jvm_artifact
targets from pom.xml
#20336
Conversation
5b53296
to
6eea77c
Compare
fbd176d
to
a1325fe
Compare
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 no expert on the JVM backend, but I guess this was mostly inspired by the scala equivalent? Looks good, with a couple of comments.
src/python/pants/jvm/target_types.py
Outdated
def parse_pom_xml(content: bytes) -> Iterator[Coordinate]: | ||
root = ET.fromstring(content.decode("utf-8")) | ||
match = re.match(r"^(\{.*\})project$", root.tag) | ||
assert match, root.tag |
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.
Can this assert fail on a bad pom? If so we want to throw a sensible error. Asserts should never fire on bad input, only on bad code.
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.
sure, added an exception with a better message
Co-authored-by: Benjy Weinberger <[email protected]>
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.
Thank you for review, @benjyw! Ready for another round
src/python/pants/jvm/target_types.py
Outdated
def parse_pom_xml(content: bytes) -> Iterator[Coordinate]: | ||
root = ET.fromstring(content.decode("utf-8")) | ||
match = re.match(r"^(\{.*\})project$", root.tag) | ||
assert match, root.tag |
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.
sure, added an exception with a better message
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.
Looking good! Just a couple of small things left.
@@ -0,0 +1,234 @@ | |||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). |
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.
Thanks for writing a test. The copyright should be 2024, but more importantly this file should be a sibling of jvm/target_types.py, whose logic it tests, not under the java backend.
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.
Fixed
src/python/pants/jvm/target_types.py
Outdated
root = ET.fromstring(content.decode("utf-8")) | ||
match = re.match(r"^(\{.*\})project$", root.tag) | ||
if not match: | ||
raise ValueError(f"Unexpected root tag `{root.tag}`, expected project") |
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.
Let's add the path to the pom.xml in the error message, so it's clear which one we're talking about.
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.
Sure
Co-authored-by: Benjy Weinberger <[email protected]>
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.
Thank you, @benjyw! Ready for another round
@@ -0,0 +1,234 @@ | |||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). |
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.
Fixed
src/python/pants/jvm/target_types.py
Outdated
root = ET.fromstring(content.decode("utf-8")) | ||
match = re.match(r"^(\{.*\})project$", root.tag) | ||
if not match: | ||
raise ValueError(f"Unexpected root tag `{root.tag}`, expected project") |
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.
Sure
@@ -517,7 +517,7 @@ async def generate_from_pom_xml( | |||
) | |||
files = await Get(DigestContents, Digest, pom_xml.snapshot.digest) | |||
mapping = request.generator[JvmArtifactsPackageMappingField].value | |||
coordinates = parse_pom_xml(files[0].content) | |||
coordinates = parse_pom_xml(files[0].content, pom_xml_path=pom_xml.snapshot.files[0]) |
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.
It just occurred to me that if files
is empty (which it shouldn't be due to other checks, but I hate relying on non-local checks) this will crash with a non-useful error message. So I'd recommend checking len(files)
and erroring with "Found no file at "
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.
Sure b68ec95
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.
Nice! Thanks for your patience through the reviews.
Thank you for time! |
Add docs for the `jvm_artifacts` target implemented in #20336
Add docs for the `jvm_artifacts` target implemented in pantsbuild#20336
Add docs for the `jvm_artifacts` target implemented in pantsbuild#20336
No description provided.