ruby.py 0.2.5 → 0.2.6
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 +4 -4
- data/README.md +22 -2
- data/lib/ruby.py.rb +8 -6
- data/ruby.py.gemspec +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: 76ccc75fe7cc12b89aa59f57750daf86eb92f3bca794351b906d8b28f7d10fb6
|
4
|
+
data.tar.gz: 6deeac2d7068e02c931a448cf417c909a3e84a5d0ca6df6f72c146e29c5db691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ad6a2b349ecf451ffb7f06cbc618b307052a19e34f813e279df107667c0968038e18e019e38cb9759808fbdbe5fd14786b6555540661a2a47b707bf5d27ab0
|
7
|
+
data.tar.gz: 471eb06ccf092e52ad0cecd6199679c43290b79702c5377efe33b74f350b7d23ccd8b299cead8706c9eb4ad59f46f80b01af507e4f358adc6bbed712b9e13291
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Ruby.py
|
2
2
|
|
3
|
-
Ruby wrapper for Python modules using the
|
4
|
-
gem)[https://rubygems.org/gems/pycall].
|
3
|
+
Ruby wrapper for Python modules using the
|
4
|
+
(PyCall gem)[https://rubygems.org/gems/pycall].
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -21,6 +21,8 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
### Consume a Python API in Ruby
|
25
|
+
|
24
26
|
```ruby
|
25
27
|
require 'ruby.py'
|
26
28
|
|
@@ -60,6 +62,24 @@ mul = tf.multiply(a, b)
|
|
60
62
|
result = sess.run(add, feed_dict: { a => 2, b => 3 })
|
61
63
|
```
|
62
64
|
|
65
|
+
### Enhance a Python API in Ruby
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'ruby.py'
|
69
|
+
|
70
|
+
# Top-level module to expose Python 'tensorflow' API to Ruby.
|
71
|
+
TensorFlow = RubyPy.import('tensorflow')
|
72
|
+
|
73
|
+
# Enhance the module's Ruby API.
|
74
|
+
module TensorFlow
|
75
|
+
# Pass a tf.Session() to a block and auto-close it.
|
76
|
+
def self.session(*args, &block)
|
77
|
+
return(s = self.Session.new(*args)) unless block
|
78
|
+
begin; yield(s); ensure; s.close; end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
63
83
|
## Support
|
64
84
|
|
65
85
|
Open an issue via [GitLab](https://gitlab.com/fjc/ruby.py) or email
|
data/lib/ruby.py.rb
CHANGED
@@ -26,21 +26,23 @@ module RubyPy
|
|
26
26
|
instance_eval("#{<<-"DEFMOD"}\n#{<<-"ENDMOD"}", __FILE__, __LINE__)
|
27
27
|
DEFMOD
|
28
28
|
module #{mod.join('::')}
|
29
|
-
unless @
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
unless @_pycall
|
30
|
+
def self._pycall
|
31
|
+
@_pycall ||= Module.new do
|
32
|
+
extend ::PyCall::Import
|
33
|
+
pyimport #{pym.inspect}, as: 'import'
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def self.method_missing(method_name, *arguments, &block)
|
36
38
|
if respond_to_missing?(method_name)
|
37
|
-
|
39
|
+
_pycall.import.send(method_name, *arguments, &block)
|
38
40
|
else
|
39
41
|
super
|
40
42
|
end
|
41
43
|
end
|
42
44
|
def self.respond_to_missing?(method_name, include_private = false)
|
43
|
-
|
45
|
+
_pycall.import.respond_to?(method_name, include_private)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
data/ruby.py.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby.py
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank J. Cameron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|