ruby-gr 0.0.24 → 0.61.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,41 +5,47 @@
5
5
  # It should not be loaded when gr_commons/gr_commons is loaded.
6
6
 
7
7
  require 'logger'
8
- require 'rainbow'
9
- require 'awesome_print'
8
+ require 'pp'
10
9
 
11
10
  module GRCommons
11
+ # Convenience class methods
12
+
12
13
  class << self
13
14
  # Create a new GRLogger
14
- # @params out [String]
15
+ # @param out [String]
15
16
  # @return [GRLogger]
16
17
  # @example
17
18
  # require 'gr_commons/gr_logger'
18
19
  # GRCommons.gr_log("log.txt")
20
+
19
21
  def gr_log(out = $stderr)
20
22
  GRCommons::GRLogger.new(out)
21
23
  end
22
24
 
23
25
  # Return the last created GRLogger
24
26
  # @return [GRLogger]
27
+
25
28
  def gr_logger
26
29
  GRCommons::GRLogger.logger
27
30
  end
28
31
  end
29
32
 
30
- # Outputs function calls to GR Framework to a log file.
31
- # Mainly used for debugging.
32
- # @note This module is for those who want to see low-level function calls in GR.
33
+ # If GR.rb call native functions of the GR framework,
34
+ # it will be recorded in the log file.
35
+ #
36
+ # @note Mainly used by developers for debugging.
33
37
  #
34
38
  # = How it works 
35
- # prepend a module named Inspector to the singular class
36
- # of the FFI module. It will inspects the GR function call of the FFI module
39
+ # It prepend a module named Inspector to the singular class of the FFI module.
40
+ # It will inspects the GR function call of the FFI module
37
41
  #
38
42
  # @example
39
43
  # require 'gr_commons/gr_logger'
40
- # GRCommons.gr_log("log.txt")
44
+ # GRCommons::GRLogger.new("log.txt")
45
+
41
46
  class GRLogger < Logger
42
47
  # Return the last created GRLogger
48
+
43
49
  def self.logger
44
50
  @@logger ||= GRCommons::GRLogger.new
45
51
  end
@@ -51,13 +57,15 @@ module GRCommons
51
57
  end
52
58
  end
53
59
 
60
+ # GR
61
+
54
62
  if Object.const_defined?(:GR)
55
63
  module GR
56
64
  module FFI
57
65
  module Inspector
58
66
  GR::FFI.ffi_methods.each do |s|
59
67
  define_method(s) do |*args|
60
- GRCommons.gr_logger.info "GR::FFI.#{s}\n" + args.ai + "\n"
68
+ GRCommons.gr_logger.info "GR::FFI.#{s}\n#{args.pretty_inspect}\n"
61
69
  super(*args)
62
70
  end
63
71
  end
@@ -69,13 +77,15 @@ if Object.const_defined?(:GR)
69
77
  end
70
78
  end
71
79
 
80
+ # GR3
81
+
72
82
  if Object.const_defined?(:GR3)
73
83
  module GR3
74
84
  module FFI
75
85
  module Inspector
76
86
  GR3::FFI.ffi_methods.each do |s|
77
87
  define_method(s) do |*args|
78
- GRCommons.gr_logger.info "GR3::FFI.#{s}\n" + args.ai + "\n"
88
+ GRCommons.gr_logger.info "GR3::FFI.#{s}\n#{args.pretty_inspect}\n"
79
89
  super(*args)
80
90
  end
81
91
  end
@@ -87,13 +97,15 @@ if Object.const_defined?(:GR3)
87
97
  end
88
98
  end
89
99
 
100
+ # GRM
101
+
90
102
  if Object.const_defined?(:GRM)
91
103
  module GRM
92
104
  module FFI
93
105
  module Inspector
94
106
  GRM::FFI.ffi_methods.each do |s|
95
107
  define_method(s) do |*args|
96
- GRCommons.gr_logger.info "GRM::FFI.#{s}\n" + args.ai + "\n"
108
+ GRCommons.gr_logger.info "GRM::FFI.#{s}\n#{args.pretty_inspect}\n"
97
109
  super(*args)
98
110
  end
99
111
  end
@@ -8,7 +8,7 @@ module GRCommons
8
8
  # Sets the environment variable when the module is extended.
9
9
  def self.extended(_obj)
10
10
  require 'tmpdir'
11
- ENV['GKSwstype'] = 'svg'
11
+ ENV['GKS_WSTYPE'] = 'svg'
12
12
  ENV['GKS_FILEPATH'] = Dir::Tmpname.create('plot-') {}
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ module GRCommons
16
16
  def show(display = true)
17
17
  emergencyclosegks
18
18
  sleep 0.5
19
- type = ENV['GKSwstype']
19
+ type = ENV['GKS_WSTYPE']
20
20
  case type
21
21
  when 'svg'
22
22
  data = File.read("#{ENV['GKS_FILEPATH']}.svg")
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GRCommons
4
4
  # This module records the names of the methods defined by Fiddle::Importer.
5
- module Extern
5
+ module TryExtern
6
6
  attr_reader :ffi_methods
7
7
 
8
8
  # Improved extern method.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.24'
4
+ VERSION = '0.61.0.0'
5
5
  end
data/lib/grm/ffi.rb CHANGED
@@ -15,7 +15,7 @@ module GRM
15
15
  raise LoadError, 'Could not find GR Framework'
16
16
  end
17
17
 
18
- extend GRCommons::Extern
18
+ extend GRCommons::TryExtern
19
19
 
20
20
  # Currently, the declarations of GRM functions are distributed in several
21
21
  # header files.
@@ -28,6 +28,7 @@ module GRM
28
28
  try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
29
29
  try_extern 'void grm_args_clear(grm_args_t *args)'
30
30
  try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
31
+ typealias 'grm_args_ptr_t', 'void*'
31
32
  try_extern 'grm_args_ptr_t grm_length(double value, const char *unit)'
32
33
 
33
34
  # https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
@@ -36,13 +37,17 @@ module GRM
36
37
  try_extern 'char *grm_dump_json_str(void)'
37
38
 
38
39
  # https://github.com/sciapp/gr/blob/master/lib/grm/event.h
40
+ typealias 'grm_event_type_t', 'int' # enum
41
+ typealias 'grm_event_callback_t', 'void*'
39
42
  try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
40
43
  try_extern 'int grm_unregister(grm_event_type_t type)'
41
44
 
42
45
  # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
46
+ # FIXME: https://github.com/ruby/fiddle/issues/68
47
+ typealias 'const_int', 'int' # FIXME
43
48
  try_extern 'int grm_input(const grm_args_t *input_args)'
44
- try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
45
- try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
49
+ try_extern 'int grm_get_box(const_int x1, const_int y1, const_int x2, const_int y2, const_int keep_aspect_ratio, int *x, int *y, int *w, int *h)' # FIXME
50
+ try_extern 'grm_tooltip_info_t *grm_get_tooltip(const_int, const_int)' # FIXME
46
51
 
47
52
  # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
48
53
  try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
data/lib/grm.rb CHANGED
@@ -17,23 +17,37 @@ end
17
17
  module GRM
18
18
  class Error < StandardError; end
19
19
 
20
+ class NotFoundError < Error; end
21
+
20
22
  class << self
21
23
  attr_accessor :ffi_lib
22
24
  end
23
25
 
24
26
  require_relative 'gr_commons/gr_commons'
25
- extend GRCommons::SearchSharedLibrary
26
27
 
27
28
  # Platforms | path
28
29
  # Windows | bin/libGRM.dll
29
- # MacOSX | lib/libGRM.so (NOT .dylib)
30
+ # MacOSX | lib/libGRM.dylib ( <= v0.53.0 .so)
30
31
  # Ubuntu | lib/libGRM.so
31
- self.ffi_lib = case RbConfig::CONFIG['host_os']
32
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
33
- search_shared_library('libGRM.dll', 'grm')
34
- else
35
- search_shared_library('libGRM.so', 'grm')
36
- end
32
+ platform = RbConfig::CONFIG['host_os']
33
+ lib_names, pkg_name = \
34
+ case platform
35
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
36
+ [['libGRM.dll'], 'grm']
37
+ when /darwin|mac os/
38
+ ENV['GKSwstype'] ||= 'gksqt'
39
+ [['libGRM.dylib', 'libGRM.so'], 'grm']
40
+ else
41
+ [['libGRM.so'], 'grm']
42
+ end
43
+
44
+ # On Windows + RubyInstaller,
45
+ # the environment variable GKS_FONTPATH will be set.
46
+ lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
47
+
48
+ raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
49
+
50
+ self.ffi_lib = lib_path
37
51
 
38
52
  require_relative 'grm/version'
39
53
  require_relative 'grm/ffi'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.61.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: histogram
@@ -52,90 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 12.3.3
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 12.3.3
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: test-unit
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
55
  description: GR framework - the graphics library for visualisation - for Ruby
140
56
  email: 2xijok@gmail.com
141
57
  executables: []
@@ -154,13 +70,13 @@ files:
154
70
  - lib/gr3/gr3base.rb
155
71
  - lib/gr3/version.rb
156
72
  - lib/gr_commons/define_methods.rb
157
- - lib/gr_commons/extern.rb
158
73
  - lib/gr_commons/fiddley.rb
159
74
  - lib/gr_commons/gr_common_utils.rb
160
75
  - lib/gr_commons/gr_commons.rb
76
+ - lib/gr_commons/gr_lib.rb
161
77
  - lib/gr_commons/gr_logger.rb
162
78
  - lib/gr_commons/jupyter_support.rb
163
- - lib/gr_commons/search_shared_library.rb
79
+ - lib/gr_commons/try_extern.rb
164
80
  - lib/gr_commons/version.rb
165
81
  - lib/grm.rb
166
82
  - lib/grm/ffi.rb
@@ -186,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
102
  - !ruby/object:Gem::Version
187
103
  version: '0'
188
104
  requirements: []
189
- rubygems_version: 3.1.4
105
+ rubygems_version: 3.2.26
190
106
  signing_key:
191
107
  specification_version: 4
192
108
  summary: GR for Ruby
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pkg-config'
4
-
5
- module GRCommons
6
- # This module helps GR, GR and GRM to search the shared library.
7
- #
8
- # The order of priority:
9
- # 1. RubyInstaller ( for Windows only )
10
- # 2. Environment variable GRDIR
11
- # 3. pkg-config : https://github.com/ruby-gnome/pkg-config
12
- # The following packages (should) support pkg-config.
13
- # - Linux
14
- # - Red Data Tools https://github.com/red-data-tools/packages.red-data-tools.org
15
- # - libgr-dev
16
- # - libgr3-dev
17
- # - libgrm-dev
18
- # - Mac
19
- # - Homebrew https://github.com/Homebrew/homebrew-core
20
- # - libgr
21
- # - Windows
22
- # - MinGW https://github.com/msys2/MINGW-packages
23
- # - mingw-w64-gr
24
- module SearchSharedLibrary
25
- # Search the shared library.
26
- # @note This method does not detect the Operating System.
27
- #
28
- # @param gr_lib_name [String] The actual file name of the shared library.
29
- # @param pkg_name [String] The package name to be used when searching with pkg-configg
30
- def search_shared_library(gr_lib_name, pkg_name)
31
- # Windows + RubyInstaller
32
- if Object.const_defined?(:RubyInstaller)
33
- ENV['GRDIR'] ||= [
34
- RubyInstaller::Runtime.msys2_installation.msys_path,
35
- RubyInstaller::Runtime.msys2_installation.mingwarch
36
- ].join(File::ALT_SEPARATOR)
37
- recursive_search(gr_lib_name, ENV['GRDIR']).tap do |path|
38
- RubyInstaller::Runtime.add_dll_directory(File.dirname(path))
39
- end
40
- # ENV['GRDIR'] (Linux, Mac, Windows)
41
- elsif ENV['GRDIR']
42
- begin
43
- recursive_search(gr_lib_name, ENV['GRDIR'])
44
- rescue StandardError => e
45
- warn "\nWhile searching for #{gr_lib_name} in the directory specified " \
46
- "in the GRDIR environment variable, ENV['GRDIR']=#{ENV['GRDIR']}, " \
47
- "the following error occurred : #{e.message}"
48
- pkg_config_search(gr_lib_name, pkg_name)
49
- end
50
- else
51
- pkg_config_search(gr_lib_name, pkg_name)
52
- end
53
- end
54
-
55
- def recursive_search(name, base_dir)
56
- Dir.chdir(base_dir) do
57
- path = Dir["**/#{name}"].first # FIXME
58
- if path
59
- File.expand_path(path)
60
- else
61
- raise "#{name} not found in #{base_dir}"
62
- end
63
- end
64
- end
65
-
66
- def pkg_config_search(gr_lib_name, pkg_name)
67
- PKGConfig.variable(pkg_name, 'sopath')
68
- rescue PackageConfig::NotFoundError => e
69
- raise "#{e.message} Cannot find #{gr_lib_name}. " \
70
- "Please Make sure that GR is installed and the environment ” \
71
- ”variable GRDIR is set correctly."
72
- end
73
- end
74
- end