pycall 1.0.1-x64-mingw32 → 1.0.2-x64-mingw32

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: 8e05704810bf423cd918b04254332b5b369cb0ba
4
- data.tar.gz: ad4f82816aa125aba4c980ee7830848bd350ed7d
3
+ metadata.gz: '089189762ae2cbdb8d8f7d5d472f3f5e8b8b7620'
4
+ data.tar.gz: 3340df4342ea9a2938699d862bc04f17c7cd6259
5
5
  SHA512:
6
- metadata.gz: a770626b71328e7395a8cd87090831bbe80396322e63501637a656ce111869581dee3ef006c24fc33d0cd695f4a09e9d675c3017bcddf01b6551043d3d2446cb
7
- data.tar.gz: d9a7e3aa1fa1626cec08ee829ca79bb1f520a4b1230f4e31271bb5ff6a761d9e492286d02e9bea506ed864a8e16cf0bcdfc6a8f013d597e7097b3dfd3b317c45
6
+ metadata.gz: 33a6396abff3be597d56630663635100b034a17ed28326b6d8cd136f9d9bb9edfe0e9dec3ecf67af6dd7b5079e035e94ca5cd5eaff7678e1fe662f01da9ab5be
7
+ data.tar.gz: dd4a2ca053b6b992bc25665f4b90d728e98869c9543932e8874289ecf7f739ddec58aa9649760ebfdfedfdb58aaf59f5558e667306d60d2aa4f202a50daab4cd
@@ -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: x64-mingw32
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