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

[internal] Refactor jvm_artifact usage #13890

Merged
merged 2 commits into from
Dec 16, 2021

Conversation

Eric-Arellano
Copy link
Contributor

  • Move some validation into the Target API
  • Leverage early returns to simplify some code

[ci skip-rust]
[ci skip-build-wheels]

# 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]
Comment on lines -134 to -135
# Materialise the existing lockfile, and check for changes. We don't want to re-write
# identical lockfiles
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were duplicating the two if statement bodies. I inverted the conditional to make this all shorter and simpler.

raise CoursierError(
raise AssertionError(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This represents a programmer error.

Comment on lines -144 to -160
group = target[JvmArtifactGroupField].value
if not group:
raise InvalidTargetException(
f"The `group` field of {target.alias} target {target.address} must be set."
)

artifact = target[JvmArtifactArtifactField].value
if not artifact:
raise InvalidTargetException(
f"The `artifact` field of {target.alias} target {target.address} must be set."
)

version = target[JvmArtifactVersionField].value
if not version:
raise InvalidTargetException(
f"The `version` field of {target.alias} target {target.address} must be set."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Target API already was checking that it's not None. We just needed to teach MyPy by setting value: str, as MyPy doesn't understand that required = True means the value is no longer Optional.

Comment on lines +21 to +23
# -----------------------------------------------------------------------------------------------
# Generic resolve support fields
# -----------------------------------------------------------------------------------------------
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section is moved, unmodified, from below. I'll need it in a followup PR defined here so that I can subclass it lower in the file.

# 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]
Comment on lines -172 to -175
if url and jar:
raise CoursierError(
"You cannot specify both a `url` and `jar` for the same `jvm_artifact`."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now done with the Target API via Target.validate(). The major benefit of that is the validation is eager, ./pants list :: will check it. We generally have preferred eager errors.

The downside is that this is less reslient to creating a new JvmArtifact-like target in a plugin, they might not have implemented Target.validate too.

Copy link
Contributor

@chrisjrn chrisjrn left a comment

Choose a reason for hiding this comment

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

This all looks reasonable. Thanks!

@Eric-Arellano Eric-Arellano merged commit 18350c5 into pantsbuild:main Dec 16, 2021
@Eric-Arellano Eric-Arellano deleted the jvm-artifact-target-api branch December 16, 2021 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants