pycall 1.0.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +41 -0
  5. data/CHANGES.md +39 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +91 -0
  9. data/Rakefile +29 -0
  10. data/appveyor.yml +138 -0
  11. data/bin/console +10 -0
  12. data/bin/guard +17 -0
  13. data/bin/rspec +17 -0
  14. data/bin/runner +6 -0
  15. data/bin/setup +8 -0
  16. data/config/Guardfile +30 -0
  17. data/docker/Dockerfile +191 -0
  18. data/docker/Gemfile +12 -0
  19. data/docker/README.md +22 -0
  20. data/examples/classifier_comparison.rb +135 -0
  21. data/examples/datascience_rb_20170519.ipynb +4836 -0
  22. data/examples/hist.rb +32 -0
  23. data/examples/notebooks/classifier_comparison.ipynb +226 -0
  24. data/examples/notebooks/forest_importances.ipynb +238 -0
  25. data/examples/notebooks/iruby_integration.ipynb +183 -0
  26. data/examples/notebooks/lorenz_attractor.ipynb +214 -0
  27. data/examples/notebooks/polar_axes.ipynb +209 -0
  28. data/examples/notebooks/sum_benchmarking.ipynb +374 -0
  29. data/examples/notebooks/xkcd_style.ipynb +149 -0
  30. data/examples/plot_forest_importances_faces.rb +46 -0
  31. data/examples/sum_benchmarking.rb +49 -0
  32. data/ext/pycall/extconf.rb +3 -0
  33. data/ext/pycall/gc.c +74 -0
  34. data/ext/pycall/libpython.c +217 -0
  35. data/ext/pycall/pycall.c +2184 -0
  36. data/ext/pycall/pycall_internal.h +700 -0
  37. data/ext/pycall/range.c +69 -0
  38. data/ext/pycall/ruby_wrapper.c +432 -0
  39. data/lib/pycall.rb +91 -0
  40. data/lib/pycall/conversion.rb +173 -0
  41. data/lib/pycall/dict.rb +48 -0
  42. data/lib/pycall/error.rb +10 -0
  43. data/lib/pycall/gc_guard.rb +84 -0
  44. data/lib/pycall/import.rb +120 -0
  45. data/lib/pycall/init.rb +55 -0
  46. data/lib/pycall/iruby_helper.rb +40 -0
  47. data/lib/pycall/libpython.rb +12 -0
  48. data/lib/pycall/libpython/finder.rb +170 -0
  49. data/lib/pycall/libpython/pyobject_struct.rb +30 -0
  50. data/lib/pycall/libpython/pytypeobject_struct.rb +273 -0
  51. data/lib/pycall/list.rb +45 -0
  52. data/lib/pycall/pretty_print.rb +9 -0
  53. data/lib/pycall/pyerror.rb +30 -0
  54. data/lib/pycall/pyobject_wrapper.rb +212 -0
  55. data/lib/pycall/python/PyCall/__init__.py +1 -0
  56. data/lib/pycall/python/PyCall/six.py +23 -0
  57. data/lib/pycall/python/investigator.py +7 -0
  58. data/lib/pycall/pytypeobject_wrapper.rb +90 -0
  59. data/lib/pycall/set.rb +19 -0
  60. data/lib/pycall/slice.rb +8 -0
  61. data/lib/pycall/tuple.rb +46 -0
  62. data/lib/pycall/version.rb +3 -0
  63. data/lib/pycall/wrapper_object_cache.rb +61 -0
  64. data/pycall.gemspec +40 -0
  65. data/tasks/docker.rake +21 -0
  66. data/tasks/pycall.rake +7 -0
  67. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e05704810bf423cd918b04254332b5b369cb0ba
4
+ data.tar.gz: ad4f82816aa125aba4c980ee7830848bd350ed7d
5
+ SHA512:
6
+ metadata.gz: a770626b71328e7395a8cd87090831bbe80396322e63501637a656ce111869581dee3ef006c24fc33d0cd695f4a09e9d675c3017bcddf01b6551043d3d2446cb
7
+ data.tar.gz: d9a7e3aa1fa1626cec08ee829ca79bb1f520a4b1230f4e31271bb5ff6a761d9e492286d02e9bea506ed864a8e16cf0bcdfc6a8f013d597e7097b3dfd3b317c45
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ __pycache__
11
+ *.bundle
12
+ *.so
13
+ *.o
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,41 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - ruby-head
6
+ - 2.4.0
7
+ - 2.3.1
8
+ - 2.2.5
9
+ - 2.1.10
10
+
11
+ env:
12
+ global:
13
+ - PYCALL_DEBUG_FIND_LIBPYTHON=1
14
+ matrix:
15
+ - PYTHON=python
16
+ - PYTHON=python3 LIBPYTHON=wrong_value
17
+ - LIBPYTHON=/opt/python/3.5.3/lib/libpython3.5m.so
18
+
19
+ addons:
20
+ apt:
21
+ packages:
22
+ - python3
23
+ - python3-dev
24
+ - python3-all
25
+ - python3-all-dev
26
+
27
+ before_install:
28
+ - gem update --system
29
+ - gem update bundler
30
+
31
+ before_script:
32
+ - bundle exec rake clobber compile
33
+ - echo === python investigator.py ===
34
+ - python lib/pycall/python/investigator.py
35
+ - python3 lib/pycall/python/investigator.py
36
+ - pip install numpy
37
+ - pip3 install numpy
38
+
39
+ matrix:
40
+ allow_failures:
41
+ - env: PYTHON=python # Ignore failed on python 2.7
data/CHANGES.md ADDED
@@ -0,0 +1,39 @@
1
+ # The change history of PyCall
2
+
3
+ ## 1.0.1
4
+
5
+ * Add PyTypeObject#===.
6
+
7
+ ## 1.0.0
8
+
9
+ * `#[]` and `#[]=` accept a `Range` and an `Enumerable`, which is genated by
10
+ `Range#step`, as a slice.
11
+
12
+ * Rewrite almost all fundamental parts of PyCall as C extension.
13
+
14
+ * PyCall now calls `Py_DecRef` in the finalizer of `PyCall::PyPtr`.
15
+
16
+ * Change the system of object mapping between Python and Ruby, drastically.
17
+ Now PyCall does not have `PyObject` class for wrapper objects.
18
+ Instead, PyCall generally makes `Object` instances and extends them by
19
+ `PyObjectWrapper` module.
20
+ But for Python module objects, PyCall makes anonymous `Module` instances
21
+ that are extended by `PyObjectWrapper` module.
22
+ Moreover for Python type objects, PyCall makes `Class` instances and extends
23
+ them by `PyTypeObjectWrapper` module.
24
+
25
+ * Change `PyCall.eval` to be a wrapper of `__builtins__.eval` in Python.
26
+ This means that `filename:` and `input_type:` parameters are dropped.
27
+ Instead, two new parameters `globals:` and `locals:` are introduced.
28
+ `globals:` is used for specifying a dictionary that is the global
29
+ namespace referred by the evaluated expression.
30
+ `locals:` is used for specifying a mapping object that is the local
31
+ namespace referred by the evaluated expression.
32
+
33
+ * Add `PyCall.exec` for the replacement of the former `PyCall.eval`
34
+ with `input_type: :file`.
35
+ It has `globals:` and `locals:` parameters for the same meaning as
36
+ the new `PyCall.eval` described above.
37
+
38
+ * Drop `PyCall.wrap_ruby_callable` and `PyCall.wrap_ruby_object` always
39
+ craetes a callable Python object taht has an ID of the given Ruby object.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pycall.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kenta Murata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # PyCall: Calling Python functions from the Ruby language
2
+
3
+ [![Build Status](https://travis-ci.org/mrkn/pycall.svg?branch=master)](https://travis-ci.org/mrkn/pycall)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/071is0f4iu0vy8lp/branch/master?svg=true)](https://ci.appveyor.com/project/mrkn/pycall/branch/master)
5
+
6
+ This library provides the features to directly call and partially interoperate
7
+ with Python from the Ruby language. You can import arbitrary Python modules
8
+ into Ruby modules, call Python functions with automatic type conversion from
9
+ Ruby to Python.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'pycall'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install --pre pycall
26
+
27
+ ## Usage
28
+
29
+ Here is a simple example to call Python's `math.sin` function and compare it to
30
+ the `Math.sin` in Ruby:
31
+
32
+ require 'pycall/import'
33
+ include PyCall::Import
34
+ pyimport :math
35
+ math.sin(math.pi / 4) - Math.sin(Math::PI / 4) # => 0.0
36
+
37
+ Type conversions from Ruby to Python are automatically performed for numeric,
38
+ boolean, string, arrays, and hashes.
39
+
40
+ ## PyCall object system
41
+
42
+ PyCall wraps pointers of Python objects in `PyCall::PyPtr` objects.
43
+ `PyCall::PyPtr` class has two subclasses, `PyCall::PyTypePtr` and
44
+ `PyCall::PyRubyPtr`. `PyCall::PyTypePtr` is specialized for type (and classobj
45
+ in 2.7) objects, and `PyCall::PyRubyPtr` is for the objects that wraps pointers
46
+ of Ruby objects.
47
+
48
+ These `PyCall::PyPtr` objects are used mainly in PyCall infrastructure.
49
+ Instead, we usually treats the instances of `Object`, `Class`, `Module`, or
50
+ other classes that are extended by `PyCall::PyObjectWrapper` module.
51
+
52
+ `PyCall::PyObjectWrapper` is a mix-in module for objects that wraps Python
53
+ objects. A wrapper object should have `PyCall::PyPtr` object in its instance
54
+ variable `@__pyptr__`. `PyCall::PyObjectWrapper` assumes the existance of
55
+ `@__pyptr__`, and provides general translation mechanisms between Ruby object
56
+ system and Python object system. For example, `PyCall::PyObjectWrapper`
57
+ translates Ruby's coerce system into Python's swapped operation protocol.
58
+
59
+ ### Specifying the Python version
60
+
61
+ If you want to use a specific version of Python instead of the default,
62
+ you can change the Python version by setting the `PYTHON` environment variable
63
+ to the path of the `python` executable.
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies.
68
+ Then, run `rake spec` to run the tests. You can also run `bin/console`
69
+ for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`.
72
+ To release a new version, update the version number in `version.rb`,
73
+ and then run `bundle exec rake release`, which will create a git tag for the
74
+ version, push git commits and tags, and push the `.gem` file to
75
+ [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at
80
+ https://github.com/mrkn/pycall.
81
+
82
+
83
+ ## Acknowledgement
84
+
85
+ [PyCall.jl](https://github.com/JuliaPy/PyCall.jl) is referred too many times
86
+ to implement this library.
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the
91
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake"
5
+ require "rake/extensiontask"
6
+ require "rspec/core/rake_task"
7
+
8
+ Dir[File.expand_path('../tasks/**/*.rake', __FILE__)].each {|f| load f }
9
+
10
+ gem_spec = eval(File.read('pycall.gemspec'))
11
+ Rake::ExtensionTask.new('pycall', gem_spec) do |ext|
12
+ ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
13
+ ext.cross_compile = true
14
+ ext.cross_platform = %w[x86-mingw32 x64-mingw32]
15
+ ext.cross_compiling do |s|
16
+ s.files.concat %w[lib/2.2/pycall.so lib/2.3/pycall.so lib/2.4/pycall.so]
17
+ end
18
+ end
19
+
20
+ desc "Compile binaries for mingw platform using rake-compiler-dock"
21
+ task 'build:mingw' do
22
+ require 'rake_compiler_dock'
23
+ RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.1.6:2.2.2:2.3.0:2.4.0"
24
+ end
25
+
26
+ RSpec::Core::RakeTask.new(:spec)
27
+
28
+ task :default => :spec
29
+ task spec: :compile
data/appveyor.yml ADDED
@@ -0,0 +1,138 @@
1
+ ---
2
+ environment:
3
+ matrix:
4
+ # Ruby 2.1 (32bit)
5
+ - ruby_version: "21"
6
+ PYTHONDIR: "C:\\Python27"
7
+ PYTHON: "C:\\Python27\\python.exe"
8
+
9
+ - ruby_version: "21"
10
+ PYTHONDIR: "C:\\Python34"
11
+ PYTHON: "C:\\Python34\\python.exe"
12
+
13
+ - ruby_version: "21"
14
+ PYTHONDIR: "C:\\Python35"
15
+ PYTHON: "C:\\Python35\\python.exe"
16
+
17
+ - ruby_version: "21"
18
+ PYTHONDIR: "C:\\Python36"
19
+ PYTHON: "C:\\Python36\\python.exe"
20
+
21
+ # Ruby 2.1 (64bit)
22
+ - ruby_version: "21-x64"
23
+ PYTHONDIR: "C:\\Python27-x64"
24
+ PYTHON: "C:\\Python27-x64\\python.exe"
25
+
26
+ - ruby_version: "21-x64"
27
+ PYTHONDIR: "C:\\Python34-x64"
28
+ PYTHON: "C:\\Python34-x64\\python.exe"
29
+
30
+ - ruby_version: "21-x64"
31
+ PYTHONDIR: "C:\\Python35-x64"
32
+ PYTHON: "C:\\Python35-x64\\python.exe"
33
+
34
+ - ruby_version: "21-x64"
35
+ PYTHONDIR: "C:\\Python36-x64"
36
+ PYTHON: "C:\\Python36-x64\\python.exe"
37
+
38
+ # Ruby 2.2 (32bit)
39
+ - ruby_version: "22"
40
+ PYTHONDIR: "C:\\Python27"
41
+ PYTHON: "C:\\Python27\\python.exe"
42
+
43
+ - ruby_version: "22"
44
+ PYTHONDIR: "C:\\Python34"
45
+ PYTHON: "C:\\Python34\\python.exe"
46
+
47
+ - ruby_version: "22"
48
+ PYTHONDIR: "C:\\Python35"
49
+ PYTHON: "C:\\Python35\\python.exe"
50
+
51
+ - ruby_version: "22"
52
+ PYTHONDIR: "C:\\Python36"
53
+ PYTHON: "C:\\Python36\\python.exe"
54
+
55
+ # Ruby 2.2 (64bit)
56
+ - ruby_version: "22-x64"
57
+ PYTHONDIR: "C:\\Python27-x64"
58
+ PYTHON: "C:\\Python27-x64\\python.exe"
59
+
60
+ - ruby_version: "22-x64"
61
+ PYTHONDIR: "C:\\Python34-x64"
62
+ PYTHON: "C:\\Python34-x64\\python.exe"
63
+
64
+ - ruby_version: "22-x64"
65
+ PYTHONDIR: "C:\\Python35-x64"
66
+ PYTHON: "C:\\Python35-x64\\python.exe"
67
+
68
+ - ruby_version: "22-x64"
69
+ PYTHONDIR: "C:\\Python36-x64"
70
+ PYTHON: "C:\\Python36-x64\\python.exe"
71
+
72
+ # Ruby 2.3 (32bit)
73
+ - ruby_version: "23"
74
+ PYTHONDIR: "C:\\Python27"
75
+ PYTHON: "C:\\Python27\\python.exe"
76
+
77
+ - ruby_version: "23"
78
+ PYTHONDIR: "C:\\Python34"
79
+ PYTHON: "C:\\Python34\\python.exe"
80
+
81
+ - ruby_version: "23"
82
+ PYTHONDIR: "C:\\Python35"
83
+ PYTHON: "C:\\Python35\\python.exe"
84
+
85
+ - ruby_version: "23"
86
+ PYTHONDIR: "C:\\Python36"
87
+ PYTHON: "C:\\Python36\\python.exe"
88
+
89
+ # Ruby 2.3 (64bit)
90
+ - ruby_version: "23-x64"
91
+ PYTHONDIR: "C:\\Python27-x64"
92
+ PYTHON: "C:\\Python27-x64\\python.exe"
93
+
94
+ - ruby_version: "23-x64"
95
+ PYTHONDIR: "C:\\Python34-x64"
96
+ PYTHON: "C:\\Python34-x64\\python.exe"
97
+
98
+ - ruby_version: "23-x64"
99
+ PYTHONDIR: "C:\\Python35-x64"
100
+ PYTHON: "C:\\Python35-x64\\python.exe"
101
+
102
+ - ruby_version: "23-x64"
103
+ PYTHONDIR: "C:\\Python36-x64"
104
+ PYTHON: "C:\\Python36-x64\\python.exe"
105
+
106
+ branches:
107
+ only:
108
+ - master
109
+ - /release-.*/
110
+
111
+ notifications:
112
+ - provider: Email
113
+ on_build_success: false
114
+ on_build_failure: false
115
+ on_build_status_changed: false
116
+
117
+ deploy: off
118
+ build: off
119
+
120
+ install:
121
+ - "SET PATH=%PYTHONDIR%;%PYTHONDIR%\\Scripts;%PATH%"
122
+ - "SET PATH=C:\\Ruby%ruby_version%\\bin;%PATH%"
123
+ - "bundle install"
124
+ - "pip install numpy"
125
+
126
+ before_test:
127
+ - "bundle exec rake -rdevkit clobber compile"
128
+ - ECHO "=== python investigator.py ==="
129
+ - "python lib\\pycall\\python\\investigator.py"
130
+
131
+ test_script:
132
+ - "SET PYCALL_DEBUG_FIND_LIBPYTHON=1"
133
+ - rake
134
+
135
+ matrix:
136
+ allow_failures:
137
+ - PYTHONDIR: "C:\\Python27"
138
+ - PYTHONDIR: "C:\\Python27-x64"
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pycall"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
data/bin/guard ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'guard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "guard")
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")