rodiff 1.0.0-x64-mingw-ucrt → 1.1.1-x64-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bd7b4b9051d81a3f39514eecd4b8ab48da416fcd800e4fc41a37e993f0b8687
4
- data.tar.gz: f94957ac0f7b9714336bdf4e9d0e1b9775599ec12418e2f4162c32ded4ff3c44
3
+ metadata.gz: fe5ddaf83f5b8ddd67111611bee0724d4719f23a4519bdfa1181c96a84b023c4
4
+ data.tar.gz: 50b2f48577fc927f6f0afec2485250ad08e78a23cb677be4a3b694c530870a12
5
5
  SHA512:
6
- metadata.gz: aa32f81d35576e721f4d9631771678ee101153a47d3d978a22a00102f1f8bbd1ddb5548809cb7245f162f3b9d62fa60eed3490990d643116f08129f9dee10634
7
- data.tar.gz: f463b797bfc946f93146caeedd0b4571952c82c0783d78eef9f5e7bef93dd685cd51be1d3ced9fcaefdcce3bf9c55eb4d8d30decfeda4f5c8da79826bf8bb795
6
+ metadata.gz: d46742e0069820e00c02fdbd9f10f012dff4afdb0b2de224e7fbaf331e88b5d36b3aeeeb98172d3bab0a539ec8eaeac4be80635827b99398a7f34ded0cf7a44d
7
+ data.tar.gz: e1378c82624ef804714b3c4a8120528902b7613181dea54f126c226b584499528a2cb35d7815aa6a0b4068ea76b3068d829ce2df87efe3680331e12e3dcccd94
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # rodiff
2
2
 
3
- A ruby wrapper for [Odiff](https://github.com/dmtrKovalenko/odiff), an image comparison tool written in OCamel.
3
+ [![Version][rubygems_badge]][rubygems]
4
+ [![CI][ci_badge]][ci_workflows]
5
+ [![Coverage][coverage_badge]][coverage]
6
+ [![Maintainability][maintainability_badge]][maintainability]
4
7
 
8
+ A ruby image comparison tool powered by [Odiff](https://github.com/dmtrKovalenko/odiff) in OCamel.
5
9
 
6
10
  ## Motivation
7
11
 
@@ -27,7 +31,7 @@ This gem wraps the [standalone executable](https://github.com/dmtrKovalenko/odif
27
31
  Supported platforms are:
28
32
  - arm64-darwin (macos-arm64)
29
33
  - x64-mingw32 (windows-x64)
30
- - x64-mingw-ucr (windows-x64)
34
+ - x64-mingw-ucrt (windows-x64)
31
35
  - x86_64-darwin (macos-x64)
32
36
  - x86_64-linux (linux-x64)
33
37
 
@@ -35,7 +39,7 @@ Supported platforms are:
35
39
 
36
40
  If you are not able to use the vendored standalone executables, a local installation of the `Odiff` executable can be configured by setting an environment variable named `ODIFF_INSTALL_DIR` to the directory path containing the executable.
37
41
 
38
- For example, if you've installed `odiff` via npm which could be something like `/path/to/node_modules/bin/odiff`, then you should set your environment variable like so:
42
+ For example, if you've installed the [`odiff-bin`](https://github.com/dmtrKovalenko/odiff#cross-platform) npm package and had the binaries downloaded at `/path/to/node_modules/bin/odiff`, then you should set your environment variable like so:
39
43
 
40
44
  ``` sh
41
45
  ODIFF_INSTALL_DIR=/path/to/node_modules/bin
@@ -93,4 +97,17 @@ See https://bundler.io/man/bundle-config.1.html for more information.
93
97
  ## License
94
98
 
95
99
  Rodiff is released under the [MIT License](https://opensource.org/licenses/MIT).
96
- Odiff is released under the [MIT License](https://opensource.org/licenses/MIT).
100
+ Odiff is released under the [MIT License](https://opensource.org/licenses/MIT).
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/ryancyq/rodiff](https://github.com/ryancyq/rodiff).
105
+
106
+ [rubygems_badge]: https://img.shields.io/gem/v/rodiff.svg
107
+ [rubygems]: https://rubygems.org/gems/rodiff
108
+ [ci_badge]: https://github.com/ryancyq/rodiff/actions/workflows/ci.yml/badge.svg
109
+ [ci_workflows]: https://github.com/ryancyq/rodiff/actions/workflows/ci.yml
110
+ [coverage_badge]: https://codecov.io/gh/ryancyq/rodiff/graph/badge.svg?token=SYR7FSDWT5
111
+ [coverage]: https://codecov.io/gh/ryancyq/rodiff
112
+ [maintainability_badge]: https://api.codeclimate.com/v1/badges/d5b1002a1a7162f86a7a/maintainability
113
+ [maintainability]: https://codeclimate.com/github/ryancyq/rodiff/maintainability
data/exe/rodiff CHANGED
@@ -1,23 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
2
 
4
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
4
 
6
5
  require "rodiff/cli"
7
6
 
8
- begin
9
- verbose = ARGV.delete "--verbose"
10
- command = [Rodiff::CLI.executable, *ARGV]
11
- puts "rodiff: #{command.inspect}" if verbose
12
-
13
- if Gem.win_platform?
14
- # use system rather than exec as exec inexplicably fails to find the executable on Windows
15
- # see related https://github.com/rubys/sprockets-esbuild/pull/4
16
- system(*command, exception: true)
17
- else
18
- exec(*command)
19
- end
20
- rescue Rodiff::CLI::CommandError => e
21
- warn("ERROR: #{e.message}")
22
- exit 1
23
- end
7
+ # set invoked_via_subcommand to ensure default command is used
8
+ Rodiff::CLI.start(ARGV, invoked_via_subcommand: true)
data/lib/rodiff/cli.rb CHANGED
@@ -1,87 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rodiff/odiff"
3
+ require "thor"
4
+ require "open3"
5
+ require "shellwords"
4
6
 
5
- module Rodiff
6
- class CLI
7
- DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe"))
8
-
9
- class CommandError < StandardError; end
7
+ require "rodiff/configuration"
8
+ require "rodiff/error"
9
+ require "rodiff/version"
10
10
 
11
- class UnsupportedPlatform < CommandError
12
- def initialize(platform)
13
- super(
14
- <<~MSG
15
- odiff does not support the #{platform} platform
16
- Please install odiff following instructions at https://github.com/dmtrKovalenko/odiff#installation
17
- MSG
18
- )
11
+ module Rodiff
12
+ class CLI < Thor
13
+ package_name "rodiff"
14
+
15
+ default_command :compare
16
+
17
+ desc "version", "Print version"
18
+ map ["-v", "--version"] => :version
19
+ method_option :odiff, type: :boolean, required: false
20
+ def version
21
+ if options.odiff?
22
+ odiff_exec("--version")
23
+ else
24
+ say Rodiff::VERSION
19
25
  end
20
26
  end
21
27
 
22
- class ExecutableNotFound < CommandError
23
- def initialize(platform, exe_path)
24
- super(
25
- <<~MSG
26
- Cannot find the odiff executable for #{platform} in #{exe_path}
27
-
28
- If you're using bundler, please make sure you're on the latest bundler version:
29
-
30
- gem install bundler
31
- bundle update --bundler
28
+ desc "compare [BASELINE] [VARIANT] [DIFF]", "Compare VARIANT against BASELINE, output to DIFF"
29
+ method_option :verbose, type: :boolean, default: false
30
+ def compare(baseline = nil, variant = nil, diff = nil)
31
+ all_present, all_absent = args_presence(baseline, variant, diff)
32
+ raise ArgumentError, "BASELINE, VARIANT, DIFF must be provided" unless all_present ^ all_absent
32
33
 
33
- Then make sure your lock file includes this platform by running:
34
-
35
- bundle lock --add-platform #{platform}
36
- bundle install
37
-
38
- See `bundle lock --help` output for details.
39
-
40
- If you're still seeing this message after taking those steps, try running
41
- `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
42
- https://github.com/ryancyq/rodiff#check-bundle_force_ruby_platform
43
- for more details.
44
- MSG
45
- )
46
- end
34
+ odiff_exec(baseline, variant, diff)
35
+ rescue Rodiff::Error => e
36
+ raise Thor::Error, "ERROR: #{e.message}"
47
37
  end
48
38
 
49
- class InstallDirectoryNotFound < CommandError
50
- def initialize(install_dir)
51
- super("ODIFF_INSTALL_DIR is set to #{install_dir}, but that directory does not exist.")
52
- end
39
+ def self.exit_on_failure?
40
+ true
53
41
  end
54
42
 
55
- class << self
56
- def platform
57
- %i[cpu os].map { |m| Gem::Platform.local.public_send(m) }.join("-")
58
- end
43
+ private
59
44
 
60
- def supported_platform?(platform = nil)
61
- return Gem::Platform.match_gem?(Gem::Platform.new(platform), "rodiff") unless platform.nil?
45
+ def config
46
+ Rodiff.configuration
47
+ end
62
48
 
63
- Rodiff::Odiff::PLATFORMS.keys.any? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), "rodiff") }
49
+ def args_presence(*args)
50
+ args.each_with_object([true, true]) do |e, acc|
51
+ acc[0] = false if e.nil? || e == ""
52
+ acc[1] = false unless e.nil? || e == ""
64
53
  end
54
+ end
65
55
 
66
- def executable(exe_path: DEFAULT_DIR)
67
- if (odiff_install_dir = ENV.fetch("ODIFF_INSTALL_DIR", nil))
68
- raise InstallDirectoryNotFound, odiff_install_dir unless File.directory?(odiff_install_dir)
69
-
70
- warn "NOTE: using ODIFF_INSTALL_DIR to find odiff executable: #{odiff_install_dir}"
71
- exe_path = odiff_install_dir
72
- exe_file = File.expand_path(File.join(odiff_install_dir, "odiff"))
73
- else
74
- raise UnsupportedPlatform, platform unless supported_platform?
75
-
76
- exe_files_of_platforms = File.expand_path(File.join(exe_path, "*", "odiff"))
77
- exe_file = Dir.glob(exe_files_of_platforms).find do |f|
78
- supported_platform?(File.basename(File.dirname(f)))
79
- end
80
- end
81
-
82
- raise ExecutableNotFound.new(platform, exe_path) if exe_file.nil? || !File.exist?(exe_file)
83
-
84
- exe_file
56
+ def odiff_exec(*cmd)
57
+ cmd_parts = []
58
+ cmd_parts << config.odiff_exe_path
59
+ cmd_parts.push(*cmd)
60
+
61
+ stdout, stderr, status = Open3.capture3(*cmd_parts)
62
+ if block_given?
63
+ yield stdout, stderr, status
64
+ else
65
+ say_error stderr unless stderr.nil? || stderr == ""
66
+ say stdout unless stdout.nil? || stdout == ""
85
67
  end
86
68
  end
87
69
  end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rodiff/error"
4
+ require "rodiff/executable"
5
+
6
+ module Rodiff
7
+ def self.configuration
8
+ @configuration ||= Rodiff::Configuration.new
9
+ end
10
+
11
+ def self.configure
12
+ yield configuration
13
+ end
14
+
15
+ class Configuration
16
+ class UnknownConfiguration < Rodiff::Error; end
17
+
18
+ ATTRS = Module.new.tap { |mod| include mod }
19
+ READER_ATTRS = {
20
+ default_dir: "/"
21
+ }.freeze
22
+
23
+ ACCESSOR_ATTRS = {
24
+ include_pattern: "{*,**/*}.jpg",
25
+ exclude_pattern: "",
26
+ compare_pattern: "",
27
+
28
+ ignore_antialiasing: false,
29
+ color_threshold: 0.1,
30
+ output_diff_mask: false,
31
+
32
+ exit_code_odiff: ->(code) { code },
33
+ exit_code_error: 1,
34
+ fail_if_no_comparison: false
35
+ }.freeze
36
+
37
+ def self.generate_config(mod, path, line, attrs)
38
+ mod.module_eval(Array(attrs).join(";").to_s, path, line)
39
+ end
40
+
41
+ def self.config_attribute(name, type:)
42
+ case type
43
+ when :reader, :writer, :accessor then "attr_#{type} :#{name}"
44
+ when :proxy
45
+ <<-RUBY
46
+ def #{name}
47
+ value_for(:#{name}) { super() }
48
+ end
49
+ RUBY
50
+ else
51
+ raise ArgumentError, "unsupported type #{type.inspect}"
52
+ end
53
+ end
54
+
55
+ generate_config ATTRS, __FILE__, __LINE__, [
56
+ *READER_ATTRS.keys.map { |key| config_attribute(key, type: :reader) },
57
+ *ACCESSOR_ATTRS.keys.map { |key| config_attribute(key, type: :accessor) }
58
+ ]
59
+
60
+ generate_config self, __FILE__, __LINE__, [
61
+ *READER_ATTRS.keys.map { |key| config_attribute(key, type: :proxy) },
62
+ *ACCESSOR_ATTRS.keys.map { |key| config_attribute(key, type: :proxy) }
63
+ ]
64
+
65
+ def initialize
66
+ @config_overrides = {}
67
+
68
+ READER_ATTRS.each { |key, value| instance_variable_set("@#{key}", value) }
69
+ ACCESSOR_ATTRS.each { |key, value| instance_variable_set("@#{key}", value) }
70
+ end
71
+
72
+ def odiff_exe_path
73
+ @odiff_exe_path ||= Rodiff::Executable.resolve
74
+ end
75
+
76
+ def odiff_exe_path=(path)
77
+ @odiff_exe_path = Rodiff::Executable.resolve(exe_path: path)
78
+ end
79
+
80
+ def overrides(opts = {})
81
+ opts.each_key { |key| validate_config_key!(key) }
82
+ @config_overrides.merge!(opts.transform_keys(&:to_sym))
83
+ end
84
+
85
+ private
86
+
87
+ def validate_config_key!(key)
88
+ return if READER_ATTRS.key?(key) || ACCESSOR_ATTRS.key?(key)
89
+
90
+ raise UnknownConfiguration, "unknown config #{key.inspect}"
91
+ end
92
+
93
+ def value_for(key, &block)
94
+ validate_config_key!(key)
95
+ @config_overrides.fetch(key, &block)
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rodiff
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rodiff/odiff"
4
+ require "rodiff/error"
5
+
6
+ module Rodiff
7
+ class Executable
8
+ DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe"))
9
+ LOCAL_INSTALL_DIR_ENV = "ODIFF_INSTALL_DIR"
10
+
11
+ class UnsupportedPlatform < Rodiff::Error
12
+ def initialize(platform)
13
+ super(
14
+ <<~MSG
15
+ odiff does not support the #{platform} platform
16
+ Please install odiff following instructions at https://github.com/dmtrKovalenko/odiff#installation
17
+ MSG
18
+ )
19
+ end
20
+ end
21
+
22
+ class ExecutableNotFound < Rodiff::Error
23
+ def initialize(platform, exe_path)
24
+ super(
25
+ <<~MSG
26
+ Cannot find the odiff executable for #{platform} in #{exe_path}
27
+
28
+ If you're using bundler, please make sure you're on the latest bundler version:
29
+
30
+ gem install bundler
31
+ bundle update --bundler
32
+
33
+ Then make sure your lock file includes this platform by running:
34
+
35
+ bundle lock --add-platform #{platform}
36
+ bundle install
37
+
38
+ See `bundle lock --help` output for details.
39
+
40
+ If you're still seeing this message after taking those steps, try running
41
+ `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
42
+ https://github.com/ryancyq/rodiff#check-bundle_force_ruby_platform
43
+ for more details.
44
+ MSG
45
+ )
46
+ end
47
+ end
48
+
49
+ class InstallDirectoryNotFound < Rodiff::Error
50
+ def initialize(install_dir)
51
+ super("#{LOCAL_INSTALL_DIR_ENV} is set to #{install_dir}, but that directory does not exist.")
52
+ end
53
+ end
54
+
55
+ class << self
56
+ def platform
57
+ %i[cpu os].map { |m| Gem::Platform.local.public_send(m) }.join("-")
58
+ end
59
+
60
+ def supported_platform?(platform = nil)
61
+ return Gem::Platform.match_gem?(Gem::Platform.new(platform), "rodiff") unless platform.nil?
62
+
63
+ Rodiff::Odiff::PLATFORMS.keys.any? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), "rodiff") }
64
+ end
65
+
66
+ def resolve(exe_path: DEFAULT_DIR)
67
+ if (odiff_install_dir = ENV.fetch(LOCAL_INSTALL_DIR_ENV, nil))
68
+ exe_path = odiff_install_dir
69
+ exe_file = expand_local_install_dir(odiff_install_dir)
70
+ elsif supported_platform?
71
+ exe_file = expand_bundled_dir(exe_path)
72
+ else
73
+ raise UnsupportedPlatform, platform
74
+ end
75
+
76
+ raise ExecutableNotFound.new(platform, exe_path) if exe_file.nil? || !File.exist?(exe_file)
77
+
78
+ exe_file
79
+ end
80
+
81
+ private
82
+
83
+ def expand_local_install_dir(local_install_dir)
84
+ raise InstallDirectoryNotFound, local_install_dir unless File.directory?(local_install_dir)
85
+
86
+ warn "NOTE: using #{LOCAL_INSTALL_DIR_ENV} to find odiff executable: #{local_install_dir}"
87
+ exe_files = File.expand_path(File.join(local_install_dir, "odiff{,.exe}"))
88
+ Dir.glob(exe_files).first
89
+ end
90
+
91
+ def expand_bundled_dir(bundled_dir)
92
+ exe_files_of_platforms = File.expand_path(File.join(bundled_dir, "*", "odiff"))
93
+ Dir.glob(exe_files_of_platforms).find do |f|
94
+ supported_platform?(File.basename(File.dirname(f)))
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
data/lib/rodiff/odiff.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Rodiff
4
4
  module Odiff
5
- VERSION = "v3.1.1"
5
+ VERSION = "3.1.1"
6
6
 
7
7
  # rubygems platform name => upstream release filename
8
8
  PLATFORMS = {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rodiff
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
data/lib/rodiff.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  module Rodiff
4
4
  end
5
5
 
6
- require_relative "rodiff/version"
7
- require_relative "rodiff/odiff"
8
- require_relative "rodiff/cli"
6
+ require "rodiff/error"
7
+ require "rodiff/configuration"
8
+ require "rodiff/executable"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Ryan Chang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.2
13
27
  description:
14
28
  email:
15
29
  - ryancyq@gmail.com
@@ -25,6 +39,9 @@ files:
25
39
  - exe/x64-mingw-ucrt/odiff
26
40
  - lib/rodiff.rb
27
41
  - lib/rodiff/cli.rb
42
+ - lib/rodiff/configuration.rb
43
+ - lib/rodiff/error.rb
44
+ - lib/rodiff/executable.rb
28
45
  - lib/rodiff/odiff.rb
29
46
  - lib/rodiff/version.rb
30
47
  homepage: https://github.com/ryancyq/rodiff
@@ -50,9 +67,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
67
  - !ruby/object:Gem::Version
51
68
  version: 3.2.0
52
69
  requirements:
53
- - odiff, v3.1.1
70
+ - odiff, >= 3.0
54
71
  rubygems_version: 3.5.16
55
72
  signing_key:
56
73
  specification_version: 4
57
- summary: A ruby wrapper for odiff
74
+ summary: A ruby image comparison tool powered by ODiff in OCamel
58
75
  test_files: []