Skip to content
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

Merged

Conversation

grihabor
Copy link
Contributor

No description provided.

@grihabor grihabor force-pushed the generate-jvm-artifact-targets-from-pom-xml branch from 5b53296 to 6eea77c Compare December 29, 2023 23:48
Copy link
Contributor

@benjyw benjyw left a 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.

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
Copy link
Contributor

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.

Copy link
Contributor Author

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

src/python/pants/jvm/target_types.py Outdated Show resolved Hide resolved
grihabor and others added 2 commits January 27, 2024 18:03
Copy link
Contributor Author

@grihabor grihabor left a 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

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
Copy link
Contributor Author

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

@grihabor grihabor requested a review from benjyw January 29, 2024 23:35
Copy link
Contributor

@benjyw benjyw left a 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).
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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")
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

src/python/pants/jvm/target_types.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@grihabor grihabor left a 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).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@grihabor grihabor requested a review from benjyw February 4, 2024 00:11
@@ -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])
Copy link
Contributor

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 "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure b68ec95

Copy link
Contributor

@benjyw benjyw left a 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.

@benjyw benjyw merged commit db3cb04 into pantsbuild:main Feb 12, 2024
24 checks passed
@grihabor
Copy link
Contributor Author

Thank you for time!

benjyw pushed a commit that referenced this pull request May 13, 2024
Add docs for the `jvm_artifacts` target implemented in
#20336
grihabor added a commit to grihabor/pants that referenced this pull request May 13, 2024
Add docs for the `jvm_artifacts` target implemented in
pantsbuild#20336
grihabor added a commit to grihabor/pants that referenced this pull request May 13, 2024
Add docs for the `jvm_artifacts` target implemented in
pantsbuild#20336
huonw pushed a commit that referenced this pull request May 13, 2024
…#20919)

Add docs for the `jvm_artifacts` target implemented in
#20336
huonw pushed a commit that referenced this pull request May 13, 2024
…#20920)

Add docs for the `jvm_artifacts` target implemented in
#20336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants