progress 3.5.2 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -6
- data/.travis.yml +12 -10
- data/CHANGELOG.markdown +4 -0
- data/LICENSE.txt +1 -1
- data/README.markdown +1 -1
- data/lib/progress.rb +1 -0
- data/lib/progress/class_methods.rb +4 -2
- data/lib/progress/elapsed_time.rb +26 -0
- data/lib/progress/eta.rb +5 -3
- data/lib/progress/kernel.rb +1 -1
- data/progress.gemspec +4 -4
- data/spec/progress/elapsed_time_spec.rb +13 -0
- data/spec/progress_spec.rb +21 -20
- metadata +15 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdce3b680bc7e08cda708708d4058f6cddd399469463d57adfeb576ce7436bd7
|
4
|
+
data.tar.gz: 699601431481e0159b0f48102a879e3bb8e47f473bedd25478002cbc55856225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84757caa1fa6d3e7e6f4a1e78d086d3494ae991021178fdbd454b05ed81b16b3ef6439719e9e3b6c37549c9fb9bc3f6420232b2fcb5f68f684d5655c1245bd4b
|
7
|
+
data.tar.gz: e1f40e3b1a84f4f8cea4e29ba798f136ed72e5b7a2e978dde51c86fd0c28cbcf4c695557b8920649948d0b6c6d5299eccde2c6b83e59fbfb7d51600b76d88651
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- '*.gemspec'
|
4
|
+
NewCops: enable
|
5
|
+
TargetRubyVersion: 2.4
|
4
6
|
|
5
7
|
Layout/AccessModifierIndentation:
|
6
8
|
EnforcedStyle: outdent
|
@@ -14,7 +16,7 @@ Layout/DotPosition:
|
|
14
16
|
Layout/EndAlignment:
|
15
17
|
EnforcedStyleAlignWith: variable
|
16
18
|
|
17
|
-
Layout/
|
19
|
+
Layout/FirstHashElementIndentation:
|
18
20
|
EnforcedStyle: consistent
|
19
21
|
|
20
22
|
Layout/SpaceBeforeBlockBraces:
|
@@ -24,7 +26,7 @@ Layout/SpaceBeforeBlockBraces:
|
|
24
26
|
Layout/SpaceInsideHashLiteralBraces:
|
25
27
|
EnforcedStyle: no_space
|
26
28
|
|
27
|
-
Lint/
|
29
|
+
Lint/RedundantRequireStatement:
|
28
30
|
Enabled: false
|
29
31
|
|
30
32
|
Metrics/AbcSize:
|
@@ -47,14 +49,14 @@ Metrics/ModuleLength:
|
|
47
49
|
Max: 200
|
48
50
|
|
49
51
|
Metrics/PerceivedComplexity:
|
50
|
-
Max:
|
52
|
+
Max: 11
|
53
|
+
|
54
|
+
Style/AccessorGrouping:
|
55
|
+
Enabled: false
|
51
56
|
|
52
57
|
Style/Alias:
|
53
58
|
EnforcedStyle: prefer_alias_method
|
54
59
|
|
55
|
-
Style/BracesAroundHashParameters:
|
56
|
-
Enabled: false
|
57
|
-
|
58
60
|
Style/DoubleNegation:
|
59
61
|
Enabled: false
|
60
62
|
|
@@ -64,12 +66,27 @@ Style/EmptyCaseCondition:
|
|
64
66
|
Style/Encoding:
|
65
67
|
Enabled: false
|
66
68
|
|
69
|
+
Style/FormatStringToken:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/HashEachMethods:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Style/HashTransformKeys:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/HashTransformValues:
|
79
|
+
Enabled: false
|
80
|
+
|
67
81
|
Style/IfUnlessModifier:
|
68
82
|
Enabled: false
|
69
83
|
|
70
84
|
Style/NumericPredicate:
|
71
85
|
Enabled: false
|
72
86
|
|
87
|
+
Style/OptionalBooleanParameter:
|
88
|
+
Enabled: false
|
89
|
+
|
73
90
|
Style/ParallelAssignment:
|
74
91
|
Enabled: false
|
75
92
|
|
data/.travis.yml
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
dist: trusty
|
1
|
+
dist: xenial
|
3
2
|
language: ruby
|
4
3
|
before_install:
|
5
4
|
- gem install bundler || gem install bundler --version '< 2'
|
@@ -9,16 +8,19 @@ rvm:
|
|
9
8
|
- '2.1.10'
|
10
9
|
- '2.2.10'
|
11
10
|
- '2.3.8'
|
12
|
-
- '2.4.
|
13
|
-
- '2.5.
|
14
|
-
- '2.6.
|
15
|
-
- '
|
11
|
+
- '2.4.10'
|
12
|
+
- '2.5.8'
|
13
|
+
- '2.6.6'
|
14
|
+
- '2.7.2'
|
15
|
+
- '3.0.0'
|
16
|
+
- 'jruby-9.1.17.0'
|
17
|
+
- 'jruby-9.2.14.0'
|
16
18
|
script: bundle exec rspec
|
17
19
|
matrix:
|
18
20
|
include:
|
19
|
-
- env: RUBOCOP
|
20
|
-
rvm: '2.4.
|
21
|
+
- env: RUBOCOP=1
|
22
|
+
rvm: '2.4.10'
|
21
23
|
script: bundle exec rubocop
|
22
|
-
- env: CHECK_RUBIES
|
23
|
-
rvm: '2.4.
|
24
|
+
- env: CHECK_RUBIES=1
|
25
|
+
rvm: '2.4.10'
|
24
26
|
script: bundle exec travis_check_rubies
|
data/CHANGELOG.markdown
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## unreleased
|
4
4
|
|
5
|
+
## v3.6.0 (2021-04-02)
|
6
|
+
|
7
|
+
* Use `Process.clock_gettime` instead of `Time.now` which is faster and should give proper estimates even if sleeping in the middle [#13](https://github.com/toy/progress/issues/13) [@toy](https://github.com/toy)
|
8
|
+
|
5
9
|
## v3.5.2 (2019-07-14)
|
6
10
|
|
7
11
|
* Remove deprecated `rubyforge_project` attribute from gemspec [rubygems/rubygems#2436](https://github.com/rubygems/rubygems/pull/2436) [@toy](https://github.com/toy)
|
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
data/lib/progress.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'progress/elapsed_time'
|
5
|
+
|
4
6
|
class Progress
|
5
7
|
# Class methods of Progress
|
6
8
|
module ClassMethods
|
@@ -165,14 +167,14 @@ class Progress
|
|
165
167
|
end
|
166
168
|
|
167
169
|
def time_to_print?
|
168
|
-
!@next_time_to_print || @next_time_to_print <=
|
170
|
+
!@next_time_to_print || @next_time_to_print <= ElapsedTime.now
|
169
171
|
end
|
170
172
|
|
171
173
|
def print_message(options = {})
|
172
174
|
force = options[:force]
|
173
175
|
lock force do
|
174
176
|
if force || time_to_print?
|
175
|
-
@next_time_to_print =
|
177
|
+
@next_time_to_print = ElapsedTime.now + 0.3
|
176
178
|
restart_beeper
|
177
179
|
io << message_for_output(options)
|
178
180
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Progress
|
4
|
+
# Use Process.clock_gettime if available to get time more fitting to calculate elapsed time
|
5
|
+
module ElapsedTime
|
6
|
+
CLOCK_NAME = %w[
|
7
|
+
CLOCK_UPTIME_RAW
|
8
|
+
CLOCK_UPTIME
|
9
|
+
CLOCK_MONOTONIC_RAW
|
10
|
+
CLOCK_MONOTONIC
|
11
|
+
CLOCK_REALTIME
|
12
|
+
].find{ |name| Process.const_defined?(name) }
|
13
|
+
|
14
|
+
CLOCK_ID = CLOCK_NAME && Process.const_get(CLOCK_NAME)
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def now
|
19
|
+
if CLOCK_ID
|
20
|
+
Process.clock_gettime(CLOCK_ID)
|
21
|
+
else
|
22
|
+
Time.now.to_f
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/progress/eta.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'progress/elapsed_time'
|
4
|
+
|
3
5
|
class Progress
|
4
6
|
# Estimate time of arrival
|
5
7
|
class Eta
|
6
8
|
def initialize
|
7
|
-
@started_at =
|
9
|
+
@started_at = ElapsedTime.now
|
8
10
|
end
|
9
11
|
|
10
12
|
def left(completed)
|
@@ -15,7 +17,7 @@ class Progress
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def elapsed
|
18
|
-
seconds_to_string(
|
20
|
+
seconds_to_string(ElapsedTime.now - @started_at)
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
@@ -36,7 +38,7 @@ class Progress
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def seconds_left(completed)
|
39
|
-
now =
|
41
|
+
now = ElapsedTime.now
|
40
42
|
return unless completed > 0 && now - @started_at >= 1
|
41
43
|
|
42
44
|
current_eta = @started_at + (now - @started_at) / completed
|
data/lib/progress/kernel.rb
CHANGED
data/progress.gemspec
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'progress'
|
5
|
-
s.version = '3.
|
5
|
+
s.version = '3.6.0'
|
6
6
|
s.summary = %q{Show progress of long running tasks}
|
7
|
-
s.homepage = "
|
7
|
+
s.homepage = "https://github.com/toy/#{s.name}"
|
8
8
|
s.authors = ['Ivan Kuchin']
|
9
9
|
s.license = 'MIT'
|
10
10
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.require_paths = %w[lib]
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '~> 3.0'
|
26
|
-
if RUBY_VERSION >= '2.
|
27
|
-
s.add_development_dependency 'rubocop', '~> 0
|
26
|
+
if RUBY_VERSION >= '2.4'
|
27
|
+
s.add_development_dependency 'rubocop', '~> 1.0'
|
28
28
|
end
|
29
29
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'progress/elapsed_time'
|
4
|
+
|
5
|
+
describe Progress::ElapsedTime do
|
6
|
+
let(:timeout){ 0.01 }
|
7
|
+
|
8
|
+
describe '.now' do
|
9
|
+
it 'returns incrementing value' do
|
10
|
+
expect{ sleep timeout }.to change{ described_class.now }.by_at_least(timeout)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/progress_spec.rb
CHANGED
@@ -5,6 +5,7 @@ require 'progress'
|
|
5
5
|
require 'tempfile'
|
6
6
|
require 'shellwords'
|
7
7
|
require 'csv'
|
8
|
+
require 'set'
|
8
9
|
|
9
10
|
describe Progress do
|
10
11
|
before do
|
@@ -86,7 +87,7 @@ describe Progress do
|
|
86
87
|
|
87
88
|
describe 'with_progress' do
|
88
89
|
it 'returns with block same as when called with each' do
|
89
|
-
expect(enum.with_progress
|
90
|
+
expect(enum.with_progress(&:to_s)).to eq(enum.with_progress.each(&:to_s))
|
90
91
|
end
|
91
92
|
|
92
93
|
it 'does not break each' do
|
@@ -180,7 +181,7 @@ describe Progress do
|
|
180
181
|
describe enum.class do
|
181
182
|
it 'calls each only once' do
|
182
183
|
expect(enum).to receive(:each).once.and_call_original
|
183
|
-
expect(enum.with_progress.each
|
184
|
+
expect(enum.with_progress.each(&:to_s)).to eq(enum)
|
184
185
|
end
|
185
186
|
|
186
187
|
include_examples 'yielding', enum
|
@@ -189,13 +190,13 @@ describe Progress do
|
|
189
190
|
|
190
191
|
[
|
191
192
|
100.times,
|
192
|
-
'a'..'z',
|
193
|
+
('a'..'z').dup,
|
193
194
|
].each do |enum|
|
194
195
|
describe enum.class do
|
195
196
|
it 'calls each twice' do
|
196
|
-
enum_each = enum.each
|
197
|
+
enum_each = enum.each(&:to_s)
|
197
198
|
expect(enum).to receive(:each).at_most(:twice).and_call_original
|
198
|
-
expect(enum.with_progress.each
|
199
|
+
expect(enum.with_progress.each(&:to_s)).to eq(enum_each)
|
199
200
|
end
|
200
201
|
|
201
202
|
include_examples 'yielding', enum
|
@@ -212,7 +213,7 @@ describe Progress do
|
|
212
213
|
|
213
214
|
with_progress = Progress::WithProgress.new(enum)
|
214
215
|
expect(with_progress).not_to receive(:warn)
|
215
|
-
expect(with_progress.each
|
216
|
+
expect(with_progress.each(&:to_s)).to eq(enum)
|
216
217
|
end
|
217
218
|
|
218
219
|
it 'yields same lines' do
|
@@ -233,18 +234,18 @@ describe Progress do
|
|
233
234
|
|
234
235
|
with_progress = enum.with_progress
|
235
236
|
expect(with_progress).not_to receive(:warn)
|
236
|
-
expect(with_progress.each
|
237
|
+
expect(with_progress.each(&:to_s)).to eq(enum)
|
237
238
|
end
|
238
239
|
end
|
239
240
|
|
240
241
|
it 'calls each only once for Tempfile' do
|
241
242
|
enum = Tempfile.open('progress')
|
242
|
-
enum_each = enum.each
|
243
|
+
enum_each = enum.each(&:to_s) # returns underlying File
|
243
244
|
expect(enum_each).to receive(:each).once.and_call_original
|
244
245
|
|
245
246
|
with_progress = enum.with_progress
|
246
247
|
expect(with_progress).not_to receive(:warn)
|
247
|
-
expect(with_progress.each
|
248
|
+
expect(with_progress.each(&:to_s)).to eq(enum_each)
|
248
249
|
end
|
249
250
|
|
250
251
|
it 'calls each only once for IO and shows warning' do
|
@@ -253,7 +254,7 @@ describe Progress do
|
|
253
254
|
|
254
255
|
with_progress = enum.with_progress
|
255
256
|
expect(with_progress).to receive(:warn)
|
256
|
-
expect(with_progress.each
|
257
|
+
expect(with_progress.each(&:to_s)).to eq(enum)
|
257
258
|
end
|
258
259
|
|
259
260
|
[
|
@@ -279,8 +280,8 @@ describe Progress do
|
|
279
280
|
|
280
281
|
with_progress = enum.with_progress
|
281
282
|
expect(with_progress).not_to receive(:warn)
|
282
|
-
expect(with_progress.each
|
283
|
-
to eq(CSV.open('spec/test.csv').each
|
283
|
+
expect(with_progress.each(&:to_s)).
|
284
|
+
to eq(CSV.open('spec/test.csv').each(&:to_s))
|
284
285
|
end
|
285
286
|
else
|
286
287
|
it 'calls each only once for CSV and shows warning' do
|
@@ -289,7 +290,7 @@ describe Progress do
|
|
289
290
|
|
290
291
|
with_progress = enum.with_progress
|
291
292
|
expect(with_progress).to receive(:warn)
|
292
|
-
expect(with_progress.each
|
293
|
+
expect(with_progress.each(&:to_s)).to eq(enum)
|
293
294
|
end
|
294
295
|
end
|
295
296
|
|
@@ -334,11 +335,11 @@ describe Progress do
|
|
334
335
|
Progress.step 2, 'simle'
|
335
336
|
|
336
337
|
Progress.step 2, 'times' do
|
337
|
-
3.times.with_progress
|
338
|
+
3.times.with_progress(&:to_s)
|
338
339
|
end
|
339
340
|
|
340
341
|
Progress.step 'enum' do
|
341
|
-
3.times.to_a.with_progress
|
342
|
+
3.times.to_a.with_progress(&:to_s)
|
342
343
|
end
|
343
344
|
end
|
344
345
|
end
|
@@ -356,11 +357,11 @@ describe Progress do
|
|
356
357
|
end
|
357
358
|
|
358
359
|
def on_line(str)
|
359
|
-
"\r
|
360
|
+
"\r#{str}\e[K"
|
360
361
|
end
|
361
362
|
|
362
363
|
def line(str)
|
363
|
-
str
|
364
|
+
"#{str}\n"
|
364
365
|
end
|
365
366
|
|
366
367
|
def on_line_n_title(str)
|
@@ -390,7 +391,7 @@ describe Progress do
|
|
390
391
|
on_line_n_title("Test: #{hl ' 93.3%'} > #{hl ' 66.7%'}"),
|
391
392
|
on_line_n_title('Test: 100.0% > 100.0%'),
|
392
393
|
on_line_n_title('Test: 100.0% - enum'),
|
393
|
-
on_line('Test: 100.0% (elapsed: 0s) - enum')
|
394
|
+
"#{on_line('Test: 100.0% (elapsed: 0s) - enum')}\n",
|
394
395
|
title(''),
|
395
396
|
].flatten.join)
|
396
397
|
end
|
@@ -426,7 +427,7 @@ describe Progress do
|
|
426
427
|
let(:reference_output) do
|
427
428
|
stub_progress_io(reference_io = StringIO.new)
|
428
429
|
count_a.times.with_progress('Test') do
|
429
|
-
count_b.times.with_progress
|
430
|
+
count_b.times.with_progress(&:to_s)
|
430
431
|
end
|
431
432
|
reference_io.string
|
432
433
|
end
|
@@ -468,7 +469,7 @@ describe Progress do
|
|
468
469
|
|
469
470
|
it 'outputs same when called using with_progress on list' do
|
470
471
|
count_a.times.to_a.with_progress('Test') do
|
471
|
-
count_b.times.to_a.with_progress
|
472
|
+
count_b.times.to_a.with_progress(&:to_s)
|
472
473
|
end
|
473
474
|
expect(io.string).to eq(reference_output)
|
474
475
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,16 +30,16 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
41
|
-
description:
|
42
|
-
email:
|
40
|
+
version: '1.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
@@ -55,23 +55,25 @@ files:
|
|
55
55
|
- lib/progress/active_record.rb
|
56
56
|
- lib/progress/beeper.rb
|
57
57
|
- lib/progress/class_methods.rb
|
58
|
+
- lib/progress/elapsed_time.rb
|
58
59
|
- lib/progress/enumerable.rb
|
59
60
|
- lib/progress/eta.rb
|
60
61
|
- lib/progress/integer.rb
|
61
62
|
- lib/progress/kernel.rb
|
62
63
|
- lib/progress/with_progress.rb
|
63
64
|
- progress.gemspec
|
65
|
+
- spec/progress/elapsed_time_spec.rb
|
64
66
|
- spec/progress_spec.rb
|
65
67
|
- spec/test.csv
|
66
|
-
homepage:
|
68
|
+
homepage: https://github.com/toy/progress
|
67
69
|
licenses:
|
68
70
|
- MIT
|
69
71
|
metadata:
|
70
72
|
bug_tracker_uri: https://github.com/toy/progress/issues
|
71
73
|
changelog_uri: https://github.com/toy/progress/blob/master/CHANGELOG.markdown
|
72
|
-
documentation_uri: https://www.rubydoc.info/gems/progress/3.
|
74
|
+
documentation_uri: https://www.rubydoc.info/gems/progress/3.6.0
|
73
75
|
source_code_uri: https://github.com/toy/progress
|
74
|
-
post_install_message:
|
76
|
+
post_install_message:
|
75
77
|
rdoc_options: []
|
76
78
|
require_paths:
|
77
79
|
- lib
|
@@ -86,10 +88,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
88
|
- !ruby/object:Gem::Version
|
87
89
|
version: '0'
|
88
90
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
91
|
+
rubygems_version: 3.1.5
|
92
|
+
signing_key:
|
91
93
|
specification_version: 4
|
92
94
|
summary: Show progress of long running tasks
|
93
95
|
test_files:
|
96
|
+
- spec/progress/elapsed_time_spec.rb
|
94
97
|
- spec/progress_spec.rb
|
95
98
|
- spec/test.csv
|