ipynbdiff 0.4.2 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ipynb_symbol_map.rb +86 -17
- data/lib/transformer.rb +1 -0
- 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: 0f26544b121fc120490029ee5e708efbd1e90ad085e5bf973fbb29214a04d7c8
|
4
|
+
data.tar.gz: cbcfa68cdf53ce539374c3053b95d7ebb4e27e57d09bf77b23b1f1297bced097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897ddec211a46b69ab9cdd8a0ecddc946c67f1a51557f7205a305ae1ce35a32890120a1cb640082b4f3d7e8739c2172e56085d2987badfa32775adc48ca87b1d
|
7
|
+
data.tar.gz: 7516f6c3b5ac3d2a38f3ea78c54f293b49643260321f4ca452d46d4adc11e6d9447de4938cc5cb9de2c6b9d9b71abebf407de7252edffe3df51e997c919622fe
|
data/lib/ipynb_symbol_map.rb
CHANGED
@@ -7,8 +7,8 @@ module IpynbDiff
|
|
7
7
|
# Creates a symbol map for a ipynb file (JSON format)
|
8
8
|
class IpynbSymbolMap
|
9
9
|
class << self
|
10
|
-
def parse(notebook)
|
11
|
-
IpynbSymbolMap.new(notebook).parse('')
|
10
|
+
def parse(notebook, objects_to_ignore = [])
|
11
|
+
IpynbSymbolMap.new(notebook, objects_to_ignore).parse('')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -18,14 +18,17 @@ module IpynbDiff
|
|
18
18
|
|
19
19
|
VALUE_STOPPERS = [',', '[', ']', '{', '}', *WHITESPACE_CHARS].freeze
|
20
20
|
|
21
|
-
def initialize(notebook)
|
21
|
+
def initialize(notebook, objects_to_ignore = [])
|
22
22
|
@chars = notebook.chars
|
23
23
|
@current_line = 0
|
24
24
|
@char_idx = 0
|
25
25
|
@results = {}
|
26
|
+
@objects_to_ignore = objects_to_ignore
|
26
27
|
end
|
27
28
|
|
28
29
|
def parse(prefix = '.')
|
30
|
+
raise_if_file_ended
|
31
|
+
|
29
32
|
skip_whitespaces
|
30
33
|
|
31
34
|
if (c = current_char) == '"'
|
@@ -49,6 +52,8 @@ module IpynbDiff
|
|
49
52
|
current_should_be '['
|
50
53
|
|
51
54
|
loop do
|
55
|
+
raise_if_file_ended
|
56
|
+
|
52
57
|
break if skip_beginning(']')
|
53
58
|
|
54
59
|
new_prefix = "#{prefix}.#{i}"
|
@@ -67,13 +72,11 @@ module IpynbDiff
|
|
67
72
|
current_should_be '{'
|
68
73
|
|
69
74
|
loop do
|
70
|
-
|
71
|
-
|
72
|
-
prop_name = parse_string
|
75
|
+
raise_if_file_ended
|
73
76
|
|
74
|
-
|
77
|
+
break if skip_beginning('}')
|
75
78
|
|
76
|
-
|
79
|
+
prop_name = parse_string(return_value: true)
|
77
80
|
|
78
81
|
next_and_skip_whitespaces
|
79
82
|
|
@@ -81,24 +84,34 @@ module IpynbDiff
|
|
81
84
|
|
82
85
|
next_and_skip_whitespaces
|
83
86
|
|
84
|
-
|
87
|
+
if @objects_to_ignore.include? prop_name
|
88
|
+
skip
|
89
|
+
else
|
90
|
+
new_prefix = "#{prefix}.#{prop_name}"
|
91
|
+
|
92
|
+
add_result(new_prefix, current_line)
|
93
|
+
|
94
|
+
parse(new_prefix)
|
95
|
+
end
|
85
96
|
end
|
86
97
|
end
|
87
98
|
|
88
|
-
def parse_string
|
89
|
-
value = ''
|
90
|
-
prev_char = nil
|
91
|
-
|
99
|
+
def parse_string(return_value: false)
|
92
100
|
current_should_be '"'
|
101
|
+
init_idx = @char_idx
|
93
102
|
|
94
103
|
loop do
|
95
104
|
increment_char_index
|
96
|
-
break if (c = current_char) == '"' && prev_char != '\\'
|
97
105
|
|
98
|
-
|
106
|
+
raise_if_file_ended
|
107
|
+
|
108
|
+
if current_char == '"' && !prev_backslash?
|
109
|
+
init_idx += 1
|
110
|
+
break
|
111
|
+
end
|
99
112
|
end
|
100
113
|
|
101
|
-
|
114
|
+
@chars[init_idx...@char_idx].join if return_value
|
102
115
|
end
|
103
116
|
|
104
117
|
def add_result(key, line_number)
|
@@ -106,11 +119,12 @@ module IpynbDiff
|
|
106
119
|
end
|
107
120
|
|
108
121
|
def parse_value
|
109
|
-
increment_char_index until VALUE_STOPPERS.include?(current_char)
|
122
|
+
increment_char_index until raise_if_file_ended || VALUE_STOPPERS.include?(current_char)
|
110
123
|
end
|
111
124
|
|
112
125
|
def skip_whitespaces
|
113
126
|
while WHITESPACE_CHARS.include?(current_char)
|
127
|
+
raise_if_file_ended
|
114
128
|
check_for_new_line
|
115
129
|
increment_char_index
|
116
130
|
end
|
@@ -126,9 +140,15 @@ module IpynbDiff
|
|
126
140
|
end
|
127
141
|
|
128
142
|
def current_char
|
143
|
+
raise_if_file_ended
|
144
|
+
|
129
145
|
@chars[@char_idx]
|
130
146
|
end
|
131
147
|
|
148
|
+
def prev_backslash?
|
149
|
+
@chars[@char_idx - 1] == '\\' && @chars[@char_idx - 2] != '\\'
|
150
|
+
end
|
151
|
+
|
132
152
|
def current_should_be(another_char)
|
133
153
|
raise InvalidTokenError unless current_char == another_char
|
134
154
|
end
|
@@ -137,6 +157,55 @@ module IpynbDiff
|
|
137
157
|
@current_line += 1 if current_char == "\n"
|
138
158
|
end
|
139
159
|
|
160
|
+
def raise_if_file_ended
|
161
|
+
@char_idx >= @chars.size && raise(InvalidTokenError)
|
162
|
+
end
|
163
|
+
|
164
|
+
def skip
|
165
|
+
raise_if_file_ended
|
166
|
+
|
167
|
+
skip_whitespaces
|
168
|
+
|
169
|
+
if (c = current_char) == '"'
|
170
|
+
parse_string
|
171
|
+
elsif c == '['
|
172
|
+
skip_array
|
173
|
+
elsif c == '{'
|
174
|
+
skip_object
|
175
|
+
else
|
176
|
+
parse_value
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def skip_array
|
181
|
+
loop do
|
182
|
+
raise_if_file_ended
|
183
|
+
|
184
|
+
break if skip_beginning(']')
|
185
|
+
|
186
|
+
skip
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def skip_object
|
191
|
+
|
192
|
+
loop do
|
193
|
+
raise_if_file_ended
|
194
|
+
|
195
|
+
break if skip_beginning('}')
|
196
|
+
|
197
|
+
parse_string
|
198
|
+
|
199
|
+
next_and_skip_whitespaces
|
200
|
+
|
201
|
+
current_should_be ':'
|
202
|
+
|
203
|
+
next_and_skip_whitespaces
|
204
|
+
|
205
|
+
skip
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
140
209
|
def skip_beginning(closing_char)
|
141
210
|
|
142
211
|
check_for_new_line
|
data/lib/transformer.rb
CHANGED
@@ -15,6 +15,7 @@ module IpynbDiff
|
|
15
15
|
include SymbolizedMarkdownHelper
|
16
16
|
|
17
17
|
@include_frontmatter = true
|
18
|
+
@objects_to_ignore = ['application/javascript', 'application/vnd.holoviews_load.v0+json']
|
18
19
|
|
19
20
|
def initialize(include_frontmatter: true)
|
20
21
|
@include_frontmatter = include_frontmatter
|
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.5
|
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-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|