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

Index into array resulting from Hash#map #7

Merged
merged 1 commit into from
Dec 11, 2024
Merged

Conversation

headius
Copy link
Collaborator

@headius headius commented Dec 11, 2024

Not sure why this is suddenly failing but the elements passed to this map block are not hashes, they are arrays. This is the simplest fix.

Not sure why this is suddenly failing but the elements passed to this `map` block are not hashes, they are arrays. This is the simplest fix.
@headius
Copy link
Collaborator Author

headius commented Dec 11, 2024

CRuby and JRuby both produce arrays at this point, so I'm not sure how the old code ever worked:

$ jruby -e 'x = {:metadata=>{:groupId=>"org.jruby", :artifactId=>"jruby-dist", :versioning=>{:latest=>"9.4.10.0-SNAPSHOT", :release=>"", :versions=>{:version=>"9.4.10.0-SNAPSHOT"}, :lastUpdated=>"20241210220254"}}}; p x.dig(:metadata, :versioning, :versions).map.to_a'
[[:version, "9.4.10.0-SNAPSHOT"]]
[] jruby $ ruby33 -e 'x = {:metadata=>{:groupId=>"org.jruby", :artifactId=>"jruby-dist", :versioning=>{:latest=>"9.4.10.0-SNAPSHOT", :release=>"", :versions=>{:version=>"9.4.10.0-SNAPSHOT"}, :lastUpdated=>"20241210220254"}}}; p x.dig(:metadata, :versioning, :versions).map.to_a'
[[:version, "9.4.10.0-SNAPSHOT"]]

@headius headius merged commit e6de7fd into master Dec 11, 2024
@headius headius deleted the hash_map_returns_arrays branch December 11, 2024 00:44
@eregon
Copy link
Member

eregon commented Dec 11, 2024

Thanks for the fix!
Although I think the old situation can happen again so it would be best to handle both.

The xml changed, on the passing build (I'm happy I chose to always output the XML there):
https://github.com/ruby/jruby-dev-builder/actions/runs/12224444272/job/34097212245 https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-dist/maven-metadata.xml

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>org.jruby</groupId>
  <artifactId>jruby-dist</artifactId>
  <versioning>
    <latest>9.4.10.0-SNAPSHOT</latest>
    <release></release>
    <versions>
      <version>9.4.9.0-SNAPSHOT</version>
      <version>9.4.10.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20241208063834</lastUpdated>
  </versioning>
</metadata>

and on the failing build:
https://github.com/ruby/jruby-dev-builder/actions/runs/12242437927/job/34149778998

https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-dist/maven-metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
  <groupId>org.jruby</groupId>
  <artifactId>jruby-dist</artifactId>
  <versioning>
    <latest>9.4.10.0-SNAPSHOT</latest>
    <release></release>
    <versions>
      <version>9.4.10.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20241209172946</lastUpdated>
  </versioning>
</metadata>

i.e. multiple <version> vs a single one and it seems MicroXMLParser just uses nested hashes when there are no duplicate keys at the same level:

if keys == keys.uniq
entries = entries.inject({}, :merge)

@eregon
Copy link
Member

eregon commented Dec 11, 2024

BTW IIRC we cannot just use <latest>9.4.10.0-SNAPSHOT</latest> because that doesn't seem to mean "snapshot of the latest release series" but maybe "latest push snapshot" or something else.

@headius
Copy link
Collaborator Author

headius commented Dec 12, 2024

Ahh, so when there's two snapshots in the snapshot repo, there will be multiple children, in which case MicroParserXML will put them in a hash. Perhaps it's MicroParserXML that should be changed to consistently return hashes? I'm not sure if that's your code or someone else's, but returning different types depending on how many child elements there are seems like a bad idea.

@eregon
Copy link
Member

eregon commented Dec 12, 2024

Yes, that's my code and indeed it's not great for that case (although convenient for other cases).
Anyway, I think we could use the nokogiri variant of this script, I'll give that a try.
The problem was installing nokogiri used to be very slow (due to C compilation) but should no longer be a concern with the precompiled nokogiri gems.

eregon added a commit that referenced this pull request Dec 14, 2024
* Installing nokogiri used to be slow, but no longer a problem nowadays.
* It's more correct, see #7
@eregon
Copy link
Member

eregon commented Dec 14, 2024

Done: c018acd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants