ruby.py 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -6
- data/lib/ruby.py.rb +20 -9
- data/ruby.py.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce46083cff4ac53b8419633a9f0c7fb0a523037db836a4775e7745ca579ece8
|
4
|
+
data.tar.gz: 20fcffbfc2b6506733b5941e6b95f0717f9554e9eea7604713d79a47573d89b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98d4cae7fe3344d147f9451c96469e1778348e70a1069d3ea1f2f063f21789e3715b4abb3b911f8e113b630dc838666d1fbf8797aa3e57b09c17e0e1973bf598
|
7
|
+
data.tar.gz: b05a1d7e0435d12b2906a2ea853ea319d886efd28e7a19f72a3f10604c8b7f93d8378267ca0ab4a2e2915b6c093ec732d36d8277b1ed1e49e4689b486c09a3b0
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Ruby.py
|
2
2
|
|
3
|
-
Ruby wrapper for Python modules
|
3
|
+
Ruby wrapper for Python modules (based on the (PyCall
|
4
|
+
gem)[https://rubygems.org/gems/pycall]).
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -59,16 +60,35 @@ mul = tf.multiply(a, b)
|
|
59
60
|
result = sess.run(add, feed_dict: { a => 2, b => 3 })
|
60
61
|
```
|
61
62
|
|
63
|
+
## Support
|
64
|
+
|
65
|
+
Open an issue via [GitLab](https://gitlab.com/fjc/ruby.py) or email
|
66
|
+
[ruby.py@fjc-group.com](mailto:ruby.py@fjc-group.com).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
[gitlab.com:fjc/ruby.py](https://gitlab.com/fjc/ruby.py)
|
71
|
+
|
62
72
|
## Development
|
63
73
|
|
64
|
-
After checking out the repo, run `bin/setup` to install
|
74
|
+
After checking out the repo, run `bin/setup` to install
|
75
|
+
dependencies. Then, run `rake spec` to run the tests. You can also run
|
76
|
+
`bin/console` for an interactive prompt that will allow you to experiment.
|
65
77
|
|
66
|
-
To
|
78
|
+
To test with an arbitrary version of pycall set the environment variable
|
79
|
+
`RUBYPY_PYCALL` to specify the version and re-bundle. E.g.
|
67
80
|
|
68
|
-
|
81
|
+
$ export RUBYPY_PYCALL="1.1.0.rc1"
|
82
|
+
$ bundle install
|
83
|
+
$ bundle exec rake spec
|
69
84
|
|
70
|
-
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake
|
86
|
+
install`. To release a new version, update the version number in
|
87
|
+
`ruby.py.gemspec`, and then run `bundle exec rake release`, which will
|
88
|
+
create a git tag for the version, push git commits and tags, and push the
|
89
|
+
`.gem` file to [rubygems.org](https://rubygems.org).
|
71
90
|
|
72
91
|
## License
|
73
92
|
|
74
|
-
The gem is available as open source under the terms of the [MIT
|
93
|
+
The gem is available as open source under the terms of the [MIT
|
94
|
+
License](https://opensource.org/licenses/MIT).
|
data/lib/ruby.py.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
1
|
+
# rubocop:disable Performance/TimesMap
|
1
2
|
# rubocop:disable Metrics/AbcSize
|
2
|
-
# rubocop:disable Security/Eval
|
3
|
-
# rubocop:disable Style/EvalWithLocation
|
4
3
|
|
5
4
|
require 'pycall/import'
|
6
5
|
|
7
|
-
# Ruby wrapper for Python modules.
|
6
|
+
# Ruby wrapper for Python modules (based on the PyCall gem).
|
8
7
|
module RubyPy
|
8
|
+
# Import a _python.module_ as a _RubyPy::Python::Module_ using the
|
9
|
+
# _PyCall_ gem. Methods called on the Ruby module will be sent to
|
10
|
+
# the Python module.
|
9
11
|
def self.import(pym)
|
12
|
+
# very simple filter to mitigate the risk of code injection attacks
|
10
13
|
raise ArgumentError unless pym =~ /\A[-_.A-Za-z0-9]+\Z/
|
11
14
|
|
12
|
-
|
13
|
-
mod
|
15
|
+
# convert a python.module.name to a [RubyPy::]Python::Module::Name
|
16
|
+
mod = pym.split('.').map do |segment|
|
17
|
+
segment.split('_').map(&:capitalize).join
|
18
|
+
end
|
14
19
|
|
15
|
-
|
20
|
+
# create the [RubyPy::]Python::Module::Name hierarchy
|
21
|
+
create_module_hierarchy = \
|
22
|
+
mod.size.times.map { |i| "module #{mod[0..i].join('::')};end" }.join(';')
|
23
|
+
instance_eval(create_module_hierarchy, __FILE__, __LINE__)
|
24
|
+
|
25
|
+
# import the python module into an anonymous module and delegate to it
|
26
|
+
instance_eval("#{<<-"BEGIN"}\n#{<<-"NIGEB"}", __FILE__, __LINE__)
|
27
|
+
BEGIN
|
16
28
|
module #{mod.join('::')}
|
17
29
|
unless @pycall
|
18
30
|
@pycall = Module.new do
|
@@ -34,10 +46,9 @@ module RubyPy
|
|
34
46
|
|
35
47
|
self
|
36
48
|
end
|
37
|
-
|
49
|
+
NIGEB
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
|
-
# rubocop:enable Style/EvalWithLocation
|
42
|
-
# rubocop:enable Security/Eval
|
43
53
|
# rubocop:enable Metrics/AbcSize
|
54
|
+
# rubocop:enable Performance/TimesMap
|
data/ruby.py.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'ruby.py'
|
6
|
-
spec.version = '0.2.
|
6
|
+
spec.version = '0.2.4'
|
7
7
|
spec.authors = ['Frank J. Cameron']
|
8
8
|
spec.email = ['fjc@fastmail.net']
|
9
9
|
|
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
30
|
spec.add_development_dependency 'rubocop', '~> 0.57.2'
|
31
31
|
|
32
|
-
spec.add_dependency 'pycall', '~> 1.0'
|
32
|
+
spec.add_dependency 'pycall', (ENV['RUBYPY_PYCALL'] || '~> 1.0')
|
33
33
|
end
|
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.4
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: pycall
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.1.0.rc1
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.1.0.rc1
|
97
97
|
description: ''
|
98
98
|
email:
|
99
99
|
- fjc@fastmail.net
|