ipynbdiff 0.4.6 → 0.4.7

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: ff3a6405d5c4034108fee997d678bee634a516f1d773b0aa9e8c7e4f50b7f28e
4
- data.tar.gz: 3a80027ec239810e6b3daaa637fc338c5a34e3ae75c2f33043303eb6e16f6980
3
+ metadata.gz: '09eee5bd0bb92f76cdabc67bd9b4ac1050756f952f9b5a3b91aaef984f860b87'
4
+ data.tar.gz: d89a1289023f1c44af159847a91f9139746a9c0846de169494f6438917754ca4
5
5
  SHA512:
6
- metadata.gz: 6d126961600c8073f2ead97b26d2879f987f15d6e3c74f0c9e2bd64c020bc8fd7963f4b50a69fd28c98728c645b595dbdda5883f4f56e18aa949df589e3787d0
7
- data.tar.gz: 30e2c855b51de45ad2147419a455a4adc8f4f3cd30445f32a9667e3f17a072c3e59bcc8e603e34be2c7216e0b9671e2ed283e827780b4da25bff4be03f733ed6
6
+ metadata.gz: 24b0b3fa46237a5b2fff8ef253b1dc2b90d5c8650c406097dd86e525e3e8bd5d89568b9280897d85c88444eb993ce3f490b15b0c741dd57dbea6e227dce2abea
7
+ data.tar.gz: a61bedd1f3b227f1b06dc97ed40ba19136fe4b157b9c0767887bbf22ee036bbbdfb21db3311c4b07a0e7ba39310f4cf8abd37dc8e7973c2035462478428bdd75
data/README.md CHANGED
@@ -1,19 +1,18 @@
1
1
  # IpynbDiff: Better diff for Jupyter Notebooks
2
2
 
3
- This is a simple diff tool that cleans up jupyter notebooks, transforming each [notebook](example/1/from.ipynb)
3
+ This is a simple diff tool that cleans up Jupyter notebooks, transforming each [notebook](example/1/from.ipynb)
4
4
  into a [readable markdown file](example/1/from_html.md), keeping the output of cells, and running the
5
5
  diff after. Markdowns are generated using an opinionated Jupyter to Markdown conversion. This means
6
6
  that the entire file is readable on the diff.
7
7
 
8
8
  The result are diffs that are much easier to read:
9
9
 
10
- | Diff | | IpynbDiff |
11
- | ------ | ------ |
12
- | [Here](example/diff.txt) | [Here](example/ipynbdiff_percent.txt) |
13
- | ![](example/img/diff.png) | ![](example/img/ipynbdiff_percent.png) |
10
+ | Diff | IpynbDiff |
11
+ | ----------------------------------- | ----------------------------------------------------- |
12
+ | [Diff text](example/diff.txt) | [IpynbDiff text](example/ipynbdiff_percent.txt) |
13
+ | ![Diff image](example/img/diff.png) | ![IpynbDiff image](example/img/ipynbdiff_percent.png) |
14
14
 
15
-
16
- This started as a port of This is a port of [ipynbdiff](https://gitlab.com/gitlab-org/incubation-engineering/mlops/ipynbdiff),
15
+ This started as a port of [ipynbdiff](https://gitlab.com/gitlab-org/incubation-engineering/mlops/poc/ipynbdiff),
17
16
  but now has extended functionality although not working as git driver.
18
17
 
19
18
  ## Usage
data/lib/ipynbdiff.rb CHANGED
@@ -5,18 +5,18 @@ module IpynbDiff
5
5
  require 'transformer'
6
6
  require 'diff'
7
7
 
8
- def self.diff(from, to, raise_if_invalid_nb: false, include_frontmatter: false, diffy_opts: {})
9
- transformer = Transformer.new(include_frontmatter: include_frontmatter)
8
+ def self.diff(from, to, raise_if_invalid_nb: false, include_frontmatter: false, hide_images: false, diffy_opts: {})
9
+ transformer = Transformer.new(include_frontmatter: include_frontmatter, hide_images: hide_images)
10
10
 
11
11
  Diff.new(transformer.transform(from), transformer.transform(to), diffy_opts)
12
12
  rescue InvalidNotebookError
13
13
  raise if raise_if_invalid_nb
14
14
  end
15
15
 
16
- def self.transform(notebook, raise_errors: false, include_frontmatter: true)
16
+ def self.transform(notebook, raise_errors: false, include_frontmatter: true, hide_images: false)
17
17
  return unless notebook
18
18
 
19
- Transformer.new(include_frontmatter: include_frontmatter).transform(notebook).as_text
19
+ Transformer.new(include_frontmatter: include_frontmatter, hide_images: hide_images).transform(notebook).as_text
20
20
  rescue InvalidNotebookError
21
21
  raise if raise_errors
22
22
  end
@@ -6,12 +6,18 @@ module IpynbDiff
6
6
  require 'symbolized_markdown_helper'
7
7
  include SymbolizedMarkdownHelper
8
8
 
9
+ HIDDEN_IMAGE_OUTPUT = ' [Hidden Image Output]'
10
+
9
11
  ORDERED_KEYS = {
10
12
  'execute_result' => %w[image/png image/svg+xml image/jpeg text/markdown text/latex text/plain],
11
13
  'display_data' => %w[image/png image/svg+xml image/jpeg text/markdown text/latex],
12
14
  'stream' => %w[text]
13
15
  }.freeze
14
16
 
17
+ def initialize(hide_images: false)
18
+ @hide_images = hide_images
19
+ end
20
+
15
21
  def transform(output, symbol)
16
22
  transformed = case (output_type = output['output_type'])
17
23
  when 'error'
@@ -61,6 +67,8 @@ module IpynbDiff
61
67
  end
62
68
 
63
69
  def transform_image(image_type, image_content, symbol)
70
+ return _(nil, HIDDEN_IMAGE_OUTPUT) if @hide_images
71
+
64
72
  lines = image_content.is_a?(Array) ? image_content : [image_content]
65
73
 
66
74
  single_line = lines.map(&:strip).join.gsub(/\s+/, ' ')
data/lib/transformer.rb CHANGED
@@ -17,9 +17,10 @@ module IpynbDiff
17
17
  @include_frontmatter = true
18
18
  @objects_to_ignore = ['application/javascript', 'application/vnd.holoviews_load.v0+json']
19
19
 
20
- def initialize(include_frontmatter: true)
20
+ def initialize(include_frontmatter: true, hide_images: false)
21
21
  @include_frontmatter = include_frontmatter
22
- @output_transformer = OutputTransformer.new
22
+ @hide_images = hide_images
23
+ @output_transformer = OutputTransformer.new(hide_images: hide_images)
23
24
  end
24
25
 
25
26
  def validate_notebook(notebook)
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.6"
4
+ VERSION = "0.4.7"
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.6
4
+ version: 0.4.7
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-04-25 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy