stepmod-utils 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +51 -0
  3. data/.github/workflows/release.yml +20 -22
  4. data/Gemfile +2 -1
  5. data/Makefile +2 -0
  6. data/README.adoc +82 -1
  7. data/exe/stepmod-annotate +44 -0
  8. data/exe/stepmod-annotate-all +39 -0
  9. data/exe/stepmod-build-resource-docs-cache +19 -0
  10. data/exe/stepmod-convert-express-description +33 -0
  11. data/exe/stepmod-convert-express-resource +33 -0
  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 +96 -0
  27. data/lib/stepmod/utils/converters/example.rb +1 -6
  28. data/lib/stepmod/utils/converters/express_g.rb +46 -0
  29. data/lib/stepmod/utils/converters/express_ref_express_description.rb +13 -0
  30. data/lib/stepmod/utils/converters/ext_description.rb +16 -0
  31. data/lib/stepmod/utils/converters/ext_descriptions.rb +14 -0
  32. data/lib/stepmod/utils/converters/fund_cons.rb +15 -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 +18 -0
  44. data/lib/stepmod/utils/converters/schema_diag.rb +14 -0
  45. data/lib/stepmod/utils/converters/strong.rb +21 -0
  46. data/lib/stepmod/utils/converters/sub.rb +16 -0
  47. data/lib/stepmod/utils/converters/sup.rb +16 -0
  48. data/lib/stepmod/utils/converters/text.rb +68 -0
  49. data/lib/stepmod/utils/html_to_asciimath.rb +157 -0
  50. data/lib/stepmod/utils/smrl_description_converter.rb +49 -0
  51. data/lib/stepmod/utils/smrl_resource_converter.rb +67 -0
  52. data/lib/stepmod/utils/stepmod_file_annotator.rb +54 -0
  53. data/lib/stepmod/utils/version.rb +1 -1
  54. data/migrating_from_cvs.adoc +190 -0
  55. metadata +54 -6
  56. data/.github/workflows/macos.yml +0 -39
  57. data/.github/workflows/ubuntu.yml +0 -53
  58. 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: 30293492d1d3224173ac5070db26552c4cb1df8d6d56059e8180a461e85b6fed
4
+ data.tar.gz: b784155408f9c0cef9ad0c3665bfe5defa35a3458ad5b9ffda75ca0aa612476a
5
5
  SHA512:
6
- metadata.gz: ca130bac46780aeef8434443d68e02a83cfc2d17a5dd1634c13c6448fd33c1861e85cc3173303db64449e7da3465b1953ed344690894e09cd5698304c4b129eb
7
- data.tar.gz: f4d94ac262f4c98ca810a1002c0bdc22d67cc3bd771521f4700e512386f226156d442de3c3f826c0aa7757bbc7d41a78dd42c22b166eca6a032b9b1177511424
6
+ metadata.gz: adb0dd04f01590a002552dedb5975d07bcb0897c1c2fe443e5d3ff865ab7c7c1ebc774e1414febabd2305c24abef5560ad4f1b24034aeba05fe0f89f956a9c36
7
+ data.tar.gz: 48dca001c264cc71a3c415ad255f7c7161cebfb4f3cb91990a2b4e538cb72b404d8e12fa3f1f046c65b8538a32cbca0004846ac0f517c3756f47bfaee9a127fa
@@ -0,0 +1,51 @@
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@master
34
+
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ bundler-cache: true
39
+
40
+ - run: bundle exec rake
41
+
42
+ tests-passed:
43
+ needs: rake
44
+ runs-on: ubuntu-latest
45
+ steps:
46
+ - uses: peter-evans/repository-dispatch@v1
47
+ with:
48
+ token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
49
+ repository: ${{ github.repository }}
50
+ event-type: notify
51
+ client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
@@ -1,41 +1,39 @@
1
1
  name: release
2
2
 
3
3
  on:
4
- push:
5
- tags:
6
- - '*'
4
+ workflow_dispatch:
5
+ inputs:
6
+ next_version:
7
+ description: |
8
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
9
+ required: true
10
+ default: 'patch'
7
11
 
8
12
  jobs:
9
13
  release:
10
- runs-on: ubuntu-18.04
14
+ runs-on: ubuntu-latest
11
15
  steps:
12
- - uses: actions/checkout@v1
13
- - name: Use Ruby
14
- uses: actions/setup-ruby@v1
16
+ - uses: actions/checkout@v2
17
+
18
+ - uses: ruby/setup-ruby@v1
15
19
  with:
16
20
  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
27
- run: |
28
- bundle exec rake
29
- - name: Publish to rubygems.org
21
+
22
+ - run: gem install gem-release
23
+
24
+ - run: |
25
+ git config user.name github-actions
26
+ git config user.email github-actions@github.com
27
+ gem bump --version ${{ github.event.inputs.next_version }} --tag --push
28
+
29
+ - name: publish to rubygems.org
30
30
  env:
31
31
  RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
32
32
  run: |
33
33
  gem install gem-release
34
- touch ~/.gem/credentials
35
34
  cat > ~/.gem/credentials << EOF
36
35
  ---
37
36
  :rubygems_api_key: ${RUBYGEMS_API_KEY}
38
37
  EOF
39
38
  chmod 0600 ~/.gem/credentials
40
- git status
41
39
  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,2 @@
1
+ convert_stepmod_repo:
2
+ bundle exec ./exe/stepmod-annotate-all ../iso-10303-stepmod
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,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'stepmod/utils/smrl_description_converter'
5
+ require 'stepmod/utils/smrl_resource_converter'
6
+
7
+ express_file = ARGV.shift
8
+ resource_docs_cache_file = ARGV.shift # output of ./stepmod-build-resource-docs-cache
9
+ stepmod_dir = ARGV.first || Dir.pwd
10
+
11
+ match = File.basename(express_file).match('^(arm|mim|bom)\.exp$')
12
+ descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" : 'descriptions.xml'
13
+ descriptions_file = File.join(File.dirname(express_file), descriptions_base)
14
+
15
+ output_express = File.read(express_file)
16
+
17
+ resource_docs_cache = JSON.parse(File.read(resource_docs_cache_file))
18
+
19
+ if File.exists?(descriptions_file)
20
+ descriptions = Nokogiri::XML(File.read(descriptions_file)).root
21
+ descriptions.xpath('ext_description').each do |description|
22
+ unless description.text.strip.empty? then
23
+ Dir.chdir(File.dirname(descriptions_file)) do
24
+ wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
25
+ output_express << "\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
26
+ end
27
+ else
28
+ # remark is empty, fallback to resource_docs_cache
29
+ resource_docs_dir = resource_docs_cache[description['linkend']]
30
+ if resource_docs_dir
31
+ resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
32
+ resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
33
+ schema = resource_docs.xpath("schema[@name='#{description['linkend']}']")
34
+
35
+ Dir.chdir(File.dirname(descriptions_file)) do
36
+ wrapper = "<resource>#{schema.to_s}</resource>"
37
+ output_express << "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ puts output_express
@@ -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("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("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
@@ -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