-
Notifications
You must be signed in to change notification settings - Fork 318
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
Pub: Improve the code for the lockfile parsing #9046
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9046 +/- ##
============================================
- Coverage 68.02% 68.01% -0.02%
- Complexity 1158 1161 +3
============================================
Files 241 241
Lines 7691 7691
Branches 867 871 +4
============================================
- Hits 5232 5231 -1
Misses 2103 2103
- Partials 356 357 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
internal data class Lockfile( | ||
val packages: Map<String, PackageInfo> = emptyMap() |
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.
Upstream seems to call the values PackageId
. Should we align?
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.
Hm, on the one hand it's good to align to keep things simple. However,
we also usually name the variables (e.g. packageInfo
) after the class (e.g. PackageInfo
).
Renaming these as well to packageId
IMO creates more confusion, as we have different terminology ffor packageId
within ORT. I'd keep it for now and re-consider it later, when more code clean-up is done. Are you fine with that?
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.
Yes, I agree that the upstream name is a bit awkward, so let's keep ours, at least for now.
val name: String? = null, | ||
val url: String? = null, | ||
val path: String? = null, | ||
@JsonProperty("resolved-ref") | ||
val resolvedRef: String? = null, | ||
val relative: Boolean? = null, | ||
val sha256: String? = null |
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.
Similar for these properties, it's hard to believe they're all optional. Maybe try the opposite way and make them all mandatory, see where tests fail, and adjust only if necessary?
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.
Would it make sense to do this in a separate commit on top, to keep this commit more like a non-functional transformation? (Some of these are certainly nullable)
} | ||
|
||
VcsInfo.EMPTY | ||
lockfile.packages.forEach { (packageName, pkgInfoFromLockfile) -> |
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.
The outer listOf("packages"/*, "packages-dev"*/).forEach {
should be removed in a preceding commit as it's unrelated to this change and deserves a dedicated rationale. That also reduces nesting already beforehand so that the relevant changes here become more obvious.
4d05924
to
1d62766
Compare
Simplify an upcoming change. Signed-off-by: Frank Viernau <[email protected]>
The comment does not help much. Remove it to prepare for an upcoming change. Signed-off-by: Frank Viernau <[email protected]>
Signed-off-by: Frank Viernau <[email protected]>
Signed-off-by: Frank Viernau <[email protected]>
Simplify an upcoming change. Signed-off-by: Frank Viernau <[email protected]>
1d62766
to
00856e6
Compare
internal fun parseLockfile(lockfile: File) = yamlMapper.readValue<Lockfile>(lockfile) | ||
|
||
/** | ||
* See https://github.com/dart-lang/pub/blob/d86e3c979a3889fed61b68dae9f9156d0891704d/lib/src/lock_file.dart#L18. |
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.
Nit: Double space after "See".
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.
Ping, just in case you overlooked this @fviernau.
@@ -59,7 +59,6 @@ class PubCacheReaderTest : WordSpec({ | |||
{ | |||
"dependency": "direct main", | |||
"description": { | |||
"ref": "master", |
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.
Is it really much simpler to remove this compared to adding ref
to PackageInfo.Description
for completeness? I somehow liked to be able to get an overview of unresolved vs resolved ref even if it's unused currently.
Or actually, wouldn't the code just with without this change and without adding ref
to PackageInfo.Description
as you have @JsonIgnoreProperties(ignoreUnknown = true)
?
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.
Is it really much simpler to remove this compared to adding ref to PackageInfo.Description for completeness?
It has to be removed anyway, because from the following commit onwards, the test no more operates on JSON input.
I somehow liked to be able to get an overview of unresolved vs resolved ref even if it's unused currently.
...
Or actually, wouldn't the code just with without this change and without adding ref to PackageInfo.Description as you have @JsonIgnoreProperties(ignoreUnknown = true)?
Yes, I've prefer to use ignore unkown and not add unused properties.
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.
Yes, I've prefer to use ignore unkown and not add unused properties.
Just to share my thinking here: That makes it a bit hard to get an overview over the features / metadata a package manager provides in order to maybe implement new features in the future.
But I'm ok with keeping this as it is in the PR now.
Signed-off-by: Frank Viernau <[email protected]>
Signed-off-by: Frank Viernau <[email protected]>
00856e6
to
aefbf0b
Compare
Simplify migrating to KxS later on. See individual commits.