pycall 0.1.0.alpha.20170426 → 0.1.0.alpha.20170502

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: 3bcfecf2fed43a5e8e5c52f5d96cfc899f180a6e
4
- data.tar.gz: 66b6648e36b7eef5e8961413144a837e85bb47cf
3
+ metadata.gz: 11a4cc6aa314d0d52e7fdea71f2fd974f10a594a
4
+ data.tar.gz: aeb28848ce5495214890214ff3da2dc94b5124de
5
5
  SHA512:
6
- metadata.gz: '0117417889164ebeb9756fd40e7393db68a1c83204f0fdfd57c9be0cabf44cde6d9b474eba22aa08aa69c97a995c78d665a94388f87b32f78761cf4b3ee1e3f1'
7
- data.tar.gz: 60d13590b7a44567a8ce47d20e137ac90518a6279777e1398c7ccf4bc6741e63d7f26b3b01672aff82b3eba8299f516017325a55825c0d1672d120b1f1873047
6
+ metadata.gz: 8e6f9da5c811d8e91e48d85a20904cd0f612df36715fa8d8366e02a82727b45741e8018e1be20b0982cd5f33d0bffaa259a1120b041a8f9c8df6320c4b9e7f8c
7
+ data.tar.gz: 11d741f4600b398bc4fa7e3fe61d02d9bb73949e9d43178fe7d9966e292f6a66f6e9667354b20587a6a64d427bc10971efb5c74e0dec44c6a59aaa4724fea590
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
+ Dir[File.expand_path('../tasks/**/*.rake', __FILE__)].each {|f| load f }
5
+
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  task :default => :spec
data/docker/Dockerfile ADDED
@@ -0,0 +1,191 @@
1
+ FROM buildpack-deps:xenial
2
+ MAINTAINER Kenta Murata mrkn
3
+
4
+ ###############################################################
5
+ # Ruby based on docker-library/ruby
6
+ ###############################################################
7
+
8
+ # skip installing gem documentation
9
+ RUN mkdir -p /usr/local/etc \
10
+ && { \
11
+ echo 'install: --no-document'; \
12
+ echo 'update: --no-document'; \
13
+ } >> /usr/local/etc/gemrc
14
+
15
+ ENV RUBY_MAJOR 2.4
16
+ ENV RUBY_VERSION 2.4.0
17
+ ENV RUBY_DOWNLOAD_SHA256 3a87fef45cba48b9322236be60c455c13fd4220184ce7287600361319bb63690
18
+ ENV RUBYGEMS_VERSION 2.6.10
19
+
20
+ # some of ruby's build scripts are written in ruby
21
+ # we purge system ruby later to make sure our final image uses what we just built
22
+ RUN set -ex \
23
+ \
24
+ && buildDeps=' \
25
+ bison \
26
+ libgdbm-dev \
27
+ ruby \
28
+ ' \
29
+ && apt-get update \
30
+ && apt-get install -y --no-install-recommends $buildDeps \
31
+ && rm -rf /var/lib/apt/lists/* \
32
+ \
33
+ && wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz" \
34
+ && echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum -c - \
35
+ \
36
+ && mkdir -p /usr/src/ruby \
37
+ && tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1 \
38
+ && rm ruby.tar.xz \
39
+ \
40
+ && cd /usr/src/ruby \
41
+ \
42
+ # hack in "ENABLE_PATH_CHECK" disabling to suppress:
43
+ # warning: Insecure world writable dir
44
+ && { \
45
+ echo '#define ENABLE_PATH_CHECK 0'; \
46
+ echo; \
47
+ cat file.c; \
48
+ } > file.c.new \
49
+ && mv file.c.new file.c \
50
+ \
51
+ && autoconf \
52
+ && ./configure --disable-install-doc --enable-shared \
53
+ && make -j"$(nproc)" \
54
+ && make install \
55
+ \
56
+ && apt-get purge -y --auto-remove $buildDeps \
57
+ && cd / \
58
+ && rm -r /usr/src/ruby \
59
+ \
60
+ && gem update --system "$RUBYGEMS_VERSION"
61
+
62
+ ENV BUNDLER_VERSION 1.14.5
63
+
64
+ RUN gem install bundler --version "$BUNDLER_VERSION"
65
+
66
+ # install things globally, for great justice
67
+ # and don't create ".bundle" in all our apps
68
+ ENV GEM_HOME /usr/local/bundle
69
+ ENV BUNDLE_PATH="$GEM_HOME" \
70
+ BUNDLE_BIN="$GEM_HOME/bin" \
71
+ BUNDLE_SILENCE_ROOT_WARNING=1 \
72
+ BUNDLE_APP_CONFIG="$GEM_HOME"
73
+ ENV PATH $BUNDLE_BIN:$PATH
74
+ RUN mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
75
+ && chmod 777 "$GEM_HOME" "$BUNDLE_BIN"
76
+
77
+
78
+ ###############################################################
79
+ # Python based on docker-library/python
80
+ ###############################################################
81
+
82
+ # ensure local python is preferred over distribution python
83
+ ENV PATH /usr/local/bin:$PATH
84
+
85
+ # http://bugs.python.org/issue19846
86
+ # > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
87
+ ENV LANG C.UTF-8
88
+
89
+ # runtime dependencies
90
+ RUN apt-get update && apt-get install -y --no-install-recommends \
91
+ tcl \
92
+ tk \
93
+ && rm -rf /var/lib/apt/lists/*
94
+
95
+ ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
96
+ ENV PYTHON_VERSION 3.6.0
97
+
98
+ # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
99
+ ENV PYTHON_PIP_VERSION 9.0.1
100
+
101
+ RUN set -ex \
102
+ && buildDeps=' \
103
+ tcl-dev \
104
+ tk-dev \
105
+ ' \
106
+ && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
107
+ \
108
+ && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
109
+ && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
110
+ && export GNUPGHOME="$(mktemp -d)" \
111
+ && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
112
+ && gpg --batch --verify python.tar.xz.asc python.tar.xz \
113
+ && rm -r "$GNUPGHOME" python.tar.xz.asc \
114
+ && mkdir -p /usr/src/python \
115
+ && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
116
+ && rm python.tar.xz \
117
+ \
118
+ && cd /usr/src/python \
119
+ && ./configure \
120
+ --enable-loadable-sqlite-extensions \
121
+ --enable-shared \
122
+ && make -j$(nproc) \
123
+ && make install \
124
+ && ldconfig \
125
+ \
126
+ # explicit path to "pip3" to ensure distribution-provided "pip3" cannot interfere
127
+ && if [ ! -e /usr/local/bin/pip3 ]; then : \
128
+ && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
129
+ && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
130
+ && rm /tmp/get-pip.py \
131
+ ; fi \
132
+ # we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
133
+ # ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
134
+ # https://github.com/docker-library/python/pull/143#issuecomment-241032683
135
+ && pip3 install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \
136
+ # then we use "pip list" to ensure we don't have more than one pip version installed
137
+ # https://github.com/docker-library/python/pull/100
138
+ && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
139
+ \
140
+ && find /usr/local -depth \
141
+ \( \
142
+ \( -type d -a -name test -o -name tests \) \
143
+ -o \
144
+ \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
145
+ \) -exec rm -rf '{}' + \
146
+ && apt-get purge -y --auto-remove $buildDeps \
147
+ && rm -rf /usr/src/python ~/.cache
148
+
149
+ # make some useful symlinks that are expected to exist
150
+ RUN cd /usr/local/bin \
151
+ && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
152
+ && ln -s idle3 idle \
153
+ && ln -s pydoc3 pydoc \
154
+ && ln -s python3 python \
155
+ && ln -s python3-config python-config
156
+
157
+ ###############################################################
158
+ # pycall
159
+ ###############################################################
160
+
161
+ RUN apt-get update \
162
+ && apt-get install -y --no-install-recommends libczmq-dev
163
+
164
+ RUN pip3 install jupyter
165
+ RUN pip3 install numpy
166
+ RUN pip3 install scipy
167
+ RUN pip3 install pandas
168
+ RUN pip3 install matplotlib
169
+ RUN pip3 install seaborn
170
+ RUN pip3 install scikit-learn
171
+ RUN pip3 install gensim
172
+ RUN pip3 install nltk
173
+ RUN pip3 install statsmodels
174
+ RUN pip3 install xray
175
+
176
+ RUN mkdir -p /app /notebooks/examples /notebooks/local
177
+ WORKDIR /app
178
+ ADD docker/Gemfile /app
179
+ ADD docker/start.sh /app
180
+
181
+ RUN bundle install
182
+ RUN bundle exec iruby register
183
+
184
+ # Deploy matplotlib's examples
185
+ RUN mkdir -p /tmp \
186
+ && curl -fsSL https://github.com/mrkn/matplotlib.rb/archive/master.tar.gz | tar -xzf - -C /tmp \
187
+ && mv /tmp/matplotlib.rb-master/examples /notebooks/examples/matplotlib \
188
+ && rm -rf /tmp/matplotlib.rb-master
189
+
190
+ CMD sh /app/start.sh
191
+ EXPOSE 8888
data/docker/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # IRuby dependencies
4
+ gem 'pry'
5
+ gem 'pry-doc'
6
+ gem 'awesome_print'
7
+ gem 'cztop', '< 0.3.0'
8
+ gem 'iruby', github: 'sciruby/iruby'
9
+
10
+ # PyCall related gems
11
+ gem 'pycall', '>= 0.1.0.alpha.20170426'
12
+ gem 'matplotlib', '>= 0.1.0.alpha.20170426'
data/docker/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # How to use and build docker image
2
+
3
+ ## Use
4
+
5
+ Execute the following command.
6
+
7
+ ```
8
+ rake docker:run [port=<PORT>] [attach_local=<DIRECTORY>]
9
+ ```
10
+
11
+ The `port` option is for specifying the port number connecting to iruby notebook.
12
+
13
+ You can access to a local directory from jupyter notebook in the container by attaching the local directory to `/notebooks/local` in the container using `attach_local` option. The default value is the current directory, that should be pycall directory.
14
+
15
+ ## Build
16
+
17
+ You can build your own docker image if you modify pycall.
18
+ Execute the following command to build it.
19
+
20
+ ```
21
+ rake docker:build
22
+ ```
data/lib/pycall/dict.rb CHANGED
@@ -21,6 +21,7 @@ module PyCall
21
21
 
22
22
  def [](key)
23
23
  key = key.to_s if key.is_a? Symbol
24
+ key = key.__pyobj__ if key.respond_to?(:__pyobj__)
24
25
  value = if key.is_a? String
25
26
  LibPython.PyDict_GetItemString(__pyobj__, key).to_ruby
26
27
  else
@@ -37,6 +38,7 @@ module PyCall
37
38
 
38
39
  def []=(key, value)
39
40
  key = key.to_s if key.is_a? Symbol
41
+ key = key.__pyobj__ if key.respond_to?(:__pyobj__)
40
42
  value = Conversions.from_ruby(value)
41
43
  value = value.__pyobj__ unless value.kind_of? LibPython::PyObjectStruct
42
44
  if key.is_a? String
@@ -49,6 +51,7 @@ module PyCall
49
51
 
50
52
  def delete(key)
51
53
  key = key.to_s if key.is_a? Symbol
54
+ key = key.__pyobj__ if key.respond_to?(:__pyobj__)
52
55
  if key.is_a? String
53
56
  value = LibPython.PyDict_GetItemString(__pyobj__, key).to_ruby
54
57
  LibPython.PyDict_DelItemString(__pyobj__, key)
@@ -327,7 +327,7 @@ module PyCall
327
327
  attach_function :PyDict_SetItem, [PyObjectStruct.by_ref, PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
328
328
  attach_function :PyDict_SetItemString, [PyObjectStruct.by_ref, :string, PyObjectStruct.by_ref], :int
329
329
  attach_function :PyDict_DelItem, [PyObjectStruct.by_ref, PyObjectStruct.by_ref], :int
330
- attach_function :PyDict_DelItem, [PyObjectStruct.by_ref, :string], :int
330
+ attach_function :PyDict_DelItemString, [PyObjectStruct.by_ref, :string], :int
331
331
  attach_function :PyDict_Size, [PyObjectStruct.by_ref], :ssize_t
332
332
  attach_function :PyDict_Keys, [PyObjectStruct.by_ref], PyObjectStruct.by_ref
333
333
  attach_function :PyDict_Values, [PyObjectStruct.by_ref], PyObjectStruct.by_ref
@@ -1,3 +1,3 @@
1
1
  module PyCall
2
- VERSION = "0.1.0.alpha.20170426"
2
+ VERSION = "0.1.0.alpha.20170502"
3
3
  end
data/pycall.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "bundler", "~> 1.13"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "launchy"
36
37
  end
data/tasks/docker.rake ADDED
@@ -0,0 +1,20 @@
1
+ namespace :docker do
2
+ task :build do
3
+ Dir.chdir File.expand_path('../..', __FILE__) do
4
+ system "docker build -f docker/Dockerfile -t rubydata/pycall ."
5
+ end
6
+ end
7
+
8
+ task :run do
9
+ require 'securerandom'
10
+ require 'launchy'
11
+ token = SecureRandom.hex(48)
12
+ port = ENV['port'] || '8888'
13
+ attach_local = File.expand_path(ENV['attach_local'] || Dir.pwd)
14
+ Thread.start do
15
+ sleep 3
16
+ Launchy.open("http://localhost:#{port}/?token=#{token}")
17
+ end
18
+ system "docker run -it -e 'JUPYTER_TOKEN=#{token}' -v #{attach_local}:/notebooks/local -p #{port}:8888 --rm --name pycall rubydata/pycall"
19
+ end
20
+ 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: 0.1.0.alpha.20170426
4
+ version: 0.1.0.alpha.20170502
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-04-26 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: launchy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: pycall
70
84
  email:
71
85
  - mrkn@mrkn.jp
@@ -86,6 +100,9 @@ files:
86
100
  - bin/rspec
87
101
  - bin/setup
88
102
  - config/Guardfile
103
+ - docker/Dockerfile
104
+ - docker/Gemfile
105
+ - docker/README.md
89
106
  - examples/classifier_comparison.rb
90
107
  - examples/hist.rb
91
108
  - examples/plot_forest_importances_faces.rb
@@ -111,6 +128,7 @@ files:
111
128
  - lib/pycall/utils.rb
112
129
  - lib/pycall/version.rb
113
130
  - pycall.gemspec
131
+ - tasks/docker.rake
114
132
  homepage: https://github.com/mrkn/pycall
115
133
  licenses:
116
134
  - MIT