ipynbdiff 0.4.0 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +25 -24
- data/ipynbdiff.gemspec +4 -1
- data/lib/ipynb_symbol_map.rb +12 -6
- data/lib/output_transformer.rb +10 -7
- data/lib/symbolized_markdown_helper.rb +4 -4
- data/lib/transformed_notebook.rb +3 -3
- data/lib/transformer.rb +6 -12
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4439ffa7f5fb1abc1243c5ab32d1196bb9bb37130c2a1eebe8461a4b0d1bf1bb
|
4
|
+
data.tar.gz: 1767b4eccbc36b2644cc2c5c4b50589b0b967dff46e50b4898c328e171adc1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86fd17c557336d668abfd4677e1883b20d7af02c75afcfe2d4357149953c54520578afd1c7b902591746a3b1ba113778e1794026b57fe44fcf53fc66ace4ddb0
|
7
|
+
data.tar.gz: 85b800b3776a519c471be72979a9a0ea186ad4a3251ff4276e2e732c9aed906fd8327ce9797ade66ada6734e248116e1b8338b6b035c607615b0fc21c602a136
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
- test
|
10
|
+
- build
|
11
|
+
- rubygems
|
8
12
|
specs:
|
9
13
|
stage: test
|
10
14
|
script:
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
- bundle install
|
16
|
+
- bundle exec rspec
|
14
17
|
build-gem:
|
15
18
|
stage: build
|
16
19
|
script:
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
25
|
-
|
27
|
+
- specs
|
26
28
|
deploy-gem:
|
27
29
|
stage: rubygems
|
28
30
|
script:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
36
|
+
- tags
|
35
37
|
except:
|
36
|
-
|
37
|
-
needs:
|
38
|
-
|
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
data/lib/ipynb_symbol_map.rb
CHANGED
@@ -86,19 +86,21 @@ module IpynbDiff
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def parse_string
|
89
|
-
value = ''
|
90
|
-
prev_char = nil
|
91
|
-
|
92
89
|
current_should_be '"'
|
90
|
+
init_idx = @char_idx
|
93
91
|
|
94
92
|
loop do
|
95
93
|
increment_char_index
|
96
|
-
break if (c = current_char) == '"' && prev_char != '\\'
|
97
94
|
|
98
|
-
|
95
|
+
break if @char_idx > @chars.length
|
96
|
+
|
97
|
+
if current_char == '"' && prev_char != '\\'
|
98
|
+
init_idx += 1
|
99
|
+
break
|
100
|
+
end
|
99
101
|
end
|
100
102
|
|
101
|
-
|
103
|
+
@chars[init_idx...@char_idx].join
|
102
104
|
end
|
103
105
|
|
104
106
|
def add_result(key, line_number)
|
@@ -129,6 +131,10 @@ module IpynbDiff
|
|
129
131
|
@chars[@char_idx]
|
130
132
|
end
|
131
133
|
|
134
|
+
def prev_char
|
135
|
+
@chars[@char_idx - 1]
|
136
|
+
end
|
137
|
+
|
132
138
|
def current_should_be(another_char)
|
133
139
|
raise InvalidTokenError unless current_char == another_char
|
134
140
|
end
|
data/lib/output_transformer.rb
CHANGED
@@ -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)
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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|
|
17
|
+
content.map.with_index { |l, idx| _(symbol / idx, block.call(l)) }
|
18
18
|
else
|
19
|
-
|
19
|
+
_(symbol, content)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/transformed_notebook.rb
CHANGED
@@ -11,9 +11,9 @@ module IpynbDiff
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
def initialize(lines = [],
|
15
|
-
@blocks = lines.
|
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
|
-
|
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
|
-
|
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
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.
|
4
|
+
version: 0.4.3
|
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-
|
11
|
+
date: 2022-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|