stepmod-utils 0.2.0 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +42 -0
  3. data/.github/workflows/release.yml +23 -20
  4. data/Gemfile +2 -1
  5. data/Makefile +5 -0
  6. data/README.adoc +82 -1
  7. data/exe/stepmod-annotate-all +39 -0
  8. data/exe/stepmod-build-resource-docs-cache +19 -0
  9. data/exe/stepmod-convert-express-description +33 -0
  10. data/exe/stepmod-convert-express-resource +33 -0
  11. data/exe/stepmod-extract-terms +3 -3
  12. data/exe/stepmod-find-express-files +23 -0
  13. data/lib/stepmod/utils/cleaner.rb +11 -0
  14. data/lib/stepmod/utils/converters/a.rb +47 -0
  15. data/lib/stepmod/utils/converters/blockquote.rb +22 -0
  16. data/lib/stepmod/utils/converters/br.rb +15 -0
  17. data/lib/stepmod/utils/converters/bypass.rb +81 -0
  18. data/lib/stepmod/utils/converters/code.rb +19 -0
  19. data/lib/stepmod/utils/converters/comment.rb +16 -0
  20. data/lib/stepmod/utils/converters/dd.rb +15 -0
  21. data/lib/stepmod/utils/converters/def.rb +11 -4
  22. data/lib/stepmod/utils/converters/dl.rb +31 -0
  23. data/lib/stepmod/utils/converters/drop.rb +22 -0
  24. data/lib/stepmod/utils/converters/dt.rb +17 -0
  25. data/lib/stepmod/utils/converters/em_express_description.rb +22 -0
  26. data/lib/stepmod/utils/converters/eqn.rb +97 -0
  27. data/lib/stepmod/utils/converters/example.rb +1 -6
  28. data/lib/stepmod/utils/converters/express_g.rb +49 -0
  29. data/lib/stepmod/utils/converters/express_ref_express_description.rb +13 -0
  30. data/lib/stepmod/utils/converters/ext_description.rb +17 -0
  31. data/lib/stepmod/utils/converters/ext_descriptions.rb +14 -0
  32. data/lib/stepmod/utils/converters/fund_cons.rb +21 -0
  33. data/lib/stepmod/utils/converters/head.rb +22 -0
  34. data/lib/stepmod/utils/converters/hr.rb +15 -0
  35. data/lib/stepmod/utils/converters/ignore.rb +16 -0
  36. data/lib/stepmod/utils/converters/introduction.rb +15 -0
  37. data/lib/stepmod/utils/converters/note.rb +1 -6
  38. data/lib/stepmod/utils/converters/ol.rb +3 -2
  39. data/lib/stepmod/utils/converters/p.rb +21 -0
  40. data/lib/stepmod/utils/converters/pass_through.rb +13 -0
  41. data/lib/stepmod/utils/converters/q.rb +16 -0
  42. data/lib/stepmod/utils/converters/resource.rb +14 -0
  43. data/lib/stepmod/utils/converters/schema.rb +19 -0
  44. data/lib/stepmod/utils/converters/schema_diag.rb +14 -0
  45. data/lib/stepmod/utils/converters/strong.rb +41 -0
  46. data/lib/stepmod/utils/converters/sub.rb +24 -0
  47. data/lib/stepmod/utils/converters/sup.rb +22 -0
  48. data/lib/stepmod/utils/converters/table.rb +62 -0
  49. data/lib/stepmod/utils/converters/text.rb +68 -0
  50. data/lib/stepmod/utils/html_to_asciimath.rb +157 -0
  51. data/lib/stepmod/utils/smrl_description_converter.rb +49 -0
  52. data/lib/stepmod/utils/smrl_resource_converter.rb +67 -0
  53. data/lib/stepmod/utils/stepmod_file_annotator.rb +78 -0
  54. data/lib/stepmod/utils/version.rb +1 -1
  55. data/migrating_from_cvs.adoc +190 -0
  56. data/stepmod-utils.gemspec +1 -0
  57. metadata +69 -8
  58. data/.github/workflows/macos.yml +0 -39
  59. data/.github/workflows/ubuntu.yml +0 -53
  60. data/.github/workflows/windows.yml +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83672fac3acf9ef0d9a2ab17fffab1204b326c7d41018675c2cc819976ac8b40
4
- data.tar.gz: 2a59c155d059ca7b73e48ebf5ddedac314e998dbb92eb301a55c460d8ac44e79
3
+ metadata.gz: fe9caf0ee63e637eb1a73289d7394a495b5f8a313c6ee3d69aff2bdcc150e57f
4
+ data.tar.gz: 791c199203956d117839a900869fd61362ead66703f6723cd4b5c0c8d871ccc4
5
5
  SHA512:
6
- metadata.gz: ca130bac46780aeef8434443d68e02a83cfc2d17a5dd1634c13c6448fd33c1861e85cc3173303db64449e7da3465b1953ed344690894e09cd5698304c4b129eb
7
- data.tar.gz: f4d94ac262f4c98ca810a1002c0bdc22d67cc3bd771521f4700e512386f226156d442de3c3f826c0aa7757bbc7d41a78dd42c22b166eca6a032b9b1177511424
6
+ metadata.gz: 1910feb532333a698daa864f4387ccefdbcdeb6ccbcf3a962d3e7ec5dfa0a0c0f17643e8eba22ed625aa2a308595b0c30ea7d49ce5bed2de0a8c638cb1e2e00d
7
+ data.tar.gz: 19757106a503652a64052eb823750bb5a618750b68bf42abdc3833dde6be9d3345dbc80c5051d37cea2507fe07c87b0669cf3af60c66cf6579ace1cd02f9bf96
@@ -0,0 +1,42 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.7', '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ include:
23
+ - ruby: '3.0'
24
+ os: 'ubuntu-latest'
25
+ experimental: true
26
+ - ruby: '3.0'
27
+ os: 'windows-latest'
28
+ experimental: true
29
+ - ruby: '3.0'
30
+ os: 'macos-latest'
31
+ experimental: true
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ with:
35
+ submodules: true
36
+
37
+ - uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ bundler-cache: true
41
+
42
+ - run: bundle exec rake
@@ -1,41 +1,44 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  name: release
2
4
 
3
5
  on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'patch'
4
13
  push:
5
- tags:
6
- - '*'
14
+ tags: [ v* ]
7
15
 
8
16
  jobs:
9
17
  release:
10
- runs-on: ubuntu-18.04
18
+ runs-on: ubuntu-latest
11
19
  steps:
12
- - uses: actions/checkout@v1
13
- - name: Use Ruby
14
- uses: actions/setup-ruby@v1
20
+ - uses: actions/checkout@v2
21
+
22
+ - uses: ruby/setup-ruby@v1
15
23
  with:
16
24
  ruby-version: '2.6'
17
- architecture: 'x64'
18
- - name: Update gems
19
- run: |
20
- gem install bundler
21
- bundle install --jobs 4 --retry 3
22
- - name: Update stepmod-utils.jar
23
- run: |
24
- rm -f bin/stepmod-utils.jar
25
- rake bin/stepmod-utils.jar
26
- - name: Run specs
25
+
26
+ - run: gem install gem-release
27
+
28
+ - if: ${{ github.event_name == 'workflow_dispatch' }}
27
29
  run: |
28
- bundle exec rake
29
- - name: Publish to rubygems.org
30
+ git config user.name github-actions
31
+ git config user.email github-actions@github.com
32
+ gem bump --version ${{ github.event.inputs.next_version }} --tag --push
33
+
34
+ - name: publish to rubygems.org
30
35
  env:
31
36
  RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
32
37
  run: |
33
38
  gem install gem-release
34
- touch ~/.gem/credentials
35
39
  cat > ~/.gem/credentials << EOF
36
40
  ---
37
41
  :rubygems_api_key: ${RUBYGEMS_API_KEY}
38
42
  EOF
39
43
  chmod 0600 ~/.gem/credentials
40
- git status
41
44
  gem release
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
7
 
8
8
  gem "rake", "~> 12.0"
9
9
  gem "rspec", "~> 3.0"
10
- gem "pry"
10
+ gem "pry"
11
+ gem "concurrent-ruby", "~> 1.1"
data/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ convert_stepmod_repo:
2
+ bundle exec ./exe/stepmod-annotate-all $(10303_stepmod_path)
3
+
4
+ create_svgs:
5
+ java -jar $(stepmod2mn_jar_path) $(10303_stepmod_path) -svg
data/README.adoc CHANGED
@@ -1,4 +1,4 @@
1
- = stepmod-utils Ruby gem
1
+ = STEPmod utilities
2
2
 
3
3
  image:https://img.shields.io/gem/v/metanorma.svg["Gem Version", link="https://rubygems.org/gems/metanorma"]
4
4
  image:https://github.com/metanorma/stepmod-utils/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/metanorma/stepmod-utils/actions?query=workflow%3Aubuntu"]
@@ -12,6 +12,12 @@ image:https://img.shields.io/github/commits-since/metanorma/stepmod-utils/latest
12
12
 
13
13
  The `stepmod-utils` Ruby gem provides a number of tools to work with the STEPmod repository.
14
14
 
15
+
16
+ == CVS to Git migration procedures
17
+
18
+ include::migrating_from_cvs.adoc[]
19
+
20
+
15
21
  == Installation
16
22
 
17
23
  [source,ruby]
@@ -37,6 +43,81 @@ Then these files will be created:
37
43
  * `031-generated-terms.adoc` all terms extracted
38
44
  * `991-generated-bibliography.adoc` all bibliographic sources where the terms come from
39
45
 
46
+ == Conversion of STEPmod descriptions.xml into adoc
47
+
48
+ [source,sh]
49
+ ----
50
+ $ stepmod-convert-express-description /path/to/the/stepmod/descriptions.xml
51
+ ----
52
+
53
+ Example output:
54
+ [source,adoc]
55
+ -----
56
+ (*"application_context_schema"
57
+
58
+ *)
59
+ (*"application_context_schema.exchange_identification_context_select"
60
+ The *exchange\_identification\_context\_select* type allows for the designation of the data types express_ref:[management_resources_schema:ir_express:management_resources_schema.identification_assignment] and express_ref:[person_organization_schema:ir_express:person_organization_schema.organization] .
61
+ *)
62
+ (*"application_context_schema.application_context"
63
+ An *application\_context*, as defined in ISO 10303-1, is a context in which product data is defined and has meaning. An *application\_context* represents various types of information that relate to product data and may affect the meaning and usage of that data.
64
+ *)
65
+ (*"application_context_schema.application_context.application"
66
+
67
+ the express_ref:[support_resource_schema:ir_express:support_resource_schema.label] by which the *application\_context* is known.
68
+
69
+ [NOTE]
70
+ --
71
+ The meaning of this attribute can be defined in the annotated EXPRESS schemas that use or specialize this entity, or in an agreement of common understanding between the partners sharing this information.
72
+ --
73
+
74
+ *)
75
+ -----
76
+
77
+
78
+ == Conversion of STEPmod resource.xml into adoc
79
+
80
+ Given resource.xml file contents:
81
+
82
+ [source,xml]
83
+ ----
84
+ <schema name="contract_schema" number="8369" version="3">
85
+ <introduction>
86
+ The subject of the <b>contract_schema</b> is the description of contract agreements.
87
+ </introduction>
88
+ <fund_cons>
89
+ Contract information may be attached to any aspect of a product data.
90
+ </fund_cons>
91
+ <express-g>
92
+ <imgfile file="contract_schemaexpg1.xml"/>
93
+ <imgfile file="contract_schemaexpg2.xml"/>
94
+ </express-g>
95
+ </schema>
96
+ ----
97
+
98
+ Command:
99
+
100
+ [source,sh]
101
+ ----
102
+ $ stepmod-convert-express-resource resource.xml
103
+ ----
104
+
105
+ Will give output:
106
+
107
+ [source,adoc]
108
+ ----
109
+ == Introduction
110
+
111
+ The subject of the *contract_schema* is the description of contract agreements.
112
+
113
+ == Fundamental concerns
114
+
115
+ Contract information may be attached to any aspect of a product data.
116
+
117
+ expg_image:contract_schemaexpg1.xml[]
118
+ expg_image:contract_schemaexpg2.xml[]
119
+ ----
120
+
40
121
 
41
122
  == CVS revision detection
42
123
 
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'concurrent'
4
+ require 'stepmod/utils/stepmod_file_annotator'
5
+
6
+ stepmod_dir = ARGV.first || Dir.pwd
7
+
8
+ # build resource_docs cache
9
+ resource_docs_cache_file = `mktemp`
10
+ `"#{File.join(__dir__, 'stepmod-build-resource-docs-cache')}" "#{stepmod_dir}" > "#{resource_docs_cache_file}"`
11
+
12
+ # annotate each file
13
+ files = `"#{File.join(__dir__, 'stepmod-find-express-files')}" "#{stepmod_dir}"`.strip.split("\n")
14
+ MAX_THREADS = [2, Concurrent.processor_count].max * 2
15
+ MAX_QUEUE_SIZE = MAX_THREADS * 4
16
+ # https://github.com/ruby-concurrency/concurrent-ruby/blob/master/docs-source/thread_pools.md
17
+ pool = Concurrent::ThreadPoolExecutor.new(
18
+ :min_threads => MAX_THREADS,
19
+ :max_threads => MAX_THREADS,
20
+ :max_queue => MAX_QUEUE_SIZE,
21
+ :fallback_policy => :caller_runs
22
+ )
23
+ files.each_slice(MAX_QUEUE_SIZE) do |batch|
24
+ puts("Queueing next batch")
25
+ batch.each do |file|
26
+ pool.post do
27
+ puts("#{Thread.current.object_id}: Queued processing #{file}")
28
+ annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file, resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
29
+ File.open(File.join(File.dirname(file), "#{File.basename(file, '.exp')}_annotated.exp"), 'w') do |file|
30
+ file.puts(annotated)
31
+ end
32
+ puts("#{Thread.current.object_id}: Done processing #{file}")
33
+ end
34
+ end
35
+ pool.shutdown
36
+ end
37
+
38
+ # cleanup
39
+ `rm "#{resource_docs_cache_file}"`
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nokogiri'
4
+ require 'json'
5
+
6
+ stepmod_dir = ARGV.first || Dir.pwd
7
+
8
+ schemas = {}
9
+ Dir.glob(File.join(stepmod_dir, 'data/resource_docs/*/resource.xml')).each do |resource_docs_file|
10
+ match = resource_docs_file.match('data/resource_docs/([^/]+)/resource.xml')
11
+ resource_docs_dir = match.captures[0]
12
+
13
+ resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
14
+ resource_docs.xpath('schema').each do |schema|
15
+ schemas[schema['name']] = resource_docs_dir
16
+ end
17
+ end
18
+
19
+ puts JSON.pretty_generate(schemas)
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ require 'bundler/setup'
19
+ require 'stepmod/utils/smrl_description_converter'
20
+
21
+ ReverseAdoc.config.unknown_tags = :bypass
22
+
23
+ input_content = ARGF.read
24
+
25
+ result = Stepmod::Utils::SmrlDescriptionConverter.convert(input_content, {})
26
+ result.split("\n").each do |line|
27
+ begin
28
+ $stdout.puts(line)
29
+ $stdout.flush
30
+ rescue Errno::EPIPE
31
+ exit(74)
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ require 'bundler/setup'
19
+ require 'stepmod/utils/smrl_resource_converter'
20
+
21
+ ReverseAdoc.config.unknown_tags = :bypass
22
+
23
+ input_content = ARGF.read
24
+
25
+ result = Stepmod::Utils::SmrlResourceConverter.convert(input_content, {})
26
+ result.split("\n").each do |line|
27
+ begin
28
+ $stdout.puts(line)
29
+ $stdout.flush
30
+ rescue Errno::EPIPE
31
+ exit(74)
32
+ end
33
+ end
@@ -76,7 +76,7 @@ files.each do |file_path|
76
76
  end
77
77
 
78
78
  # TODO: we may want a command line option to override this in the future
79
- unless %w(IS DIS TS).include? bibdata.doctype
79
+ unless %w(IS DIS FDIS TS).include? bibdata.doctype
80
80
  log "INFO: skipped #{bibdata.docid} as it is not IS, DIS or TS"
81
81
  next
82
82
  end
@@ -135,7 +135,7 @@ files.each do |file_path|
135
135
 
136
136
  end
137
137
 
138
- parsed_bibliography.uniq!
138
+ parsed_bibliography
139
139
 
140
140
  File.open('031-generated-terms.adoc', 'w') { |file|
141
141
  file.puts(parsed_terms.map(&:to_mn_adoc).join("\n"))
@@ -144,7 +144,7 @@ File.open('031-generated-terms.adoc', 'w') { |file|
144
144
  log "INFO: written to: 031-generated-terms.adoc"
145
145
 
146
146
  File.open('991-generated-bibliography.adoc', 'w') { |file|
147
- file.puts(parsed_bibliography.map(&:to_mn_adoc).join("\n"))
147
+ file.puts(parsed_bibliography.map(&:to_mn_adoc).uniq.join("\n"))
148
148
  }
149
149
 
150
150
  log "INFO: written to: 991-generated-bibliography.adoc"
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'nokogiri'
4
+
5
+ stepmod_dir = ARGV.first || Dir.pwd
6
+
7
+ index = Nokogiri::XML(File.read(File.join(stepmod_dir, 'repository_index.xml'))).root
8
+
9
+ files = []
10
+ index.xpath('modules/module').each do |item|
11
+ files << "#{stepmod_dir}/data/modules/#{item['name']}/arm.exp"
12
+ files << "#{stepmod_dir}/data/modules/#{item['name']}/mim.exp"
13
+ end
14
+ index.xpath('resources/resource').each do |item|
15
+ files << "#{stepmod_dir}/data/resources/#{item['name']}/#{item['name']}.exp"
16
+ end
17
+ index.xpath('business_object_models/business_object_model').each do |item|
18
+ files << "#{stepmod_dir}/data/business_object_models/#{item['name']}/bom.exp"
19
+ files << "#{stepmod_dir}/data/business_object_models/#{item['name']}/DomainModel.exp"
20
+ end
21
+
22
+ existing_files = files.filter{|file| File.exists?(file)}
23
+ puts existing_files
@@ -0,0 +1,11 @@
1
+ require 'reverse_adoc/cleaner'
2
+
3
+ module Stepmod
4
+ module Utils
5
+ class Cleaner < ReverseAdoc::Cleaner
6
+ def tidy(string)
7
+ super.gsub(/^ +/, '')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module Stepmod
6
+ module Utils
7
+ module Converters
8
+ class A < ReverseAdoc::Converters::Base
9
+ def convert(node, state = {})
10
+ name = treat_children(node, state)
11
+ href = node['href']
12
+ title = extract_title(node)
13
+ id = node['id'] || node['name']
14
+
15
+ id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
16
+
17
+ if /^_Toc\d+$|^_GoBack$/.match id
18
+ ""
19
+ elsif !id.nil? && !id.empty?
20
+ "[[#{id}]]"
21
+ elsif href.to_s.start_with?('#')
22
+ href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
23
+ if name.empty?
24
+ "<<#{href}>>"
25
+ else
26
+ "<<#{href},#{name}>>"
27
+ end
28
+ elsif href.to_s.empty?
29
+ name
30
+ else
31
+ name = title if name.empty?
32
+ href = "link:#{href}" unless href.to_s =~ URI::DEFAULT_PARSER.make_regexp
33
+ link = "#{href}[#{name}]"
34
+ # link.prepend(' ')
35
+ link = " #{link}"
36
+ link
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ end
43
+
44
+ ReverseAdoc::Converters.register :a, A.new
45
+ end
46
+ end
47
+ end