suma 0.1.22 → 0.1.23

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: 414cf7549060d821671a08771418a9f3c163ba23af62ef980eb4b12ccd0f5ad4
4
- data.tar.gz: 0b30377a2b1db558bf62c765f136c5c505ba905b387a5d76e249fc48fce8c237
3
+ metadata.gz: 2c9cab2e048b99f3208e2956c0611dd64774a280afbe06cd60fb72474e4a8b4b
4
+ data.tar.gz: 9b12e455229ec616e08c3cba4d6e7e23adc14193241bfaeb33f605ba29a9ee2e
5
5
  SHA512:
6
- metadata.gz: 7e899f31a08df29536d7abe1e8d2fc29a0c20038e1bb7dcedda35a7b9fa5d5041046e963d543401b4eaa100fa9d1aff19218b4e1c72457fb2a081a34211072f5
7
- data.tar.gz: c764fc1985311dafb09074a498cfc30694427e95c2f29d4d243872fca5ddfa0ab6df3d323d785254b3ef69848cf3114c8b0b44b483ae09b97a1e293b05f82356
6
+ metadata.gz: e31649ea7c3e8bd144f212f4f3568a017bcf4a85550d9ad17d8210bb8df674163bdee055484f94bab2d41b42281444bfaff9e8d234cf970e71da5e8dd27f5308
7
+ data.tar.gz: '0281f7449d90c3979507e7a834091970cfb2f380bcc2a9fe8186f0e4cad2315f3a7e82d8279093d4ca721190c63a24a227d70ee87b05931354c37a6a3ffc7972'
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2025-10-04 11:33:46 UTC using RuboCop version 1.81.1.
3
+ # on 2025-10-05 11:55:30 UTC using RuboCop version 1.81.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -18,7 +18,7 @@ Gemspec/RequiredRubyVersion:
18
18
  Exclude:
19
19
  - 'suma.gemspec'
20
20
 
21
- # Offense count: 67
21
+ # Offense count: 70
22
22
  # This cop supports safe autocorrection (--autocorrect).
23
23
  # Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
24
24
  # URISchemes: http, https
@@ -26,6 +26,7 @@ Layout/LineLength:
26
26
  Exclude:
27
27
  - 'lib/suma/cli.rb'
28
28
  - 'lib/suma/cli/build.rb'
29
+ - 'lib/suma/cli/export.rb'
29
30
  - 'lib/suma/cli/validate.rb'
30
31
  - 'lib/suma/jsdai/figure.rb'
31
32
  - 'lib/suma/jsdai/figure_image.rb'
@@ -50,6 +51,11 @@ Lint/DuplicateMethods:
50
51
  Exclude:
51
52
  - 'lib/suma/express_schema.rb'
52
53
 
54
+ # Offense count: 1
55
+ Lint/IneffectiveAccessModifier:
56
+ Exclude:
57
+ - 'lib/suma/cli/export.rb'
58
+
53
59
  # Offense count: 9
54
60
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
55
61
  Metrics/AbcSize:
@@ -68,18 +74,24 @@ Metrics/CyclomaticComplexity:
68
74
  - 'lib/suma/jsdai/figure_image.rb'
69
75
  - 'lib/suma/thor_ext.rb'
70
76
 
77
+ # Offense count: 4
78
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
79
+ Metrics/MethodLength:
80
+ Max: 13
81
+
71
82
  # Offense count: 1
72
83
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
73
84
  Metrics/PerceivedComplexity:
74
85
  Exclude:
75
86
  - 'lib/suma/jsdai/figure_image.rb'
76
87
 
77
- # Offense count: 4
88
+ # Offense count: 6
78
89
  # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
79
90
  # SupportedStyles: snake_case, normalcase, non_integer
80
91
  # AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
81
92
  Naming/VariableNumber:
82
93
  Exclude:
94
+ - 'spec/suma/cli/export_spec.rb'
83
95
  - 'spec/suma/cli/validate_ascii_spec.rb'
84
96
 
85
97
  # Offense count: 1
@@ -88,11 +100,24 @@ Performance/CollectionLiteralInLoop:
88
100
  Exclude:
89
101
  - 'spec/suma/cli_spec.rb'
90
102
 
91
- # Offense count: 24
103
+ # Offense count: 1
104
+ # Configuration parameters: Prefixes, AllowedPatterns.
105
+ # Prefixes: when, with, without
106
+ RSpec/ContextWording:
107
+ Exclude:
108
+ - 'spec/suma/cli/export_spec.rb'
109
+
110
+ # Offense count: 32
92
111
  # Configuration parameters: CountAsOne.
93
112
  RSpec/ExampleLength:
94
113
  Max: 44
95
114
 
96
- # Offense count: 21
115
+ # Offense count: 2
116
+ # Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
117
+ RSpec/IndexedLet:
118
+ Exclude:
119
+ - 'spec/suma/cli/export_spec.rb'
120
+
121
+ # Offense count: 28
97
122
  RSpec/MultipleExpectations:
98
123
  Max: 12
data/README.adoc CHANGED
@@ -548,6 +548,141 @@ Sequential position:: assigned as the numbered href in both SVG and `svgmap`
548
548
  list
549
549
 
550
550
 
551
+ === Export schemas command
552
+
553
+ ==== General
554
+
555
+ The `suma export` command exports EXPRESS schemas from a manifest file to a
556
+ specified output directory. This command is useful for extracting plain or
557
+ annotated EXPRESS schemas for distribution or further processing.
558
+
559
+ [source,sh]
560
+ ----
561
+ $ suma export MANIFEST_FILE [options]
562
+ ----
563
+
564
+ Parameters:
565
+
566
+ `MANIFEST_FILE`:: Path to the EXPRESS schema manifest file (e.g., "schemas-srl.yml")
567
+
568
+ Options:
569
+
570
+ `--output=PATH`, `-o PATH`:: (required) Output directory path
571
+
572
+ `--additional=PATH`, `-a PATH`:: Additional schemas manifest file to merge
573
+
574
+ `--[no-]annotations`:: Include annotations (remarks/comments) in exported schemas (default: false)
575
+
576
+ `--[no-]zip`:: Create ZIP archive of exported schemas (default: false)
577
+
578
+ ==== Behavior
579
+
580
+ The command exports schemas while preserving the directory structure from the
581
+ manifest file paths:
582
+
583
+ * Schemas under `resources/` are exported to `OUTPUT/resources/`
584
+ * Schemas under `modules/` are exported to `OUTPUT/modules/`
585
+ * Other categories (`business_object_models/`, `core_model/`) follow the same pattern
586
+
587
+ By default, schemas are exported without annotations (plain EXPRESS). Use the
588
+ `--annotations` flag to include remarks and comments.
589
+
590
+ The `--zip` flag creates a ZIP archive in addition to the directory output,
591
+ named `OUTPUT.zip`.
592
+
593
+ [example]
594
+ .To export schemas without annotations
595
+ [source,sh]
596
+ ----
597
+ $ bundle exec suma export -o express-files schemas-srl.yml
598
+ # => generates express-files/ directory with plain EXPRESS schemas
599
+ ----
600
+
601
+ [example]
602
+ .To export schemas with annotations
603
+ [source,sh]
604
+ ----
605
+ $ bundle exec suma export -o express-files --annotations schemas-srl.yml
606
+ # => generates express-files/ directory with annotated EXPRESS schemas
607
+ ----
608
+
609
+ [example]
610
+ .To export and create ZIP archive
611
+ [source,sh]
612
+ ----
613
+ $ bundle exec suma export -o express-files --zip schemas-srl.yml
614
+ # => generates both:
615
+ # - express-files/ directory
616
+ # - express-files.zip archive
617
+ ----
618
+
619
+ [example]
620
+ .To merge additional schemas and export
621
+ [source,sh]
622
+ ----
623
+ $ bundle exec suma export -o express-files \
624
+ -a additional-schemas.yml \
625
+ schemas-srl.yml
626
+ # => exports schemas from both manifest files
627
+ ----
628
+
629
+ [example]
630
+ .To merge multiple additional schemas
631
+ [source,sh]
632
+ ----
633
+ $ bundle exec suma export -o express-files \
634
+ -a additional-schemas-1.yml \
635
+ -a additional-schemas-2.yml \
636
+ schemas-srl.yml
637
+ # => exports schemas from primary manifest and all additional manifests
638
+ ----
639
+
640
+ [example]
641
+ .To export with all options
642
+ [source,sh]
643
+ ----
644
+ $ bundle exec suma export -o express-files \
645
+ -a additional-schemas.yml \
646
+ schemas-srl.yml
647
+ # => exports schemas from both manifest files
648
+ ----
649
+
650
+ [example]
651
+ .To export with all options
652
+ [source,sh]
653
+ ----
654
+ $ bundle exec suma export -o express-files \
655
+ --annotations \
656
+ --zip \
657
+ -a additional-schemas.yml \
658
+ schemas-srl.yml
659
+ # => generates annotated schemas in both directory and ZIP format,
660
+ # including schemas from both manifest files
661
+ ----
662
+
663
+ ==== Output structure
664
+
665
+ The exported directory structure mirrors the schema paths in the manifest:
666
+
667
+ [source]
668
+ ----
669
+ express-files/
670
+ ├── resources/
671
+ │ ├── action_schema/
672
+ │ │ └── action_schema.exp
673
+ │ └── ...
674
+ ├── modules/
675
+ │ ├── activity/
676
+ │ │ ├── arm.exp
677
+ │ │ └── mim.exp
678
+ │ └── ...
679
+ ├── business_object_models/
680
+ │ └── ...
681
+ └── core_model/
682
+ └── ...
683
+ ----
684
+
685
+
551
686
  == Usage: Ruby
552
687
 
553
688
  === General
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "../thor_ext"
5
+
6
+ module Suma
7
+ module Cli
8
+ # Export command for exporting EXPRESS schemas from a manifest
9
+ class Export < Thor
10
+ desc "export MANIFEST_FILE",
11
+ "Export EXPRESS schemas from manifest"
12
+ option :output, type: :string, aliases: "-o", required: true,
13
+ desc: "Output directory path"
14
+ option :additional, type: :array, aliases: "-a",
15
+ desc: "Additional schemas manifest files to merge (can be specified multiple times)"
16
+ option :annotations, type: :boolean, default: false,
17
+ desc: "Include annotations (remarks/comments)"
18
+ option :zip, type: :boolean, default: false,
19
+ desc: "Create ZIP archive of exported schemas"
20
+
21
+ def export(manifest_file)
22
+ require_relative "../schema_exporter"
23
+ require_relative "../utils"
24
+ require "expressir"
25
+
26
+ unless File.exist?(manifest_file)
27
+ raise Errno::ENOENT, "Specified manifest file " \
28
+ "`#{manifest_file}` not found."
29
+ end
30
+
31
+ run(manifest_file, options)
32
+ end
33
+
34
+ private
35
+
36
+ def run(manifest_file, options)
37
+ config = load_and_merge_configs(manifest_file, options[:additional])
38
+
39
+ exporter = SchemaExporter.new(
40
+ config: config,
41
+ output_path: options[:output],
42
+ options: {
43
+ annotations: options[:annotations],
44
+ create_zip: options[:zip],
45
+ },
46
+ )
47
+
48
+ exporter.export
49
+ end
50
+
51
+ # rubocop:disable Metrics/MethodLength
52
+ def load_and_merge_configs(primary_path, additional_paths)
53
+ primary_config = Expressir::SchemaManifest.from_file(primary_path)
54
+ return primary_config unless additional_paths && !additional_paths.empty?
55
+
56
+ # Load all additional manifests
57
+ additional_configs = additional_paths.map do |path|
58
+ unless File.exist?(path)
59
+ raise Errno::ENOENT, "Specified additional manifest file " \
60
+ "`#{path}` not found."
61
+ end
62
+ Expressir::SchemaManifest.from_file(path)
63
+ end
64
+
65
+ # Merge all configs into the primary
66
+ merge_all_configs(primary_config, additional_configs)
67
+ end
68
+ # rubocop:enable Metrics/MethodLength
69
+
70
+ def merge_all_configs(primary, additional_configs)
71
+ # Collect all schemas from primary and all additional manifests
72
+ all_schemas = primary.schemas.dup
73
+
74
+ additional_configs.each do |config|
75
+ all_schemas += config.schemas
76
+ end
77
+
78
+ Expressir::SchemaManifest.new(
79
+ path: primary.path,
80
+ schemas: all_schemas,
81
+ )
82
+ end
83
+
84
+ def self.exit_on_failure?
85
+ true
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/suma/cli.rb CHANGED
@@ -60,6 +60,21 @@ module Suma
60
60
  Cli::ConvertJsdai.start
61
61
  end
62
62
 
63
+ desc "export MANIFEST_FILE",
64
+ "Export EXPRESS schemas from manifest"
65
+ option :output, type: :string, aliases: "-o", required: true,
66
+ desc: "Output directory path"
67
+ option :additional, type: :array, aliases: "-a",
68
+ desc: "Additional schemas manifest files to merge (can be specified multiple times)"
69
+ option :annotations, type: :boolean, default: false,
70
+ desc: "Include annotations (remarks/comments)"
71
+ option :zip, type: :boolean, default: false,
72
+ desc: "Create ZIP archive of exported schemas"
73
+ def export(_manifest_file)
74
+ require_relative "cli/export"
75
+ Cli::Export.start
76
+ end
77
+
63
78
  desc "validate SUBCOMMAND ...ARGS", "Validate express documents"
64
79
  subcommand "validate", Cli::Validate
65
80
 
@@ -42,14 +42,16 @@ module Suma
42
42
  File.join(@output_path, type, id, File.basename(@path))
43
43
  end
44
44
 
45
- def save_exp
45
+ def save_exp(with_annotations: false)
46
46
  relative_path = Pathname.new(filename_plain).relative_path_from(Dir.pwd)
47
- Utils.log "Save plain schema: #{relative_path}"
47
+ schema_type = with_annotations ? "annotated" : "plain"
48
+ Utils.log "Save #{schema_type} schema: #{relative_path}"
48
49
 
49
50
  # return if File.exist?(filename_plain)
50
51
  FileUtils.mkdir_p(File.dirname(filename_plain))
51
52
 
52
- File.write(filename_plain, to_plain)
53
+ content = with_annotations ? parsed.to_s(no_remarks: false) : to_plain
54
+ File.write(filename_plain, content)
53
55
  end
54
56
  end
55
57
  end
@@ -3,6 +3,7 @@
3
3
  require_relative "express_schema"
4
4
  require_relative "schema_attachment"
5
5
  require_relative "schema_document"
6
+ require_relative "schema_exporter"
6
7
  require "expressir"
7
8
  require_relative "utils"
8
9
 
@@ -62,11 +63,17 @@ module Suma
62
63
  end
63
64
  end
64
65
 
66
+ # rubocop:disable Metrics/MethodLength
65
67
  def compile
66
68
  finalize
67
- schemas.each_pair do |_schema_id, entry|
68
- entry.save_exp
69
- end
69
+
70
+ # Use SchemaExporter for schema export
71
+ exporter = SchemaExporter.new(
72
+ config: @config,
73
+ output_path: @output_path_schemas,
74
+ options: { annotations: false },
75
+ )
76
+ exporter.export
70
77
 
71
78
  docs.each_pair do |_schema_id, entry|
72
79
  entry.compile
@@ -98,5 +105,6 @@ module Suma
98
105
  # end
99
106
  # pp results
100
107
  end
108
+ # rubocop:enable Metrics/MethodLength
101
109
  end
