pycall 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f55fc9d9a1eb95adf30ecec437c5fe5aa459e4a5
4
- data.tar.gz: c49a974635e8e4fe7c9fc9fc98c6afbc47bc9c5d
3
+ metadata.gz: fc7457af2e316e61b4e58a0a11075914fad55c34
4
+ data.tar.gz: 17adfb758a2822733fdeb79ff2d2bc261d6230af
5
5
  SHA512:
6
- metadata.gz: '09f4f8fa2e3d9353ba31791ba3e689f5b36271ed0170685b82d7580ba3c1afa69f3acd0c39488313c5908143d52cce6a78d2f496b99c0c3975c17a9a2d9f70eb'
7
- data.tar.gz: '028d50abd8e1dc5e39eb7161b3f384ac6f4918107dab120c95341a0011f071a63b9fee0feffc1d11b8acce5bff81c9e9ca040625bc1238e8ab71c6b50ccd307b'
6
+ metadata.gz: 5e309b2814a7ed985e6d3f4c763cbc68f3a354d1beebb1330230825085351a823cae292875bb41984ae308e8d668c83f11e064bb863f9e5e82bb7a3feaad247b
7
+ data.tar.gz: 0ce1b87b5df41852c11995b794921a929f30a710f53641cdec4b2ed626689493c302e66d359eacfcf66addd062605c5538b5eceb1603c05164d999a1dd9b2895
@@ -12,9 +12,9 @@ env:
12
12
  global:
13
13
  - PYCALL_DEBUG_FIND_LIBPYTHON=1
14
14
  matrix:
15
- - PYTHON=python
16
- - PYTHON=python3 LIBPYTHON=wrong_value
17
- - LIBPYTHON=/opt/python/3.5.3/lib/libpython3.5m.so
15
+ - PYTHON=python PYENV_VERSION=system
16
+ - PYTHON=python3 PYENV_VERSION=3.5.3 LIBPYTHON=wrong_value
17
+ - PYENV_VERSION=3.5.3 LIBPYTHON=/opt/python/3.5.3/lib/libpython3.5m.so
18
18
 
19
19
  addons:
20
20
  apt:
@@ -33,8 +33,8 @@ before_script:
33
33
  - echo === python investigator.py ===
34
34
  - python lib/pycall/python/investigator.py
35
35
  - python3 lib/pycall/python/investigator.py
36
- - pip install numpy
37
- - pip3 install numpy
36
+ - travis_retry pip install --user numpy
37
+ - PYENV_VERSION=3.5.3 travis_retry pip3 install --user numpy
38
38
 
39
39
  matrix:
40
40
  allow_failures:
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # The change history of PyCall
2
2
 
3
+ ## 1.0.2
4
+
5
+ * Fix the bug that a large Python string is broken when it converted to Ruby string
6
+ https://github.com/mrkn/pycall.rb/issues/32
7
+
3
8
  ## 1.0.1
4
9
 
5
10
  * Add PyTypeObject#===.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # PyCall: Calling Python functions from the Ruby language
2
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)
3
+ [![Build Status](https://travis-ci.org/mrkn/pycall.rb.svg?branch=1.0)](https://travis-ci.org/mrkn/pycall.rb)
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/naw56ldru71w7qsw/branch/1.0?svg=true)](https://ci.appveyor.com/project/mrkn/pycall-rb/branch/1.0)
5
5
 
6
6
  This library provides the features to directly call and partially interoperate
7
7
  with Python from the Ruby language. You can import arbitrary Python modules
@@ -77,7 +77,7 @@ version, push git commits and tags, and push the `.gem` file to
77
77
  ## Contributing
78
78
 
79
79
  Bug reports and pull requests are welcome on GitHub at
80
- https://github.com/mrkn/pycall.
80
+ https://github.com/mrkn/pycall.rb.
81
81
 
82
82
 
83
83
  ## Acknowledgement
@@ -1,4 +1,5 @@
1
1
  #include "pycall_internal.h"
2
+ #include <ruby/encoding.h>
2
3
 
3
4
  #include <stdarg.h>
4
5
 
@@ -1317,7 +1318,10 @@ pycall_pyobject_to_ruby(PyObject *pyobj)
1317
1318
  if (pyobj->ob_type == Py_API(PyLong_Type))
1318
1319
  return pycall_pylong_to_ruby(pyobj);
1319
1320
 
1320
- if (pyobj->ob_type == Py_API(PyUnicode_Type) || pyobj->ob_type == Py_API(PyString_Type))
1321
+ if (pyobj->ob_type == Py_API(PyUnicode_Type))
1322
+ return pycall_pyunicode_to_ruby(pyobj);
1323
+
1324
+ if (pyobj->ob_type == Py_API(PyString_Type))
1321
1325
  return pycall_pystring_to_ruby(pyobj);
1322
1326
 
1323
1327
  Py_API(Py_IncRef)(pyobj);
@@ -1469,24 +1473,46 @@ pycall_pystring_to_ruby(PyObject *pyobj)
1469
1473
  {
1470
1474
  char *str = NULL;
1471
1475
  Py_ssize_t len = 0;
1472
- int res = -1;
1476
+ int res;
1477
+
1478
+ /* TODO: PyString_Check */
1479
+ if (pyobj->ob_type != Py_API(PyString_Type)) {
1480
+ return Qnil;
1481
+ }
1482
+
1483
+ res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
1484
+ if (res < 0) {
1485
+ return Qnil;
1486
+ }
1487
+
1488
+ return rb_enc_str_new(str, len, rb_enc_from_index(rb_ascii8bit_encindex()));
1489
+ }
1490
+
1491
+ VALUE
1492
+ pycall_pyunicode_to_ruby(PyObject *pyobj)
1493
+ {
1494
+ char *str = NULL;
1495
+ Py_ssize_t len = 0;
1496
+ int res;
1473
1497
 
1474
1498
  /* TODO: PyUnicode_Check */
1475
- if (pyobj->ob_type == Py_API(PyUnicode_Type)) {
1476
- pyobj = Py_API(PyUnicode_AsUTF8String)(pyobj);
1477
- res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
1478
- pycall_Py_DecRef(pyobj);
1499
+ if (pyobj->ob_type != Py_API(PyUnicode_Type)) {
1500
+ return Qnil;
1479
1501
  }
1480
- /* TODO: PyString_Check */
1481
- else if (pyobj->ob_type == Py_API(PyString_Type)) {
1482
- res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
1502
+
1503
+ pyobj = Py_API(PyUnicode_AsUTF8String)(pyobj);
1504
+ if (!pyobj) {
1505
+ Py_API(PyErr_Clear)();
1506
+ return Qnil;
1483
1507
  }
1484
1508
 
1509
+ res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
1485
1510
  if (res < 0) {
1511
+ pycall_Py_DecRef(pyobj);
1486
1512
  return Qnil;
1487
1513
  }
1488
1514
 
1489
- return rb_str_new(str, len);
1515
+ return rb_enc_str_new(str, len, rb_enc_from_index(rb_utf8_encindex()));
1490
1516
  }
1491
1517
 
1492
1518
  static VALUE
@@ -646,6 +646,7 @@ VALUE pycall_pyfloat_to_ruby(PyObject *);
646
646
  VALUE pycall_pyint_to_ruby(PyObject *);
647
647
  VALUE pycall_pylong_to_ruby(PyObject *);
648
648
  VALUE pycall_pystring_to_ruby(PyObject *);
649
+ VALUE pycall_pyunicode_to_ruby(PyObject *);
649
650
  VALUE pycall_pyobject_to_a(PyObject *);
650
651
 
651
652
  VALUE pycall_conv_to_str(VALUE);
@@ -89,3 +89,5 @@ module PyCall
89
89
  end
90
90
  end
91
91
  end
92
+
93
+ require 'pycall/iruby_helper' if defined? IRuby
@@ -5,21 +5,19 @@ module PyCall
5
5
  module IRubyHelper
6
6
  private
7
7
 
8
- def check_pyobject_respond_to_format_method(obj, method_name)
9
- return false unless obj.kind_of? PyObject
10
- return false unless PyCall.hasattr?(obj, method_name)
11
- PyCall.getattr(obj, method_name).kind_of? PyCall::LibPython.PyMethod_Type
8
+ def check_python_object_respond_to_format_method(obj, method_name)
9
+ return false unless obj.kind_of? PyObjectWrapper
10
+ return false unless obj.respond_to? method_name
11
+ true
12
12
  end
13
13
 
14
- def register_pyobject_formatter(format_name, mime, priority_value=0)
14
+ def register_python_object_formatter(format_name, mime, priority_value=0)
15
15
  method_name = :"_repr_#{format_name}_"
16
16
  match do |obj|
17
- check_pyobject_respond_to_format_method(obj, method_name)
17
+ check_python_object_respond_to_format_method(obj, method_name)
18
18
  end
19
19
  priority priority_value
20
- format mime do |obj|
21
- PyCall.getattr(obj, method_name).()
22
- end
20
+ format mime, &method_name
23
21
  end
24
22
  end
25
23
  end
@@ -27,14 +25,14 @@ end
27
25
  ::IRuby::Display::Registry.module_eval do
28
26
  extend PyCall::IRubyHelper
29
27
 
30
- register_pyobject_formatter :html, 'text/html'
31
- register_pyobject_formatter :markdown, 'text/markdown'
32
- register_pyobject_formatter :svg, 'image/svg+xml'
33
- register_pyobject_formatter :png, 'image/png'
34
- register_pyobject_formatter :jpeg, 'image/jpeg'
35
- register_pyobject_formatter :latex, 'text/latex'
36
- register_pyobject_formatter :json, 'application/json'
37
- register_pyobject_formatter :javascript, 'application/javascript'
38
- register_pyobject_formatter :pdf, 'application/pdf'
39
- register_pyobject_formatter :pretty, 'text/plain', -1000
28
+ register_python_object_formatter :html, 'text/html', 1
29
+ register_python_object_formatter :markdown, 'text/markdown', 1
30
+ register_python_object_formatter :svg, 'image/svg+xml', 1
31
+ register_python_object_formatter :png, 'image/png', 1
32
+ register_python_object_formatter :jpeg, 'image/jpeg', 1
33
+ register_python_object_formatter :latex, 'text/latex', 1
34
+ register_python_object_formatter :json, 'application/json', 1
35
+ register_python_object_formatter :javascript, 'application/javascript', 1
36
+ register_python_object_formatter :pdf, 'application/pdf', 1
37
+ register_python_object_formatter :pretty, 'text/plain', -1000
40
38
  end
@@ -1,3 +1,3 @@
1
1
  module PyCall
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pycall
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2017-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  requirements: []
217
217
  rubyforge_project:
218
- rubygems_version: 2.6.12
218
+ rubygems_version: 2.6.13
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: pycall