$ ruby sum-frozen-gems.rb
Number of gems that have `# frozen-string-literal: true` in all .rb files
among all public gems: 14254 / 175170 (8.14%)
per-file basis: 445132 / 3051922 (14.59%)
among public gems with the latest version released in 2015-present: 14208 / 101904 (13.94%)
per-file basis: 443460 / 1952225 (22.72%)
among public gems with the latest version released in 2020-present: 11974 / 41205 (29.06%)
per-file basis: 389559 / 1136445 (34.28%)
among public gems with the latest version released in 2022-present: 9121 / 26721 (34.13%)
per-file basis: 329742 / 848061 (38.88%)
-
-
Save mame/d4a9be41acf3d25cc2667a6959c4d37d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "zlib" | |
require "rubygems/package" | |
total_src_count = total_frozen_src_count = 0 | |
$out = open("frozen_gems.log", "w") | |
Dir.glob("/srv/gems/*") do |dir_path| | |
gem_name = File.basename(dir_path) | |
gem_path = "/home/gem-codesearch/gem-codesearch/mirror/gems/#{ gem_name }.gem" | |
metadata = nil | |
File.open gem_path, Gem.binary_mode do |io| | |
tar = Gem::Package::TarReader.new io | |
tar.each_entry do |entry| | |
case entry.full_name | |
when "metadata" then | |
metadata = entry.read | |
when "metadata.gz" then | |
begin | |
gz = Zlib::GzipReader.new(entry) | |
metadata = gz.read | |
gz.close | |
rescue Zlib::GzipFile::Error | |
metadata = "date: XXXX-XX-XX" | |
end | |
end | |
end | |
end | |
date = metadata[/^date: ([\dX]+-[\dX]+-[\dX]+)/, 1] | |
if date | |
src_count = frozen_src_count = 0 | |
Dir.glob(File.join(dir_path, "**/*.rb")) do |file| | |
next unless File.file?(file) && File.readable?(file) | |
src_count += 1 | |
frozen_src_count += 1 if File.binread(file) =~ /^# frozen[-_]string[-_]literal: true$/ | |
end | |
if src_count >= 1 | |
msg = "#{ date } #{ gem_name }: #{ frozen_src_count } / #{ src_count }" | |
puts msg | |
$out.puts msg | |
end | |
end | |
end | |
$out.close |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Number of gems that have `# frozen-string-literal: true` in all .rb files" | |
puts | |
["", "2015", "2020", "2022"].each do |year| | |
total_frozen_src_count = total_src_count = 0 | |
gem_count = frozen_gem_count = 0 | |
File.foreach("frozen_gems.log", chomp: true) do |s| | |
if s =~ /^(\d+)-\d+-\d+ .*?: (\d+) \/ (\d+)$/ | |
if $1 >= year | |
frozen_src_count = $2.to_i | |
src_count = $3.to_i | |
total_src_count += src_count | |
total_frozen_src_count += frozen_src_count | |
gem_count += 1 | |
if src_count == frozen_src_count | |
frozen_gem_count += 1 | |
end | |
end | |
end | |
end | |
if year == "" | |
among = "among all public gems" | |
else | |
among = "among public gems with the latest version released in #{ year }-present" | |
end | |
puts " #{ among }: #{ frozen_gem_count } / #{ gem_count } (#{ "%.2f%%" % (frozen_gem_count.to_f / gem_count * 100) })" | |
puts " per-file basis: #{ total_frozen_src_count } / #{ total_src_count } (#{ "%.2f%%" % (total_frozen_src_count.to_f / total_src_count * 100) })" | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment