suma 0.5.2 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f9f2ba538c3f9515549875292447ece09cc661afd3357af6b2662052afeb8aa
4
- data.tar.gz: a8fbfe210cb3d5e112ef03632c8f93678a02a59c307bb2407491dae30471d455
3
+ metadata.gz: bd20e6823c86b989284cda93b4edf57c6ff7d16520e4a35fb111ee7df94c45e2
4
+ data.tar.gz: cd8763148b716e7ee6b226f4306fb4f33c825b9d6139978fb8f633496164b319
5
5
  SHA512:
6
- metadata.gz: b9b4920a4a4961319ac8ee67abccf38557b41d19f12d579711f20310429af4a9532be3204e11384ecb52fe6a22db82967fa7afd7a24bca15fb5f77357a0bdffe
7
- data.tar.gz: 1a03d235c43500e7361fe8002cfb877944285a608cca4ee8be5edde1904cccb6fb0d7cda2df0b93b1f3a56574ff642651f1461bbda8f0c0f5875fdec7ca56ab0
6
+ metadata.gz: ceb4f07c65cf174b04c0511d0f5cf9c0b753de5d1e55cf14c87d98276f4c11518d6c9d3367c4804eb7a7c0368f08ece16f36dc26fe07e6492ec24d07fc20ea85
7
+ data.tar.gz: d8f38fa09779fb06f5c8d6d0da109e6f3edf11be8dfb00b382bb0aba5a1c5e03cb4da981e8ea45a06cd6bebec093a6e50fa6acdb10d19013c94d517e5a286e1b
@@ -14,21 +14,17 @@ on:
14
14
  repository_dispatch:
15
15
  types: [ do-release ]
16
16
 
17
+ # Least-privilege ceiling for the called rubygems-release.yml: its release job
18
+ # needs contents:write (git tag push) and id-token:write (OIDC Trusted Publishing).
19
+ permissions:
20
+ contents: write
21
+ id-token: write
22
+
17
23
  jobs:
18
24
  release:
19
25
  uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
20
26
  with:
21
27
  next_version: ${{ github.event.inputs.next_version }}
22
- # Explicit release_command needed since metanorma/ci#314 deprecated
23
- # `bundler_cache` (hardcoded to false) — the reusable's release job no
24
- # longer runs `bundle install` implicitly via ruby/setup-ruby, so the
25
- # default `bundle exec rake release` fires against uninstalled gems.
26
- # Surfaced by kwkwan on metanorma-plugin-lutaml#285. Deeper fix
27
- # (bundle install inside rubygems-release.yml's release job) tracked
28
- # separately.
29
- release_command: |
30
- bundle install
31
- bundle exec rake release
32
28
  secrets:
33
29
  rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
34
30
  pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
data/Gemfile CHANGED
@@ -6,13 +6,17 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "canon"
9
- # Staged build (suma#94) needs the preserve_unresolved: / artifact_store_dir: /
10
- # reinflate: render options from metanorma#578 (metanorma 2.5.0). Point at the
11
- # feature branch until it is released; drop this once 2.5.0 is on rubygems.
12
- gem "metanorma", github: "metanorma/metanorma",
13
- branch: "feature/collection-incremental-resumable"
9
+ # metanorma resolves from the gemspec constraint (~> 2.3) to the released gem.
10
+ # The staged-build render options (preserve_unresolved:/artifact_store_dir:/
11
+ # reinflate:, metanorma#578) landed in metanorma 2.5.0, now on rubygems, so the
12
+ # former feature-branch override (feature/collection-incremental-resumable) is
13
+ # dropped: CI builds against a stable released metanorma, not a floating branch.
14
+ # Flavor gem needed to compile the dummy-collection integration fixture
15
+ # (spec/fixtures/dummy_collection, suma#107).
16
+ gem "metanorma-iso"
14
17
  # gem "metanorma-plugin-lutaml", github: "metanorma/metanorma-plugin-lutaml", branch: "main"
15
18
  # gem "metanorma-standoc", github: "metanorma/metanorma-standoc", branch: "main"
19
+ # gem "expressir", github: "lutaml/expressir", branch: "main"
16
20
  gem "nokogiri"
17
21
  gem "openssl", "~> 3.0"
18
22
  gem "rake"
@@ -10,7 +10,7 @@ module Suma
10
10
  desc "convert_jsdai XML_FILE IMAGE_FILE OUTPUT_DIR",
11
11
  "Convert JSDAI XML and image files to SVG and EXP files"
12
12
 
13
- # rubocop:disable Metrics/MethodLength
13
+ # rubocop:disable-next Metrics/MethodLength
14
14
  def convert_jsdai(xml_file, image_file, output_dir)
15
15
  xml_file = File.expand_path(xml_file)
16
16
  image_file = File.expand_path(image_file)
@@ -34,11 +34,10 @@ module Suma
34
34
 
35
35
  run(xml_file, image_file, output_dir)
36
36
  end
37
- # rubocop:enable Metrics/MethodLength
38
37
 
39
38
  private
40
39
 
41
- # rubocop:disable Metrics/MethodLength
40
+ # rubocop:disable-next Metrics/MethodLength
42
41
  def run(xml_file, image_file, output_dir)
43
42
  FileUtils.mkdir_p(output_dir)
44
43
 
@@ -57,7 +56,6 @@ module Suma
57
56
 
58
57
  puts "Conversion complete."
59
58
  end
60
- # rubocop:enable Metrics/MethodLength
61
59
  end
62
60
  end
63
61
  end
@@ -64,7 +64,7 @@ module Suma
64
64
  end
65
65
 
66
66
  def to_plain
67
- parsed.to_s(no_remarks: true)
67
+ parsed.to_s
68
68
  end
69
69
 
70
70
  def filename_plain
@@ -92,7 +92,7 @@ module Suma
92
92
 
93
93
  FileUtils.mkdir_p(File.dirname(filename_plain))
94
94
 
95
- content = with_annotations ? parsed.to_s(no_remarks: false) : to_plain
95
+ content = with_annotations ? parsed.format(no_remarks: false) : to_plain
96
96
  File.write(filename_plain, content)
97
97
  end
98
98
 
@@ -12,7 +12,7 @@ module Suma
12
12
  @xml_file = xml_file
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable-next Metrics/MethodLength
16
16
  def to_svg
17
17
  width, height = @image.dimensions
18
18
  svg_parts = []
@@ -46,9 +46,8 @@ module Suma
46
46
  svg_parts << "\n\t\t</svg>"
47
47
  svg_parts.join
48
48
  end
49
- # rubocop:enable Metrics/MethodLength
50
49
 
51
- # rubocop:disable Metrics/MethodLength
50
+ # rubocop:disable-next Metrics/MethodLength
52
51
  def to_exp
53
52
  basename = File.basename(@xml_file, ".xml")
54
53
  schema_name = extract_schema_name(basename)
@@ -73,11 +72,10 @@ module Suma
73
72
  exp_parts << "\n*)\n"
74
73
  exp_parts.join
75
74
  end
76
- # rubocop:enable Metrics/MethodLength
77
75
 
78
76
  private
79
77
 
80
- # rubocop:disable Metrics/MethodLength
78
+ # rubocop:disable-next Metrics/MethodLength
81
79
  def generate_shape_element(area)
82
80
  shape_attrs = []
83
81
  shape_attrs << 'onmouseout="this.style.opacity=0" '
@@ -108,7 +106,6 @@ module Suma
108
106
  "<rect #{shape_attrs.join}"
109
107
  end
110
108
  end
111
- # rubocop:enable Metrics/MethodLength
112
109
 
113
110
  def parse_rect_coords(coords_str)
114
111
  parts = coords_str.split(",").map(&:to_i)
@@ -140,7 +137,7 @@ module Suma
140
137
  end
141
138
  end
142
139
 
143
- # rubocop:disable Metrics/MethodLength
140
+ # rubocop:disable-next Metrics/MethodLength
144
141
  def extract_schema_name(basename)
145
142
  # For module schemas like "armexpg1" with module="activity"
146
143
  # Result should be "Activity_arm"
@@ -159,9 +156,8 @@ module Suma
159
156
  basename.sub(/expg\d+$/, "")
160
157
  end
161
158
  end
162
- # rubocop:enable Metrics/MethodLength
163
159
 
164
- # rubocop:disable Metrics/MethodLength
160
+ # rubocop:disable-next Metrics/MethodLength
165
161
  def extract_target_from_href(href)
166
162
  # Extract the target from href
167
163
  # Type 1: "../../resources/action_schema/action_schema.xml#action_schema.as_name_attribute_select"
@@ -201,7 +197,6 @@ module Suma
201
197
  href
202
198
  end
203
199
  end
204
- # rubocop:enable Metrics/MethodLength
205
200
  end
206
201
  end
207
202
  end
@@ -58,7 +58,7 @@ module Suma
58
58
  end
59
59
  end
60
60
 
61
- # rubocop:disable Metrics/MethodLength
61
+ # rubocop:disable-next Metrics/MethodLength
62
62
  def extract_jpeg_dimensions
63
63
  # Read JPEG file to extract dimensions
64
64
  # JPEG uses markers, we look for SOF (Start of Frame) markers
@@ -90,7 +90,6 @@ module Suma
90
90
  end
91
91
  end
92
92
  end
93
- # rubocop:enable Metrics/MethodLength
94
93
  end
95
94
  end
96
95
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ # Null-object cache used when schema caching is disabled: every fetch misses
5
+ # and nothing is stored, so callers need no conditional guards around a cache.
6
+ class NullCache
7
+ def fetch(*, **) = nil
8
+
9
+ def store(*, **) = nil
10
+ end
11
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "fileutils"
5
+
6
+ module Suma
7
+ # Content-addressed, on-disk cache of *generated* EXPRESS schema output --
8
+ # the plain (annotations stripped, ISO copyright kept) or annotated `.exp`
9
+ # text produced from a source schema.
10
+ #
11
+ # The cache key composes the source bytes, the Expressir version, and the
12
+ # annotation mode. Those three fully determine the output (Expressir's
13
+ # serialiser is deterministic), so a hit is guaranteed byte-identical to a
14
+ # fresh generation -- and the store can be shared across builds and git
15
+ # worktrees: identical source content hits regardless of which build wrote it.
16
+ #
17
+ # Supersedes the parsed-AST `Marshal` approach of metanorma/suma#35, which was
18
+ # brittle across Ruby/Expressir versions and cached the wrong artifact (the
19
+ # parse, not the output).
20
+ class SchemaCache
21
+ def initialize(directory)
22
+ @directory = directory.to_s
23
+ end
24
+
25
+ # The cached output for +source+, or +nil+ on a miss.
26
+ def fetch(source, annotations:)
27
+ path = entry_path(source, annotations: annotations)
28
+ return unless File.exist?(path)
29
+
30
+ File.read(path, encoding: "UTF-8")
31
+ end
32
+
33
+ # Cache +content+ as the output for +source+. Returns the entry path.
34
+ def store(source, annotations:, content:)
35
+ path = entry_path(source, annotations: annotations)
36
+ FileUtils.mkdir_p(@directory)
37
+ write_atomically(path, content)
38
+ path
39
+ end
40
+
41
+ private
42
+
43
+ def entry_path(source, annotations:)
44
+ File.join(@directory, key(source, annotations: annotations))
45
+ end
46
+
47
+ def key(source, annotations:)
48
+ mode = annotations ? "annotated" : "plain"
49
+ "#{Digest::SHA256.hexdigest(source)}-#{expressir_version}-#{mode}.exp"
50
+ end
51
+
52
+ def expressir_version
53
+ @expressir_version ||= Expressir::VERSION
54
+ end
55
+
56
+ # Write through a sibling temp file and rename, so a concurrent reader never
57
+ # observes a half-written entry.
58
+ def write_atomically(path, content)
59
+ temp = "#{path}.#{Process.pid}.tmp"
60
+ File.write(temp, content, encoding: "UTF-8")
61
+ File.rename(temp, path)
62
+ ensure
63
+ File.delete(temp) if temp && File.exist?(temp)
64
+ end
65
+ end
66
+ end
@@ -7,8 +7,9 @@ module Suma
7
7
  attr_accessor :config, :schemas, :docs, :output_path_docs,
8
8
  :output_path_schemas, :manifest
9
9
 
10
- def initialize(config: nil, config_yaml: nil, output_path_docs: nil,
11
- output_path_schemas: nil, manifest: nil)
10
+ def initialize(config: nil, config_yaml: nil, output_path_docs: nil, # rubocop:disable Metrics/ParameterLists
11
+ output_path_schemas: nil, manifest: nil,
12
+ options: { annotations: true })
12
13
  @schemas = {}
13
14
  @docs = {}
14
15
  @schema_name_to_docs = {}
@@ -19,6 +20,7 @@ module Suma
19
20
  @config = config
20
21
  @config ||= config_yaml && Expressir::SchemaManifest.from_file(config_yaml)
21
22
  @manifest = manifest
23
+ @options = options
22
24
  end
23
25
 
24
26
  def doc_from_schema_name(schema_name)
@@ -42,7 +44,7 @@ module Suma
42
44
  exporter = SchemaExporter.new(
43
45
  schemas: schemas.values,
44
46
  output_path: @output_path_schemas,
45
- options: { annotations: false },
47
+ options: @options,
46
48
  )
47
49
  exporter.export
48
50
 
@@ -23,6 +23,7 @@ module Suma
23
23
  @schemas = schemas
24
24
  @output_path = Pathname.new(output_path).expand_path
25
25
  @options = default_options.merge(options)
26
+ @cache = build_cache
26
27
  end
27
28
 
28
29
  def export
@@ -45,19 +46,51 @@ module Suma
45
46
  end
46
47
 
47
48
  def export_to_directory(schemas)
48
- schemas.each do |schema|
49
- schema.save_exp(with_annotations: options[:annotations])
50
- end
49
+ schemas.each { |schema| export_single_schema(schema) }
50
+ end
51
+
52
+ # Reuse cached plain/annotated output when the schema source is unchanged,
53
+ # otherwise generate it via +save_exp+ and cache the result. The Expressir
54
+ # parse (the cost) happens only on a cache miss. Caching is an orchestration
55
+ # concern, so it lives here in the service rather than in the ExpressSchema
56
+ # data model.
57
+ def export_single_schema(schema)
58
+ source = File.read(schema.path.to_s, encoding: "UTF-8")
59
+ cached = @cache.fetch(source, annotations: options[:annotations])
60
+ cached ? write_cached(schema, cached) : generate_and_cache(schema, source)
61
+ end
62
+
63
+ def generate_and_cache(schema, source)
64
+ schema.save_exp(with_annotations: options[:annotations])
65
+ content = File.read(schema.filename_plain)
66
+ @cache.store(source, annotations: options[:annotations], content: content)
67
+ end
68
+
69
+ def write_cached(schema, content)
70
+ relative = Pathname.new(schema.filename_plain).relative_path_from(Dir.pwd)
71
+ Utils.log "Save schema (cached): #{relative}"
72
+ FileUtils.mkdir_p(File.dirname(schema.filename_plain))
73
+ File.write(schema.filename_plain, content)
74
+ end
75
+
76
+ # A shared, content-addressed cache when a cache directory is configured
77
+ # (via the +:cache_dir+ option or the SUMA_SCHEMA_CACHE_DIR environment
78
+ # variable), otherwise a null cache (caching disabled).
79
+ def build_cache
80
+ directory = options[:cache_dir] || ENV.fetch("SUMA_SCHEMA_CACHE_DIR", nil)
81
+ return NullCache.new if directory.nil? || directory.empty?
82
+
83
+ SchemaCache.new(directory)
51
84
  end
52
85
 
53
- # rubocop:disable Metrics/MethodLength
86
+ # rubocop:disable-next Metrics/MethodLength
54
87
  def create_zip_archive
55
88
  require "zip"
56
89
 
57
90
  zip_path = "#{output_path}.zip"
58
91
  Utils.log "Creating ZIP archive: #{zip_path}"
59
92
 
60
- Zip::File.open(zip_path, Zip::File::CREATE) do |zipfile|
93
+ Zip::File.open(zip_path, create: true) do |zipfile|
61
94
  Dir.glob("#{output_path}/**/*").each do |file|
62
95
  next if File.directory?(file)
63
96
 
@@ -68,6 +101,5 @@ module Suma
68
101
 
69
102
  Utils.log "ZIP archive created: #{zip_path}"
70
103
  end
71
- # rubocop:enable Metrics/MethodLength
72
104
  end
73
105
  end
@@ -5,8 +5,8 @@ module Suma
5
5
  module Formatters
6
6
  autoload :TerminalFormatter,
7
7
  "suma/svg_quality/formatters/terminal_formatter"
8
- autoload :JsonFormatter, "suma/svg_quality/formatters/json_formatter"
9
- autoload :YamlFormatter, "suma/svg_quality/formatters/yaml_formatter"
8
+ autoload :JsonFormatter, "suma/svg_quality/formatters/json_formatter"
9
+ autoload :YamlFormatter, "suma/svg_quality/formatters/yaml_formatter"
10
10
  end
11
11
  end
12
12
  end
data/lib/suma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suma
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
data/lib/suma.rb CHANGED
@@ -17,7 +17,9 @@ module Suma
17
17
  autoload :LinkValidator, "suma/link_validator"
18
18
  autoload :ManifestTraverser, "suma/manifest_traverser"
19
19
  autoload :NoteProcessor, "suma/note_processor"
20
+ autoload :NullCache, "suma/null_cache"
20
21
  autoload :RegisterManifestGenerator, "suma/register_manifest_generator"
22
+ autoload :SchemaCache, "suma/schema_cache"
21
23
  autoload :SchemaCategory, "suma/schema_category"
22
24
  autoload :SchemaCollection, "suma/schema_collection"
23
25
  autoload :SchemaComparer, "suma/schema_comparer"
data/suma.gemspec CHANGED
@@ -33,13 +33,13 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- spec.add_dependency "expressir", ">= 2.1.29", "~> 2.1"
36
+ spec.add_dependency "expressir"
37
37
  spec.add_dependency "glossarist", "~> 2.8", ">= 2.8.7"
38
38
  spec.add_dependency "lutaml-model", "~> 0.8.0"
39
39
  spec.add_dependency "metanorma", "~> 2.3"
40
40
  spec.add_dependency "plurimath"
41
41
  spec.add_dependency "ruby-progressbar"
42
- spec.add_dependency "rubyzip", "~> 2.3"
42
+ spec.add_dependency "rubyzip"
43
43
  spec.add_dependency "svg_conform", "~> 0.1.0"
44
44
  spec.add_dependency "table_tennis"
45
45
  spec.add_dependency "thor", ">= 0.20"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
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-07-28 00:00:00.000000000 Z
11
+ date: 2026-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.29
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '2.1'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 2.1.29
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '2.1'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: glossarist
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -110,16 +104,16 @@ dependencies:
110
104
  name: rubyzip
111
105
  requirement: !ruby/object:Gem::Requirement
112
106
  requirements:
113
- - - "~>"
107
+ - - ">="
114
108
  - !ruby/object:Gem::Version
115
- version: '2.3'
109
+ version: '0'
116
110
  type: :runtime
117
111
  prerelease: false
118
112
  version_requirements: !ruby/object:Gem::Requirement
119
113
  requirements:
120
- - - "~>"
114
+ - - ">="
121
115
  - !ruby/object:Gem::Version
122
- version: '2.3'
116
+ version: '0'
123
117
  - !ruby/object:Gem::Dependency
124
118
  name: svg_conform
125
119
  requirement: !ruby/object:Gem::Requirement
@@ -217,8 +211,10 @@ files:
217
211
  - lib/suma/link_validator/step.rb
218
212
  - lib/suma/manifest_traverser.rb
219
213
  - lib/suma/note_processor.rb
214
+ - lib/suma/null_cache.rb
220
215
  - lib/suma/processor.rb
221
216
  - lib/suma/register_manifest_generator.rb
217
+ - lib/suma/schema_cache.rb
222
218
  - lib/suma/schema_category.rb
223
219
  - lib/suma/schema_collection.rb
224
220
  - lib/suma/schema_comparer.rb