102
110
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "express_schema"
4
+ require_relative "utils"
5
+ require "fileutils"
6
+
7
+ module Suma
8
+ # SchemaExporter exports EXPRESS schemas from a manifest
9
+ # with configurable options for annotations and ZIP packaging
10
+ class SchemaExporter
11
+ attr_reader :config, :output_path, :options
12
+
13
+ def initialize(config:, output_path:, options: {})
14
+ @config = config
15
+ @output_path = Pathname.new(output_path).expand_path
16
+ @options = default_options.merge(options)
17
+ end
18
+
19
+ def export
20
+ Utils.log "Exporting schemas to: #{output_path}"
21
+
22
+ schemas = config.schemas
23
+ export_to_directory(schemas)
24
+ create_zip_archive if options[:create_zip]
25
+
26
+ Utils.log "Export complete!"
27
+ end
28
+
29
+ private
30
+
31
+ def default_options
32
+ {
33
+ annotations: false,
34
+ create_zip: false,
35
+ structure: :preserve,
36
+ }
37
+ end
38
+
39
+ def export_to_directory(schemas)
40
+ schemas.each do |schema|
41
+ export_single_schema(schema)
42
+ end
43
+ end
44
+
45
+ def export_single_schema(schema)
46
+ category = categorize_schema(schema)
47
+ schema_output_path = output_path.join(category).to_s
48
+
49
+ express_schema = ExpressSchema.new(
50
+ id: schema.id,
51
+ path: schema.path.to_s,
52
+ output_path: schema_output_path,
53
+ )
54
+
55
+ express_schema.save_exp(with_annotations: options[:annotations])
56
+ end
57
+
58
+ # rubocop:disable Metrics/MethodLength
59
+ def categorize_schema(schema)
60
+ path = schema.path.to_s
61
+
62
+ case path
63
+ when %r{/resources/}
64
+ "resources"
65
+ when %r{/modules/}
66
+ "modules"
67
+ when %r{/business_object_models/}
68
+ "business_object_models"
69
+ when %r{/core_model/}
70
+ "core_model"
71
+ else
72
+ "other"
73
+ end
74
+ end
75
+ # rubocop:enable Metrics/MethodLength
76
+
77
+ # rubocop:disable Metrics/MethodLength
78
+ def create_zip_archive
79
+ require "zip"
80
+
81
+ zip_path = "#{output_path}.zip"
82
+ Utils.log "Creating ZIP archive: #{zip_path}"
83
+
84
+ Zip::File.open(zip_path, Zip::File::CREATE) do |zipfile|
85
+ Dir.glob("#{output_path}/**/*").each do |file|
86
+ next if File.directory?(file)
87
+
88
+ relative_path = file.sub("#{output_path}/", "")
89
+ zipfile.add(relative_path, file)
90
+ end
91
+ end
92
+
93
+ Utils.log "ZIP archive created: #{zip_path}"
94
+ end
95
+ # rubocop:enable Metrics/MethodLength
96
+ end
97
+ 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.1.22"
4
+ VERSION = "0.1.23"
5
5
  end
data/suma.gemspec CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
39
39
  spec.add_dependency "metanorma-cli"
40
40
  spec.add_dependency "plurimath"
41
41
  spec.add_dependency "ruby-progressbar"
42
+ spec.add_dependency "rubyzip", "~> 2.3"
42
43
  spec.add_dependency "table_tennis"
43
44
  spec.add_dependency "thor", ">= 0.20"
44
45
  spec.metadata["rubygems_mfa_required"] = "true"
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.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-10-05 00:00:00.000000000 Z
11
+ date: 2025-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubyzip
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.3'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: table_tennis
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +163,7 @@ files:
149
163
  - lib/suma/cli.rb
150
164
  - lib/suma/cli/build.rb
151
165
  - lib/suma/cli/convert_jsdai.rb
166
+ - lib/suma/cli/export.rb
152
167
  - lib/suma/cli/extract_terms.rb
153
168
  - lib/suma/cli/generate_schemas.rb
154
169
  - lib/suma/cli/reformat.rb
@@ -166,6 +181,7 @@ files:
166
181
  - lib/suma/schema_attachment.rb
167
182
  - lib/suma/schema_collection.rb
168
183
  - lib/suma/schema_document.rb
184
+ - lib/suma/schema_exporter.rb
169
185
  - lib/suma/site_config.rb
170
186
  - lib/suma/thor_ext.rb
171
187
  - lib/suma/utils.rb