ipynbdiff 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97969c0adb99db01eecef0831de1cbdb6eb1d2bfc58233195c76d475c8c4a97f
4
- data.tar.gz: e04aa8f6b704f85d539eb6b59021f67ad3ca1c032a8fd3051115545828ad2c67
3
+ metadata.gz: dd4b3e7e96694361ee62a498007e9bda9165b47b2ef9a31b41322cf8cdd8781f
4
+ data.tar.gz: 1680189fc74e0b8e8909d671ce3b77abff51e8ccd0d4304cf088b43a3254a311
5
5
  SHA512:
6
- metadata.gz: 9699f6249f6c47df87d0854069da21a484a91ef5974cd58570660e48bee7cadda633c7497396875e21d83221b00eaa8b8eb7d1e502340b0dec78718e7735d8b0
7
- data.tar.gz: 63a1153092296010189a76dc3c9eadb6cf421603b6199189a9d8681048820fc607123aa41a65c08169a8497e7a28795a0325f790fd792105374268d0996e5e0a
6
+ metadata.gz: fd5cf9cad8f9c20db2051a8b66a998a8174d066ca71e8a45c7bb5e1e274478919ed44fee1a38b296b7a5c679df686da96e402c750d51df0a68db7328260181a7
7
+ data.tar.gz: a7ba937ec71caa7a5a5a31cd47ea047f9b2518bd6c7f8a61f120b62deb7d3e6a07dc8ba76e8719b725dab8b6f78cb9b86771273a5a46d9798d744c2bc25d00bf
data/.gitlab-ci.yml CHANGED
@@ -1,42 +1,43 @@
1
+ # You can override the included template(s) by including variable overrides
2
+ # SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
3
+ # Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
4
+ # Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
5
+ # Note that environment variables can be set in several places
6
+ # See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
1
7
  image: ruby:2.7
2
-
3
8
  stages:
4
- - test
5
- - build
6
- - rubygems
7
-
9
+ - test
10
+ - build
11
+ - rubygems
8
12
  specs:
9
13
  stage: test
10
14
  script:
11
- - bundle install
12
- - bundle exec rspec
13
-
15
+ - bundle install
16
+ - bundle exec rspec
14
17
  build-gem:
15
18
  stage: build
16
19
  script:
17
- - bundle install
18
- - cat .VERSION.TMPL | sed s/GEM_VERSION/0.0.0/ > lib/version.rb
19
- - gem build ipynbdiff.gemspec
20
+ - bundle install
21
+ - cat .VERSION.TMPL | sed s/GEM_VERSION/0.0.0/ > lib/version.rb
22
+ - gem build ipynbdiff.gemspec
20
23
  artifacts:
21
24
  paths:
22
25
  - ipynbdiff-0.0.0.gem
23
26
  needs:
24
- - specs
25
-
27
+ - specs
26
28
  deploy-gem:
27
29
  stage: rubygems
28
30
  script:
29
- - bundle install
30
- - cat .VERSION.TMPL | sed s/GEM_VERSION/$CI_COMMIT_TAG/ > lib/version.rb
31
- - gem build ipynbdiff.gemspec
32
- - gem push ipynbdiff-$CI_COMMIT_TAG.gem
31
+ - bundle install
32
+ - cat .VERSION.TMPL | sed s/GEM_VERSION/$CI_COMMIT_TAG/ > lib/version.rb
33
+ - gem build ipynbdiff.gemspec
34
+ - gem push ipynbdiff-$CI_COMMIT_TAG.gem
33
35
  only:
34
- - tags
36
+ - tags
35
37
  except:
36
- - branches
37
- needs:
38
- - build-gem
38
+ - branches
39
+ needs:
40
+ - build-gem
39
41
  when: manual
40
-
41
-
42
-
42
+ include:
43
+ - template: Security/Dependency-Scanning.gitlab-ci.yml
data/ipynbdiff.gemspec CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/version'
3
+ lib = File.expand_path('lib/..', __dir__)
4
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'lib/version'
4
7
 
5
8
  Gem::Specification.new do |s|
6
9
  s.name = 'ipynbdiff'
@@ -8,7 +8,8 @@ module IpynbDiff
8
8
 
9
9
  ORDERED_KEYS = {
10
10
  'execute_result' => %w[image/png image/svg+xml image/jpeg text/markdown text/latex text/plain],
11
- 'display_data' => %w[image/png image/svg+xml image/jpeg text/markdown text/latex]
11
+ 'display_data' => %w[image/png image/svg+xml image/jpeg text/markdown text/latex],
12
+ 'stream' => %w[text]
12
13
  }.freeze
13
14
 
14
15
  def transform(output, symbol)
@@ -17,15 +18,17 @@ module IpynbDiff
17
18
  transform_error(output['traceback'], symbol / 'traceback')
18
19
  when 'execute_result', 'display_data'
19
20
  transform_non_error(ORDERED_KEYS[output_type], output['data'], symbol / 'data')
21
+ when 'stream'
22
+ transform_element('text', output['text'], symbol)
20
23
  end
21
24
 
22
- decorate_output(transformed, output, symbol) if transformed
25
+ transformed ? decorate_output(transformed, output, symbol) : []
23
26
  end
24
27
 
25
28
  def decorate_output(output_rows, output, symbol)
26
29
  [
27
30
  _,
28
- symbol, %(%%%% Output: #{output['output_type']}),
31
+ _(symbol, %(%%%% Output: #{output['output_type']})),
29
32
  _,
30
33
  *output_rows
31
34
  ]
@@ -34,7 +37,7 @@ module IpynbDiff
34
37
  def transform_error(traceback, symbol)
35
38
  traceback.map.with_index do |t, idx|
36
39
  t.split("\n").map do |l|
37
- [symbol / idx, l.gsub(/\[[0-9][0-9;]*m/, '').sub("\u001B", ' ').gsub(/\u001B/, '').rstrip]
40
+ _(symbol / idx, l.gsub(/\[[0-9][0-9;]*m/, '').sub("\u001B", ' ').gsub(/\u001B/, '').rstrip)
38
41
  end
39
42
  end
40
43
  end
@@ -52,13 +55,13 @@ module IpynbDiff
52
55
  transform_image(output_type, output_element, new_symbol)
53
56
  when 'image/svg+xml'
54
57
  transform_svg(output_element, new_symbol)
55
- when 'text/markdown', 'text/latex', 'text/plain'
58
+ when 'text/markdown', 'text/latex', 'text/plain', 'text'
56
59
  transform_text(output_element, new_symbol)
57
60
  end
58
61
  end
59
62
 
60
63
  def transform_image(image_type, image_content, symbol)
61
- [symbol, " ![](data:#{image_type};base64,#{image_content.gsub("\n", '')})"]
64
+ _(symbol, " ![](data:#{image_type};base64,#{image_content.gsub("\n", '')})")
62
65
  end
63
66
 
64
67
  def transform_svg(image_content, symbol)
@@ -66,7 +69,7 @@ module IpynbDiff
66
69
 
67
70
  single_line = lines.map(&:strip).join.gsub(/\s+/, ' ')
68
71
 
69
- [symbol, " ![](data:image/svg+xml;utf8,#{single_line})"]
72
+ _(symbol, " ![](data:image/svg+xml;utf8,#{single_line})")
70
73
  end
71
74
 
72
75
  def transform_text(text_content, symbol)
@@ -4,8 +4,8 @@ module IpynbDiff
4
4
  # Helper functions
5
5
  module SymbolizedMarkdownHelper
6
6
 
7
- def _(content = '')
8
- [nil, content]
7
+ def _(symbol = nil, content = '')
8
+ { symbol: symbol, content: content }
9
9
  end
10
10
 
11
11
  def array_if_not_array(thing)
@@ -14,9 +14,9 @@ module IpynbDiff
14
14
 
15
15
  def symbolize_array(symbol, content, &block)
16
16
  if content.is_a?(Array)
17
- content.map.with_index { |l, idx| [symbol / idx, block.call(l)] }
17
+ content.map.with_index { |l, idx| _(symbol / idx, block.call(l)) }
18
18
  else
19
- [symbol, content]
19
+ _(symbol, content)
20
20
  end
21
21
  end
22
22
  end
@@ -11,9 +11,9 @@ module IpynbDiff
11
11
 
12
12
  private
13
13
 
14
- def initialize(lines = [], symbols = [], symbol_map = {})
15
- @blocks = lines.zip(symbols).map do |line, symbol|
16
- { content: line, source_symbol: symbol, source_line: symbol && symbol_map[symbol] }
14
+ def initialize(lines = [], symbol_map = {})
15
+ @blocks = lines.map do |line|
16
+ { content: line[:content], source_symbol: (symbol = line[:symbol]), source_line: symbol && symbol_map[symbol] }
17
17
  end
18
18
  end
19
19
  end
data/lib/transformer.rb CHANGED
@@ -38,13 +38,7 @@ module IpynbDiff
38
38
  transformed = transform_document(notebook_json)
39
39
  symbol_map = IpynbSymbolMap.parse(notebook)
40
40
 
41
- symbols, lines = if transformed && !transformed.empty?
42
- transformed.partition.each_with_index { |_el, i| i.even? }
43
- else
44
- [[], []]
45
- end
46
-
47
- TransformedNotebook.new(lines, symbols, symbol_map)
41
+ TransformedNotebook.new(transformed, symbol_map)
48
42
  end
49
43
 
50
44
  def transform_document(notebook)
@@ -63,9 +57,9 @@ module IpynbDiff
63
57
  type = cell['cell_type'] || 'raw'
64
58
 
65
59
  [
66
- symbol, %(%% Cell type:#{type} id:#{cell['id']} tags:#{tags&.join(',')}),
60
+ _(symbol, %(%% Cell type:#{type} id:#{cell['id']} tags:#{tags&.join(',')})),
67
61
  _,
68
- *rows,
62
+ rows,
69
63
  _
70
64
  ]
71
65
  end
@@ -76,9 +70,9 @@ module IpynbDiff
76
70
 
77
71
  def transform_code_cell(cell, notebook, symbol)
78
72
  [
79
- symbol / 'source', %(``` #{notebook.dig('metadata', 'kernelspec', 'language') || ''}),
73
+ _(symbol / 'source', %(``` #{notebook.dig('metadata', 'kernelspec', 'language') || ''})),
80
74
  symbolize_array(symbol / 'source', cell['source'], &:rstrip),
81
- _('```'),
75
+ _(nil, '```'),
82
76
  cell['outputs'].map.with_index do |output, idx|
83
77
  @output_transformer.transform(output, symbol / ['outputs', idx])
84
78
  end
@@ -99,7 +93,7 @@ module IpynbDiff
99
93
  }
100
94
  }.to_yaml
101
95
 
102
- as_yaml.split("\n").map { |l| _(l) }.append(_('---'), _)
96
+ as_yaml.split("\n").map { |l| _(nil, l) }.append(_(nil, '---'), _)
103
97
  end
104
98
  end
105
99
  end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # lib/emoticon/version.rb
2
2
 
3
3
  module IpynbDiff
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipynbdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Bonet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-27 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy