judges 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,13 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
- require 'time'
7
- require 'fileutils'
6
+ require 'base64'
7
+ require 'elapsed'
8
8
  require 'factbase'
9
+ require 'fileutils'
9
10
  require 'nokogiri'
10
- require 'elapsed'
11
+ require 'time'
12
+ require 'typhoeus'
11
13
  require_relative '../../judges'
12
14
  require_relative '../../judges/impex'
13
15
 
@@ -82,8 +84,19 @@ class Judges::Print
82
84
  'date' => Time.now.utc.iso8601,
83
85
  'columns' => opts['columns'] || 'when,what,who',
84
86
  'hidden' => opts['hidden'] || '_id,_version,_time,_job',
85
- 'version' => Judges::VERSION
87
+ 'version' => Judges::VERSION,
88
+ 'css_hash' => sha384('index.css'),
89
+ 'js_hash' => sha384('index.js')
86
90
  )
87
91
  )
88
92
  end
93
+
94
+ def sha384(asset)
95
+ url = "https://yegor256.github.io/judges/assets/#{asset}"
96
+ http = Typhoeus::Request.get(url)
97
+ return "Timeout at #{url.inspect}" if http.timed_out?
98
+ raise "Failed to load #{url.inspect}" unless http.code == 200
99
+ sha = Base64.strict_encode64(Digest::SHA256.digest(http.body))
100
+ "sha256-#{sha}"
101
+ end
89
102
  end
@@ -7,6 +7,8 @@ require 'backtrace'
7
7
  require 'elapsed'
8
8
  require 'factbase'
9
9
  require 'factbase/churn'
10
+ require 'factbase/logged'
11
+ require 'logger'
10
12
  require 'tago'
11
13
  require 'timeout'
12
14
  require_relative '../../judges'
@@ -40,10 +42,7 @@ class Judges::Update
40
42
  start = Time.now
41
43
  impex = Judges::Impex.new(@loog, args[1])
42
44
  fb = impex.import(strict: false)
43
- if opts['log']
44
- require 'factbase/logged'
45
- fb = Factbase::Logged.new(fb, @loog)
46
- end
45
+ fb = Factbase::Logged.new(fb, @loog) if opts['log']
47
46
  options = Judges::Options.new(opts['option'])
48
47
  if opts['options-file']
49
48
  options += Judges::Options.new(
@@ -148,6 +147,7 @@ class Judges::Update
148
147
  # @return [Churn] How many modifications have been made
149
148
  def one_judge(opts, fb, judge, global, options, errors)
150
149
  local = {}
150
+ start = Time.now
151
151
  begin
152
152
  if opts['lifetime'] && Time.now - @start > opts['lifetime']
153
153
  throw :"👎 The '#{judge.name}' judge skipped, no time left"
@@ -155,9 +155,9 @@ class Judges::Update
155
155
  Timeout.timeout(opts['timeout']) do
156
156
  judge.run(fb, global, local, options)
157
157
  end
158
- rescue Timeout::Error => e
159
- errors << "Judge #{judge.name} stopped by timeout: #{e.message}"
160
- throw :"👎 The '#{judge.name}' judge timed out: #{e.message}"
158
+ rescue Timeout::Error, Timeout::ExitException => e
159
+ errors << "Judge #{judge.name} stopped by timeout after #{start.ago}: #{e.message}"
160
+ throw :"👎 The '#{judge.name}' judge timed out after #{start.ago}: #{e.message}"
161
161
  end
162
162
  end
163
163
 
data/lib/judges/judge.rb CHANGED
@@ -28,6 +28,12 @@ class Judges::Judge
28
28
  @start = start
29
29
  end
30
30
 
31
+ # Print it as a string.
32
+ # @return [String] Name of it
33
+ def to_s
34
+ name
35
+ end
36
+
31
37
  # Run it with the given Factbase and environment variables.
32
38
  #
33
39
  # @param [Factbase] fb The factbase
data/lib/judges/judges.rb CHANGED
@@ -57,13 +57,18 @@ class Judges::Judges
57
57
  list.sort_by!(&:name)
58
58
  all = list.each_with_index.to_a
59
59
  good = all.dup
60
- all.reject { |a| a[0].name.start_with?(@shuffle) }.map { |a| a[1] }.each_with_index do |i, idx|
61
- good[i] = all[idx]
60
+ mapping = all
61
+ .map { |a| [a[0].name, a[1], a[1]] }
62
+ .reject { |a| a[0].start_with?(@shuffle) }
63
+ .to_h { |a| [a[1], a[2]] }
64
+ positions = mapping.values.shuffle
65
+ mapping.keys.zip(positions).to_h.each do |before, after|
66
+ good[after] = all[before]
62
67
  end
63
68
  good.map { |a| a[0] }.each(&)
64
69
  end
65
70
 
66
- # Iterate over them all.
71
+ # Iterate over them all, with an index.
67
72
  # @yield [(Judge, Integer)]
68
73
  def each_with_index
69
74
  idx = 0
data/lib/judges.rb CHANGED
@@ -8,5 +8,5 @@
8
8
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
9
9
  # License:: MIT
10
10
  module Judges
11
- VERSION = '0.38.0' unless const_defined?(:VERSION)
11
+ VERSION = '0.39.0' unless const_defined?(:VERSION)
12
12
  end