metanorma-plugin-lutaml 0.7.92 → 0.7.94
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/docs/usages/enterprise_architect.adoc +64 -0
- data/lib/metanorma/plugin/lutaml/ea_xmi_slicer_compat.rb +136 -0
- data/lib/metanorma/plugin/lutaml/express_remark_adapter.rb +37 -0
- data/lib/metanorma/plugin/lutaml/lutaml_data_preprocessor.rb +2 -0
- data/lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb +1 -0
- data/lib/metanorma/plugin/lutaml/version.rb +1 -1
- data/lib/metanorma/plugin/lutaml/xmi_cache.rb +3 -3
- data/lib/metanorma/plugin/lutaml/xmi_parse_cache.rb +5 -0
- data/lib/metanorma/plugin/lutaml/xmi_partial_load_registry.rb +89 -18
- data/lib/metanorma-plugin-lutaml.rb +6 -0
- data/metanorma-plugin-lutaml.gemspec +5 -7
- metadata +5 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a034f4429bf6f4afb9c76c699297b7f6980c15a67db07d46c58ef186c6b06e8
|
|
4
|
+
data.tar.gz: e971918f21c4a71c927579982dadf1ea51de2954adabaed48f4022bf253472da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 55d91d7076114b5bef00f5369c509ac4e09e53e4ea46ef9ccd15ae92ce6673614e9e729e5e5a5da3af840f6851180a43831e7dafc1d3741f4eb4a434d4ffff5d
|
|
7
|
+
data.tar.gz: 5fbb0f8aec6d642b26fd7da3b107aae119421ee085cbc13f444ca7baca4d277637033b265da6b16b78c4b204812256596312dd12a9e50df552815f644db28f1b
|
data/Rakefile
CHANGED
|
@@ -15,6 +15,7 @@ XMI_SPEC_FILES = %w[
|
|
|
15
15
|
spec/metanorma/plugin/lutaml/lutaml_enum_table_block_macro_spec.rb
|
|
16
16
|
spec/metanorma/plugin/lutaml/lutaml_xmi_index_spec.rb
|
|
17
17
|
spec/metanorma/plugin/lutaml/lutaml_xmi_uml_preprocessor_spec.rb
|
|
18
|
+
spec/metanorma/plugin/lutaml/xmi_partial_load_registry_spec.rb
|
|
18
19
|
].freeze
|
|
19
20
|
|
|
20
21
|
# The diagram/GML/XSD/Liquid-rendering families each leave 25-70 MB of
|
|
@@ -10,6 +10,62 @@ The commands are prefixed as `lutaml_ea_*` to denote their specific use with
|
|
|
10
10
|
Enterprise Architect XMI files.
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
[[partial-xmi-loading]]
|
|
14
|
+
=== Partial loading of XMI sources for the table macros
|
|
15
|
+
|
|
16
|
+
The `lutaml_klass_table` and `lutaml_enum_table` commands load their XMI
|
|
17
|
+
sources partially by default: only the subgraph reachable from the classes
|
|
18
|
+
named by the document's table macros is parsed, instead of the whole export.
|
|
19
|
+
|
|
20
|
+
Enterprise Architect exports of large models can reach ~100 MB, more than
|
|
21
|
+
half of it diagram presentation data that no definition table reads, and
|
|
22
|
+
fully materializing such an export costs 10+ GB of live objects, which is
|
|
23
|
+
more than a standard build runner provides. With partial loading, each table
|
|
24
|
+
macro parses only the slice of the source that its class needs. Nothing is
|
|
25
|
+
written to disk.
|
|
26
|
+
|
|
27
|
+
Sources smaller than 2 MB are whole-loaded: slicing them costs more than
|
|
28
|
+
parsing them.
|
|
29
|
+
|
|
30
|
+
A document can opt out of partial loading with the `lutaml-ea-xmi-load`
|
|
31
|
+
document attribute:
|
|
32
|
+
|
|
33
|
+
[source,adoc]
|
|
34
|
+
----
|
|
35
|
+
:lutaml-ea-xmi-load: whole
|
|
36
|
+
----
|
|
37
|
+
|
|
38
|
+
Without the attribute, partial loading engages. The `whole` value restores
|
|
39
|
+
the load of the full source for the document.
|
|
40
|
+
|
|
41
|
+
When a table macro's class cannot be resolved into any slice, the macro
|
|
42
|
+
falls back to loading the whole source. For a source at or above the 2 MB
|
|
43
|
+
threshold, this fallback emits a warning through the Asciidoctor logger that
|
|
44
|
+
names the document, the class and the source path, because whole-loading a
|
|
45
|
+
plateau-scale export can exhaust the memory of the build runner:
|
|
46
|
+
|
|
47
|
+
[source,console]
|
|
48
|
+
----
|
|
49
|
+
WARN -- : [metanorma-plugin-lutaml] lutaml-ea-xmi-load is partial by default, but no slice was prepared for class "Ghost" (NoSuchPackageAnywhere::Ghost) in /path/to/example.xmi: document /path/to/document.adoc whole-loads the 98.0 MB source, the memory-death path on plateau-scale corpora. Check the macro's name and package options, or set :lutaml-ea-xmi-load: whole to acknowledge the whole load.
|
|
50
|
+
----
|
|
51
|
+
|
|
52
|
+
[example]
|
|
53
|
+
.Opting out of partial loading for one document
|
|
54
|
+
====
|
|
55
|
+
[source,adoc]
|
|
56
|
+
----
|
|
57
|
+
= My specification
|
|
58
|
+
Author
|
|
59
|
+
:lutaml-ea-xmi-load: whole
|
|
60
|
+
|
|
61
|
+
lutaml_klass_table::/path/to/example.xmi[name="NameOfClass"]
|
|
62
|
+
----
|
|
63
|
+
|
|
64
|
+
The `lutaml_klass_table` command loads the full `/path/to/example.xmi`
|
|
65
|
+
source instead of the slice for `NameOfClass`.
|
|
66
|
+
====
|
|
67
|
+
|
|
68
|
+
|
|
13
69
|
=== Document attribute `:lutaml-xmi-index:`
|
|
14
70
|
|
|
15
71
|
This attribute allows specifying one or more XMI files to define names
|
|
@@ -196,6 +252,10 @@ The command accepts the options listed below:
|
|
|
196
252
|
* `guidance="/path/to/my_guidance.yml"` specifies the path of
|
|
197
253
|
the yaml file of the guidance. (Optional)
|
|
198
254
|
|
|
255
|
+
NOTE: The XMI source is loaded partially by default; only the subgraph
|
|
256
|
+
reachable from the class named by the macro is parsed. See
|
|
257
|
+
<<partial-xmi-loading>>.
|
|
258
|
+
|
|
199
259
|
The guidance file should be in the following format:
|
|
200
260
|
|
|
201
261
|
[source,yaml]
|
|
@@ -266,6 +326,10 @@ The command accepts the options listed below:
|
|
|
266
326
|
(e.g. `my_data` or `second_data` in the above example)
|
|
267
327
|
The external data file should be in YAML/JSON format.
|
|
268
328
|
|
|
329
|
+
NOTE: The XMI source is loaded partially by default; only the subgraph
|
|
330
|
+
reachable from the enumeration named by the macro is parsed. See
|
|
331
|
+
<<partial-xmi-loading>>.
|
|
332
|
+
|
|
269
333
|
=== Usage of `lutaml_ea_xmi` command
|
|
270
334
|
|
|
271
335
|
The `lutaml_ea_xmi` command performs the same function as the
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Carries the Ea::Xmi::Slicer primitive-types closure fix from
|
|
4
|
+
# lutaml/ea#280 until a released ea ships it (the change lands upstream
|
|
5
|
+
# in lutaml/ea; this shim retires on the first ea release that contains
|
|
6
|
+
# it). Without it the slicer's reference closure drops EA's primitive
|
|
7
|
+
# types: they live in the extension's <primitivetypes> block, which
|
|
8
|
+
# section_for maps to :drop, and their ids carry the EAJava_ prefix,
|
|
9
|
+
# which the slicer's EA_ID_RE does not match. A sliced klass table of
|
|
10
|
+
# a class whose inherited attributes reference gml::/xs:: primitives
|
|
11
|
+
# then renders the raw id (EAJava_gml__LengthType) where the
|
|
12
|
+
# whole-load path renders the type name (gml::LengthType) - the
|
|
13
|
+
# byte-parity gap the corpus gate exists to catch.
|
|
14
|
+
#
|
|
15
|
+
# Three pieces, mirroring the upstream change:
|
|
16
|
+
# - EA_ID_RE recognizes the EAJava_ id prefix, so references to the
|
|
17
|
+
# primitives are collected;
|
|
18
|
+
# - the extension's primitivetypes/profiles blocks map to a gated
|
|
19
|
+
# :primitivetypes section instead of :drop, so referenced entries
|
|
20
|
+
# become keepable nodes;
|
|
21
|
+
# - closure keeps the ancestry of kept :primitivetypes nodes, so the
|
|
22
|
+
# EA_PrimitiveTypes_Package wrappers survive the writer's
|
|
23
|
+
# parent-key chain.
|
|
24
|
+
module Ea
|
|
25
|
+
module Xmi
|
|
26
|
+
class Slicer
|
|
27
|
+
# The released slicer fix redefines EA_ID_RE with the EAJava_
|
|
28
|
+
# alternative; when it is present, the whole shim retires.
|
|
29
|
+
unless EA_ID_RE.source.include?("EAJava")
|
|
30
|
+
remove_const :EA_ID_RE
|
|
31
|
+
EA_ID_RE = /\A(?:EAID|EAPK|EAEM|EAJava)_[0-9A-Za-z_]+\z/
|
|
32
|
+
private_constant :EA_ID_RE
|
|
33
|
+
|
|
34
|
+
remove_const :GATED
|
|
35
|
+
GATED = {
|
|
36
|
+
model: ["packagedElement", "umldi:Diagram"].freeze,
|
|
37
|
+
elements: ["element"].freeze,
|
|
38
|
+
connectors: ["connector"].freeze,
|
|
39
|
+
primitivetypes: ["packagedElement"].freeze,
|
|
40
|
+
diagrams: ["diagram"].freeze,
|
|
41
|
+
}.freeze
|
|
42
|
+
private_constant :GATED
|
|
43
|
+
|
|
44
|
+
remove_const :SECTION_CHILD
|
|
45
|
+
SECTION_CHILD = {
|
|
46
|
+
"elements" => :elements,
|
|
47
|
+
"connectors" => :connectors,
|
|
48
|
+
"primitivetypes" => :primitivetypes,
|
|
49
|
+
"profiles" => :primitivetypes,
|
|
50
|
+
"diagrams" => :drop,
|
|
51
|
+
}.freeze
|
|
52
|
+
private_constant :SECTION_CHILD
|
|
53
|
+
|
|
54
|
+
class IndexHandler
|
|
55
|
+
def section_for(name, current)
|
|
56
|
+
return :model if name == "uml:Model"
|
|
57
|
+
return :extension if name == "xmi:Extension"
|
|
58
|
+
|
|
59
|
+
if current == :extension
|
|
60
|
+
SECTION_CHILD.fetch(name, :drop)
|
|
61
|
+
elsif current == :drop
|
|
62
|
+
:drop
|
|
63
|
+
else
|
|
64
|
+
current
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class GroupWriter
|
|
70
|
+
def section_for(name, current)
|
|
71
|
+
return :model if name == "uml:Model"
|
|
72
|
+
return :extension if name == "xmi:Extension"
|
|
73
|
+
|
|
74
|
+
if current == :extension
|
|
75
|
+
SECTION_CHILD.fetch(name, :drop)
|
|
76
|
+
elsif current == :drop
|
|
77
|
+
:drop
|
|
78
|
+
else
|
|
79
|
+
current
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The slicer's closure with one extension: kept
|
|
85
|
+
# :primitivetypes nodes keep their package ancestry, exactly
|
|
86
|
+
# as :model nodes do - the writer's parent-key chain drops
|
|
87
|
+
# children of unkept gated containers, so the
|
|
88
|
+
# EA_PrimitiveTypes_Package wrappers have to be kept for a
|
|
89
|
+
# referenced primitive to reach the slice. The method mirrors
|
|
90
|
+
# the upstream one (whose Metrics allowances are grandfathered
|
|
91
|
+
# in the ea gem) plus the single ancestry extension.
|
|
92
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
93
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
94
|
+
# rubocop:disable Metrics/BlockNesting
|
|
95
|
+
ANCESTRY_SECTIONS = %i[model primitivetypes].freeze
|
|
96
|
+
private_constant :ANCESTRY_SECTIONS
|
|
97
|
+
|
|
98
|
+
def closure(nodes, seeds)
|
|
99
|
+
keep = {}
|
|
100
|
+
frontier = seeds.map { |i| [i, false] }
|
|
101
|
+
until frontier.empty?
|
|
102
|
+
id, via_links = frontier.pop
|
|
103
|
+
next if keep[id]
|
|
104
|
+
|
|
105
|
+
node = nodes[id]
|
|
106
|
+
next unless node
|
|
107
|
+
# links references only buy the connector record they name;
|
|
108
|
+
# following them further pulled every relation's endpoints
|
|
109
|
+
# into a class's closure (half the model per class)
|
|
110
|
+
next if via_links && node.section != :connectors
|
|
111
|
+
|
|
112
|
+
keep[id] = true
|
|
113
|
+
node.refs.each { |r| frontier << [r, false] }
|
|
114
|
+
node.links_refs.each { |r| frontier << [r, true] }
|
|
115
|
+
# keeping a model element keeps its package ancestry
|
|
116
|
+
next unless ANCESTRY_SECTIONS.include?(node.section)
|
|
117
|
+
|
|
118
|
+
anc = nodes[node.parent_id]
|
|
119
|
+
while anc && !keep[anc.id]
|
|
120
|
+
keep[anc.id] = true
|
|
121
|
+
unless anc.section == :model
|
|
122
|
+
anc.refs.each { |r| frontier << [r, false] }
|
|
123
|
+
end
|
|
124
|
+
anc = nodes[anc.parent_id]
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
keep_diagrams(nodes, keep)
|
|
128
|
+
keep
|
|
129
|
+
end
|
|
130
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
|
131
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
132
|
+
# rubocop:enable Metrics/BlockNesting
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -277,14 +277,29 @@ module Metanorma
|
|
|
277
277
|
end
|
|
278
278
|
|
|
279
279
|
class RepoAdapter < Base
|
|
280
|
+
# Decorating a schema stages its EXPRESS-G figures into the
|
|
281
|
+
# document's image folder. A block that selects the schemas it
|
|
282
|
+
# covers (config_yaml) renders only those (ordered_schemas), so
|
|
283
|
+
# only those are decorated: decorating the whole index copied
|
|
284
|
+
# every figure of every indexed schema into the folder.
|
|
280
285
|
def decorate_remarks(options)
|
|
286
|
+
selected = options["selected_schemas"]
|
|
281
287
|
@model.schemas.each do |schema|
|
|
288
|
+
next if selected && !selected_schema?(schema, selected)
|
|
289
|
+
|
|
282
290
|
ExpressRemarkAdapter.for(schema).decorate_remarks(options)
|
|
283
291
|
end
|
|
284
292
|
end
|
|
285
293
|
|
|
286
294
|
private
|
|
287
295
|
|
|
296
|
+
# The match reorder_schemas uses for the rendered selection.
|
|
297
|
+
def selected_schema?(schema, selected)
|
|
298
|
+
selected.any? do |name|
|
|
299
|
+
schema.id == name || schema.file_basename == name
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
288
303
|
# NO document-level imagesdir here: metanorma's figure
|
|
289
304
|
# absolutization joins document.attributes["imagesdir"] with
|
|
290
305
|
# svgmap-synthesized targets that are ALREADY document-relative
|
|
@@ -328,12 +343,28 @@ module Metanorma
|
|
|
328
343
|
# remark-bearing form of the same faces — for the models this
|
|
329
344
|
# adapter decorates only; undecorated prints keep expressir's
|
|
330
345
|
# plain faces.
|
|
346
|
+
#
|
|
347
|
+
# The base face's round-trip form prints every remark item's
|
|
348
|
+
# raw tag (`(*"schema.entity.__note" text *)`), but keyed prose
|
|
349
|
+
# items print through the document's note machinery, not the
|
|
350
|
+
# listing — so the faces drop the keyed __note/__example items
|
|
351
|
+
# (metanorma-plugin-lutaml#429, the iso-10303 gate regression)
|
|
352
|
+
# and keep the keyed __figure blocks, which stage the
|
|
353
|
+
# EXPRESS-G figures.
|
|
354
|
+
KEYED_PROSE_ITEM = /__(?:note|example)\z/.freeze
|
|
355
|
+
|
|
331
356
|
class DocumentSourceFormatter < Expressir::Express::Formatter
|
|
332
357
|
include Expressir::Express::HyperlinkFormatter
|
|
333
358
|
|
|
334
359
|
def owner_tagged_blocks?
|
|
335
360
|
false
|
|
336
361
|
end
|
|
362
|
+
|
|
363
|
+
def format_remark_item(node)
|
|
364
|
+
return "" if node.id.to_s.match?(KEYED_PROSE_ITEM)
|
|
365
|
+
|
|
366
|
+
super
|
|
367
|
+
end
|
|
337
368
|
end
|
|
338
369
|
|
|
339
370
|
class DocumentAdocSourceFormatter < Expressir::Express::Formatter
|
|
@@ -342,6 +373,12 @@ module Metanorma
|
|
|
342
373
|
def owner_tagged_blocks?
|
|
343
374
|
false
|
|
344
375
|
end
|
|
376
|
+
|
|
377
|
+
def format_remark_item(node)
|
|
378
|
+
return "" if node.id.to_s.match?(KEYED_PROSE_ITEM)
|
|
379
|
+
|
|
380
|
+
super
|
|
381
|
+
end
|
|
345
382
|
end
|
|
346
383
|
|
|
347
384
|
# The adoc face's post-formatting chain, mirroring
|
|
@@ -66,6 +66,7 @@ module Metanorma
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def load_lutaml_file(_document, file_path, _options)
|
|
69
|
+
require "lutaml/lml"
|
|
69
70
|
::Lutaml::Lml.parse_document(File.new(file_path, encoding: "UTF-8"))
|
|
70
71
|
end
|
|
71
72
|
|
|
@@ -149,6 +150,7 @@ module Metanorma
|
|
|
149
150
|
)
|
|
150
151
|
end
|
|
151
152
|
|
|
153
|
+
require "lutaml/lml"
|
|
152
154
|
compiler = ::Lutaml::Lml::ModelCompiler.new
|
|
153
155
|
compiler.compile(File.new(definition_path, encoding: "UTF-8"))
|
|
154
156
|
instances = load_instances(instances_path, compiler)
|
|
@@ -36,6 +36,7 @@ module Metanorma
|
|
|
36
36
|
::Expressir::Express::Parser.from_file(full_path)
|
|
37
37
|
end
|
|
38
38
|
else
|
|
39
|
+
require "lutaml/lml"
|
|
39
40
|
file = File.new(full_path, encoding: "UTF-8")
|
|
40
41
|
# The lutaml monogem front door (lutaml-lml >= 0.3.8 shims it):
|
|
41
42
|
# Source.wrap reads the File's contents and carries its path for
|
|
@@ -7,9 +7,9 @@ module Metanorma
|
|
|
7
7
|
module Lutaml
|
|
8
8
|
module XmiCache
|
|
9
9
|
# Bounded parse-once cache: every macro touching a source (the
|
|
10
|
-
# full file, or its package slice under
|
|
11
|
-
# reuses the one parsed graph; the LRU bound keeps the
|
|
12
|
-
# graphs to a few live at once, which the section-ordered
|
|
10
|
+
# full file, or its package slice under the default partial
|
|
11
|
+
# XMI load) reuses the one parsed graph; the LRU bound keeps the
|
|
12
|
+
# retained graphs to a few live at once, which the section-ordered
|
|
13
13
|
# macros of a document turn into near-perfect reuse.
|
|
14
14
|
XMI_PARSE_CACHE = XmiParseCache.new(max_size: 4)
|
|
15
15
|
|
|
@@ -55,6 +55,11 @@ module Metanorma
|
|
|
55
55
|
if slice
|
|
56
56
|
xml = XmiPartialLoadRegistry.slice_string(slice)
|
|
57
57
|
::Ea::Xmi.load_graph(StringIO.new(xml))
|
|
58
|
+
elsif full_path.downcase.end_with?(".qea")
|
|
59
|
+
# Ea-native lazy rendering (#278): .qea sources feed the
|
|
60
|
+
# klass-table drops straight from the SQLite rows — no XMI
|
|
61
|
+
# graph materialization.
|
|
62
|
+
::Ea::Qea::LazyDrops.parsed_graph(full_path)
|
|
58
63
|
else
|
|
59
64
|
::Ea::Xmi.load_graph(full_path)
|
|
60
65
|
end
|
|
@@ -12,32 +12,44 @@ module Metanorma
|
|
|
12
12
|
# EA exports of plateau scale reach ~100 MB, more than half of it
|
|
13
13
|
# diagram presentation data, and fully materializing the Xmi tree
|
|
14
14
|
# plus the Ea graph costs 10+ GB of live objects - more than a
|
|
15
|
-
# standard build runner has.
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
15
|
+
# standard build runner has. Partial loading is the default: every
|
|
16
|
+
# klass and enum table macro's (package, name) pair seeds a
|
|
17
|
+
# per-package reference closure; one streaming pass per source
|
|
18
|
+
# assembles the closures in memory and each macro parses only its
|
|
19
|
+
# own package's slice. Sources smaller than MIN_SOURCE_BYTES are
|
|
20
|
+
# whole-loaded - slicing them costs more than parsing them.
|
|
21
|
+
# Nothing is written to disk.
|
|
21
22
|
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
23
|
+
# A document opts out with the `lutaml-ea-xmi-load` document
|
|
24
|
+
# attribute set to `whole`; without any attribute the partial
|
|
25
|
+
# path engages, and with the opt-out the behavior is byte-for-byte
|
|
26
|
+
# the whole-load path.
|
|
27
|
+
#
|
|
28
|
+
# When a macro's (path, name) resolves to no slice in an engaged
|
|
29
|
+
# document and the source is large enough that whole-loading it is
|
|
30
|
+
# the memory-death path, a warning through the Asciidoctor logger
|
|
31
|
+
# names the document, the class and the source: a silent fallback
|
|
32
|
+
# here hides an out-of-memory behind an apparently successful
|
|
33
|
+
# build.
|
|
24
34
|
module XmiPartialLoadRegistry
|
|
25
35
|
MACRO_REGEXP = /lutaml_(?:klass|enum)_table::([^\[<]+)\[([^\]]*)\]/
|
|
26
36
|
MIN_SOURCE_BYTES = 2 * 1024 * 1024
|
|
37
|
+
WHOLE_LOAD_REGEXP = /\A:lutaml-ea-xmi-load:\s*whole\s*$/
|
|
27
38
|
|
|
28
39
|
class << self
|
|
29
40
|
# Rewrites (xmi_path, name_path) to the partial-load form of
|
|
30
41
|
# the macro's class: [path, bare name, slice token]. The
|
|
31
42
|
# token is nil when no slice was prepared, in which case the
|
|
32
|
-
# macro whole-loads the source unchanged
|
|
43
|
+
# macro whole-loads the source unchanged - warned about when
|
|
44
|
+
# the document is engaged and the source is large.
|
|
33
45
|
def rewrite(xmi_path, name_path)
|
|
34
46
|
return [xmi_path, name_path, nil] unless @registry
|
|
35
47
|
|
|
36
48
|
entry = @registry[xmi_path]
|
|
37
|
-
return
|
|
49
|
+
return whole_load_fallback(xmi_path, name_path) unless entry
|
|
38
50
|
|
|
39
51
|
group_key = entry[name_path] || entry[bare_name(name_path)]
|
|
40
|
-
return
|
|
52
|
+
return whole_load_fallback(xmi_path, name_path) unless group_key
|
|
41
53
|
|
|
42
54
|
[xmi_path, bare_name(name_path), [xmi_path, group_key]]
|
|
43
55
|
end
|
|
@@ -57,17 +69,33 @@ module Metanorma
|
|
|
57
69
|
def reset!
|
|
58
70
|
@registry = nil
|
|
59
71
|
@slices = nil
|
|
72
|
+
@docfile = nil
|
|
73
|
+
@whole_load_warned = []
|
|
60
74
|
end
|
|
61
75
|
|
|
62
76
|
def prepare(document, lines) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
unless enabled?(document, lines)
|
|
78
|
+
# an explicit opt-out is a main-document decision; drop
|
|
79
|
+
# any slices a previous document left behind
|
|
80
|
+
reset!
|
|
81
|
+
return
|
|
82
|
+
end
|
|
67
83
|
|
|
68
84
|
groups = collect_groups(document, lines)
|
|
69
|
-
|
|
85
|
+
if groups.empty?
|
|
86
|
+
# standoc re-parses attribute snippets (asciidoc_sub titles
|
|
87
|
+
# and friends) as one-line documents mid-conversion; the
|
|
88
|
+
# global extension registry runs this preprocessor on those
|
|
89
|
+
# fragments too. They carry no table macros and must not
|
|
90
|
+
# wipe the slices prepared for the enclosing document, so
|
|
91
|
+
# only a macro-less main document - one carrying the
|
|
92
|
+
# docfile attribute - drops stale slices.
|
|
93
|
+
reset! if document.attributes["docfile"]
|
|
94
|
+
return
|
|
95
|
+
end
|
|
70
96
|
|
|
97
|
+
reset!
|
|
98
|
+
@docfile = document.attributes["docfile"]
|
|
71
99
|
@registry = {}
|
|
72
100
|
@slices = {}
|
|
73
101
|
groups.each do |path, entries|
|
|
@@ -99,8 +127,51 @@ module Metanorma
|
|
|
99
127
|
private
|
|
100
128
|
|
|
101
129
|
def enabled?(document, lines)
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
return false if
|
|
131
|
+
document.attributes["lutaml-ea-xmi-load"] == "whole"
|
|
132
|
+
return false if lines.any? { |l| l.match?(WHOLE_LOAD_REGEXP) }
|
|
133
|
+
|
|
134
|
+
true
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# The whole-load fallback triple, preceded by the loud
|
|
138
|
+
# warning on an engaged document with a large source:
|
|
139
|
+
# silently whole-loading a plateau-scale export is the
|
|
140
|
+
# build runner's out-of-memory.
|
|
141
|
+
def whole_load_fallback(xmi_path, name_path)
|
|
142
|
+
notify_whole_load_fallback(xmi_path, name_path)
|
|
143
|
+
[xmi_path, name_path, nil]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def notify_whole_load_fallback(xmi_path, name_path)
|
|
147
|
+
return unless whole_load_risk?(xmi_path)
|
|
148
|
+
|
|
149
|
+
warned = [xmi_path, name_path]
|
|
150
|
+
return if @whole_load_warned.include?(warned)
|
|
151
|
+
|
|
152
|
+
@whole_load_warned << warned
|
|
153
|
+
::Asciidoctor::LoggerManager.logger.warn(
|
|
154
|
+
"[metanorma-plugin-lutaml] lutaml-ea-xmi-load is partial " \
|
|
155
|
+
"by default, but no slice was prepared for class " \
|
|
156
|
+
"\"#{bare_name(name_path)}\" (#{name_path}) in " \
|
|
157
|
+
"#{xmi_path}: #{document_label} whole-loads the " \
|
|
158
|
+
"#{megabytes(xmi_path)} MB source, the memory-death path " \
|
|
159
|
+
"on plateau-scale corpora. Check the macro's name and " \
|
|
160
|
+
"package options, or set :lutaml-ea-xmi-load: whole to " \
|
|
161
|
+
"acknowledge the whole load.",
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def whole_load_risk?(xmi_path)
|
|
166
|
+
File.file?(xmi_path) && File.size(xmi_path) >= MIN_SOURCE_BYTES
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def document_label
|
|
170
|
+
@docfile ? "document #{@docfile}" : "the document"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def megabytes(xmi_path)
|
|
174
|
+
(File.size(xmi_path).to_f / (1024 * 1024)).round(1)
|
|
104
175
|
end
|
|
105
176
|
|
|
106
177
|
# Slices are grouped per package, not per class: the tables
|
|
@@ -100,3 +100,9 @@ if defined?(Metanorma::Collection::Renderer) &&
|
|
|
100
100
|
.respond_to?(:register_reference_anchor_resolver)
|
|
101
101
|
require "metanorma/plugin/lutaml/express_hotspot_anchor"
|
|
102
102
|
end
|
|
103
|
+
|
|
104
|
+
# Eager: patches the loaded Ea::Xmi::Slicer in place (constant and
|
|
105
|
+
# method overrides, a load-time side effect). Carries the primitive
|
|
106
|
+
# types closure fix until a released ea ships it; the shim retires on
|
|
107
|
+
# its own once the released slicer carries the fix.
|
|
108
|
+
require "metanorma/plugin/lutaml/ea_xmi_slicer_compat"
|
|
@@ -45,13 +45,11 @@ Gem::Specification.new do |spec|
|
|
|
45
45
|
spec.add_dependency "liquid", "~> 5"
|
|
46
46
|
spec.add_dependency "lutaml-graphviz"
|
|
47
47
|
spec.add_dependency "lutaml-jsonschema", "~> 0.1", ">= 0.1.29"
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
|
|
53
|
-
spec.add_dependency "lutaml-lml", ">= 0.3.8"
|
|
54
|
-
spec.add_dependency "lutaml-model", "~> 0.8.159"
|
|
48
|
+
# The LML language core ships inside lutaml-model (>= 0.8.188, the
|
|
49
|
+
# lutaml-lml subsume); the retired lutaml-lml shim dependency drops.
|
|
50
|
+
# `lutaml/lml` resolves from lutaml-model's tree with the same
|
|
51
|
+
# require path.
|
|
52
|
+
spec.add_dependency "lutaml-model", "~> 0.8.188"
|
|
55
53
|
# >= 1.0.4: Lutaml::Uml::Value#initial (enum literal codes) — required by
|
|
56
54
|
# ea >= 0.6.151+ which writes initial values during XMI parsing.
|
|
57
55
|
spec.add_dependency "lutaml-uml", "~> 1.0", ">= 1.0.4"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-plugin-lutaml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.94
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -156,34 +156,20 @@ dependencies:
|
|
|
156
156
|
- - ">="
|
|
157
157
|
- !ruby/object:Gem::Version
|
|
158
158
|
version: 0.1.29
|
|
159
|
-
- !ruby/object:Gem::Dependency
|
|
160
|
-
name: lutaml-lml
|
|
161
|
-
requirement: !ruby/object:Gem::Requirement
|
|
162
|
-
requirements:
|
|
163
|
-
- - ">="
|
|
164
|
-
- !ruby/object:Gem::Version
|
|
165
|
-
version: 0.3.8
|
|
166
|
-
type: :runtime
|
|
167
|
-
prerelease: false
|
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
169
|
-
requirements:
|
|
170
|
-
- - ">="
|
|
171
|
-
- !ruby/object:Gem::Version
|
|
172
|
-
version: 0.3.8
|
|
173
159
|
- !ruby/object:Gem::Dependency
|
|
174
160
|
name: lutaml-model
|
|
175
161
|
requirement: !ruby/object:Gem::Requirement
|
|
176
162
|
requirements:
|
|
177
163
|
- - "~>"
|
|
178
164
|
- !ruby/object:Gem::Version
|
|
179
|
-
version: 0.8.
|
|
165
|
+
version: 0.8.188
|
|
180
166
|
type: :runtime
|
|
181
167
|
prerelease: false
|
|
182
168
|
version_requirements: !ruby/object:Gem::Requirement
|
|
183
169
|
requirements:
|
|
184
170
|
- - "~>"
|
|
185
171
|
- !ruby/object:Gem::Version
|
|
186
|
-
version: 0.8.
|
|
172
|
+
version: 0.8.188
|
|
187
173
|
- !ruby/object:Gem::Dependency
|
|
188
174
|
name: lutaml-uml
|
|
189
175
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -520,6 +506,7 @@ files:
|
|
|
520
506
|
- lib/metanorma/plugin/lutaml/content.rb
|
|
521
507
|
- lib/metanorma/plugin/lutaml/data2_text_preprocessor.rb
|
|
522
508
|
- lib/metanorma/plugin/lutaml/data_providers.rb
|
|
509
|
+
- lib/metanorma/plugin/lutaml/ea_xmi_slicer_compat.rb
|
|
523
510
|
- lib/metanorma/plugin/lutaml/express_hotspot_anchor.rb
|
|
524
511
|
- lib/metanorma/plugin/lutaml/express_remark_adapter.rb
|
|
525
512
|
- lib/metanorma/plugin/lutaml/express_remark_figures.rb
|