nanoc-core 4.11.13 → 4.11.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0e2dd5ec7f304ce59ed69129bf291b1be44dfd01740ab59634a7f3f1033ad43
4
- data.tar.gz: dc054fcd938d0980cab9699705b622b5cff901631bc69f9aa89fae08a42c7239
3
+ metadata.gz: bd4fffaf7813aba1bc2544b16ff1cf801f141a293605c4cd3a4f44d26e6baf02
4
+ data.tar.gz: a11c2bd8d095dbfcfddc00628cf2a65115184dee3cbedd3ea956d17ce0551f57
5
5
  SHA512:
6
- metadata.gz: 2030d8250adaeb13cc7974cf35cada04e0c6ec8a7c62e81382ca0f808dfd8e6a3b0e719ffc3bdb4131236bbbfb730e122fa4779b447bc386487f588bc90a5e01
7
- data.tar.gz: ec172cf7c9d17bcfc399212e855cc4c5dfbf9cc627b48ead86e0fe9ff264f79a67d90089f3ead1a1cbf1ba363858974ef9eb276b198e3060a27905cd5542c419
6
+ metadata.gz: 26a6cf153b5cb6c2fc0c12e1597ab4a77dd6ff52cf95fa90e9b636f684caf819e883677cfbe3d60a179f2f87c548be5a4f436c56f2e981b2691908163844628a
7
+ data.tar.gz: 2b2dcbaf7d2b0c41a7d9558af9b33c3e7eafa5b8986ec230fb31c74c916beb4912872f80ffa63f02eea9558c60f5e4723ee08d71ece1731ae8d107b5e847b990
@@ -9,6 +9,7 @@ require 'tmpdir'
9
9
  require 'yaml'
10
10
 
11
11
  # External gems
12
+ require 'concurrent-ruby'
12
13
  require 'json_schema'
13
14
  require 'ddmemoize'
14
15
  require 'ddmetrics'
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nanoc
4
+ module Core
5
+ class ChangesStream
6
+ class ChangesListener
7
+ def initialize(y)
8
+ @y = y
9
+ end
10
+
11
+ def unknown
12
+ @y << :unknown
13
+ end
14
+
15
+ def lib
16
+ @y << :lib
17
+ end
18
+
19
+ def to_stop(&block)
20
+ if block_given?
21
+ @to_stop = block
22
+ else
23
+ @to_stop
24
+ end
25
+ end
26
+ end
27
+
28
+ def initialize(enum: nil)
29
+ @enum = enum
30
+ @enum ||=
31
+ Enumerator.new do |y|
32
+ @listener = ChangesListener.new(y)
33
+ yield(@listener)
34
+ end.lazy
35
+ end
36
+
37
+ def stop
38
+ @listener&.to_stop&.call
39
+ end
40
+
41
+ def map
42
+ self.class.new(enum: @enum.map { |e| yield(e) })
43
+ end
44
+
45
+ def to_enum
46
+ @enum
47
+ end
48
+
49
+ def each
50
+ @enum.each { |e| yield(e) }
51
+ nil
52
+ end
53
+ end
54
+ end
55
+ end
@@ -64,7 +64,7 @@ module Nanoc
64
64
 
65
65
  @checksums = {}
66
66
  new_data.each_pair do |key, checksum|
67
- if references.include?(key) || references.include?(key.first)
67
+ if references.include?(key) || (key.respond_to?(:first) && references.include?(key.first))
68
68
  @checksums[key] = checksum
69
69
  end
70
70
  end
@@ -50,8 +50,8 @@ module Nanoc
50
50
  end
51
51
 
52
52
  def calc_for_each_attribute_of(obj, digest_class = CompactDigest)
53
- obj.attributes.each_with_object({}) do |(key, value), memo|
54
- memo[key] = Nanoc::Core::Checksummer.calc(value, digest_class)
53
+ obj.attributes.transform_values do |value|
54
+ Nanoc::Core::Checksummer.calc(value, digest_class)
55
55
  end
56
56
  end
57
57
 
@@ -3,6 +3,12 @@
3
3
  module Nanoc
4
4
  module Core
5
5
  class CompilationItemRepView < ::Nanoc::Core::BasicItemRepView
6
+ # How long to wait before the requested file appears.
7
+ #
8
+ # This is a bit of a hack -- ideally, Nanoc would know that the file is
9
+ # being generated, and wait the appropriate amount of time.
10
+ FILE_APPEAR_TIMEOUT = 10.0
11
+
6
12
  # @abstract
7
13
  def item_view_class
8
14
  Nanoc::Core::CompilationItemView
@@ -27,7 +33,7 @@ module Nanoc
27
33
  # Wait for file to exist
28
34
  if res
29
35
  start = Time.now
30
- sleep 0.05 until File.file?(res) || Time.now - start > 1.0
36
+ sleep 0.05 until File.file?(res) || Time.now - start > FILE_APPEAR_TIMEOUT
31
37
  raise Nanoc::Core::Errors::InternalInconsistency, "File did not apear in time: #{res}" unless File.file?(res)
32
38
  end
33
39
 
@@ -32,7 +32,7 @@ module Nanoc
32
32
  end
33
33
 
34
34
  contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
35
- def run(_rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
35
+ def run(_rep, is_outdated:)
36
36
  raise NotImplementedError
37
37
  end
38
38
 
@@ -21,7 +21,7 @@ module Nanoc
21
21
  raise(res)
22
22
  when Proc
23
23
  fiber.resume(res.call)
24
- when DONE # rubocop:disable Lint/EmptyWhen
24
+ when DONE
25
25
  # ignore
26
26
  else
27
27
  raise Nanoc::Core::Errors::InternalInconsistency.new(
@@ -6,45 +6,6 @@ module Nanoc
6
6
  class Write < Abstract
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
- class Worker
10
- def initialize(queue:, compiled_content_store:)
11
- @queue = queue
12
- @compiled_content_store = compiled_content_store
13
- end
14
-
15
- def start
16
- @thread = Thread.new do
17
- Thread.current.abort_on_exception = true
18
- Thread.current.priority = -1 # schedule I/O work ASAP
19
-
20
- writer = Nanoc::Core::ItemRepWriter.new
21
-
22
- while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
23
- writer.write_all(rep, @compiled_content_store)
24
- end
25
- end
26
- end
27
-
28
- def join
29
- @thread.join
30
- end
31
- end
32
-
33
- class WorkerPool
34
- def initialize(queue:, size:, compiled_content_store:)
35
- @workers = Array.new(size) { Worker.new(queue: queue, compiled_content_store: compiled_content_store) }
36
- end
37
-
38
- def start
39
- @workers.each(&:start)
40
- end
41
-
42
- def join
43
- @workers.each(&:join)
44
- end
45
- end
46
-
47
- QUEUE_SIZE = 40
48
9
  WORKER_POOL_SIZE = 5
49
10
 
50
11
  def initialize(compiled_content_store:, wrapped:)
@@ -52,19 +13,16 @@ module Nanoc
52
13
 
53
14
  @compiled_content_store = compiled_content_store
54
15
 
55
- @queue = SizedQueue.new(QUEUE_SIZE)
56
- @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, compiled_content_store: @compiled_content_store)
57
- end
16
+ @pool = Concurrent::FixedThreadPool.new(WORKER_POOL_SIZE)
58
17
 
59
- def start
60
- super
61
- @worker_pool.start
18
+ @writer = Nanoc::Core::ItemRepWriter.new
62
19
  end
63
20
 
64
21
  def stop
22
+ @pool.shutdown
23
+ @pool.wait_for_termination
24
+
65
25
  super
66
- @queue.close
67
- @worker_pool.join
68
26
  end
69
27
 
70
28
  contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
@@ -76,7 +34,9 @@ module Nanoc
76
34
  # notification happens before the :rep_write_enqueued one.
77
35
  Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)
78
36
 
79
- @queue << rep
37
+ @pool.post do
38
+ @writer.write_all(rep, @compiled_content_store)
39
+ end
80
40
  end
81
41
  end
82
42
  end
@@ -46,8 +46,8 @@ module Nanoc
46
46
  @binary_cache[rep] = content.select { |_key, c| c.binary? }
47
47
  end
48
48
 
49
- def prune(*args)
50
- @wrapped_caches.each { |w| w.prune(*args) }
49
+ def prune(items:)
50
+ @wrapped_caches.each { |w| w.prune(items: items) }
51
51
  end
52
52
 
53
53
  # True if there is cached compiled content available for this item, and
@@ -32,7 +32,7 @@ module Nanoc
32
32
  outdatedness_store: outdatedness_store,
33
33
  }
34
34
 
35
- Nanoc::Core::Compiler.new(site, params)
35
+ Nanoc::Core::Compiler.new(site, **params)
36
36
  end
37
37
 
38
38
  def compiled_content_cache_class
@@ -103,6 +103,8 @@ module Nanoc
103
103
  ::Contracts.const_set('Named', EnabledContracts::Named)
104
104
  ::Contracts.const_set('IterOf', EnabledContracts::IterOf)
105
105
  ::Contracts.const_set('AbsolutePathString', EnabledContracts::AbsolutePathString)
106
+
107
+ warn_about_performance
106
108
  end
107
109
 
108
110
  @_contracts_support__should_enable
@@ -126,6 +128,24 @@ module Nanoc
126
128
  base.const_set('C', DisabledContracts)
127
129
  end
128
130
  end
131
+
132
+ def self.warn_about_performance
133
+ return if ENV.key?('CI')
134
+ return if ENV.key?('NANOC_DEV_MODE')
135
+
136
+ puts '-' * 78
137
+ puts 'A NOTE ABOUT PERFORMANCE:'
138
+ puts 'The `contracts` gem is loaded, which enables extra run-time checks, but can drastically reduce Nanoc’s performance. The `contracts` gem is intended for development purposes, and is not recommended for day-to-day Nanoc usage.'
139
+ puts
140
+
141
+ if defined?(Bundler)
142
+ puts 'To speed up compilation, remove `contracts` from the Gemfile and run `bundle install`.'
143
+ else
144
+ puts 'To speed up compilation, either uninstall the `contracts` gem, or use Bundler (https://bundler.io/) with a Gemfile that doesn’t include `contracts`.'
145
+ end
146
+
147
+ puts '-' * 78
148
+ end
129
149
  end
130
150
  end
131
151
  end
@@ -113,7 +113,7 @@ module Nanoc
113
113
  src_ref = obj2ref(src)
114
114
  dst_ref = obj2ref(dst)
115
115
 
116
- existing_props = Nanoc::Core::DependencyProps.new(@graph.props_for(dst_ref, src_ref) || {})
116
+ existing_props = Nanoc::Core::DependencyProps.new(**(@graph.props_for(dst_ref, src_ref) || {}))
117
117
  new_props = Nanoc::Core::DependencyProps.new(raw_content: raw_content, attributes: attributes, compiled_content: compiled_content, path: path)
118
118
  props = existing_props.merge(new_props)
119
119
 
@@ -184,8 +184,8 @@ module Nanoc
184
184
  @graph = Nanoc::Core::DirectedGraph.new([nil] + refs)
185
185
 
186
186
  # Load vertices
187
- previous_refs = new_data[:vertices]
188
- previous_objects = Set.new(refs2objs(previous_refs))
187
+ previous_objects = refs2objs(new_data[:vertices])
188
+ previous_refs = objs2refs(previous_objects)
189
189
 
190
190
  # Load edges
191
191
  new_data[:edges].each do |edge|
@@ -88,6 +88,17 @@ module Nanoc
88
88
  end
89
89
  end
90
90
 
91
+ # Error that is raised during site compilation when a layout is compiled
92
+ # for which the filter cannot be determined. This is similar to the
93
+ # {UnknownFilter} error, but specific for filters for layouts.
94
+ class CannotDetermineFilter < ::Nanoc::Core::Error
95
+ # @param [String] layout_identifier The identifier of the layout for
96
+ # which the filter could not be determined
97
+ def initialize(layout_identifier)
98
+ super("The filter to be used for the “#{layout_identifier}” layout could not be determined. Make sure the layout does have a filter.")
99
+ end
100
+ end
101
+
91
102
  # Error that is raised when the compiled content of a binary item is attempted to be accessed.
92
103
  class CannotGetCompiledContentOfBinaryItem < ::Nanoc::Core::Error
93
104
  # @param [Nanoc::Core::ItemRep] rep The binary item representation whose compiled content was attempted to be accessed
@@ -39,7 +39,7 @@ module Nanoc
39
39
  filter_name_and_args = @compilation_context.filter_name_and_args_for_layout(layout)
40
40
  filter_name = filter_name_and_args.name
41
41
  if filter_name.nil?
42
- raise ::Nanoc::Core::Error, "Cannot find rule for layout matching #{layout_identifier}"
42
+ raise Nanoc::Core::Errors::CannotDetermineFilter.new(layout_identifier)
43
43
  end
44
44
 
45
45
  filter_args = filter_name_and_args.args
@@ -111,8 +111,12 @@ module Nanoc
111
111
  end
112
112
 
113
113
  def log_delete_and_run(thing)
114
- Nanoc::Core::NotificationCenter.post(:file_pruned, thing)
115
- yield unless @dry_run
114
+ if @dry_run
115
+ Nanoc::Core::NotificationCenter.post(:file_listed_for_pruning, thing)
116
+ else
117
+ Nanoc::Core::NotificationCenter.post(:file_pruned, thing)
118
+ yield
119
+ end
116
120
  end
117
121
  end
118
122
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.11.13'
5
+ VERSION = '4.11.18'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.13
4
+ version: 4.11.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-02 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: ddmemoize
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +171,7 @@ files:
157
171
  - lib/nanoc/core/basic_item_view.rb
158
172
  - lib/nanoc/core/binary_compiled_content_cache.rb
159
173
  - lib/nanoc/core/binary_content.rb
174
+ - lib/nanoc/core/changes_stream.rb
160
175
  - lib/nanoc/core/checksum_collection.rb
161
176
  - lib/nanoc/core/checksum_store.rb
162
177
  - lib/nanoc/core/checksummer.rb
@@ -299,7 +314,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
314
  - !ruby/object:Gem::Version
300
315
  version: '0'
301
316
  requirements: []
302
- rubygems_version: 3.0.6
317
+ rubygems_version: 3.1.4
303
318
  signing_key:
304
319
  specification_version: 4
305
320
  summary: Core of Nanoc