pycall_thread 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +1 -1
- data/examples/puma/Gemfile +2 -2
- data/examples/puma/Gemfile.lock +3 -3
- data/examples/puma/app.rb +12 -10
- data/lib/pycall_thread/version.rb +1 -1
- data/lib/pycall_thread.rb +3 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de04a7790f025c9450436bf4258476136b2a9e55732fa0adcbfc9671ecdf2840
|
4
|
+
data.tar.gz: db51f2e173305c25bff70add0a291e442c3beb1eee425b5d0aeef1a74a522a5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aa5641cc051976e0cddd405bf98960881ab2ee698c1c35bdbf9fff6cf11bd57ed2cf6515ba140ffce0972e544d4eecce724fcd2a2db83491ec0424319d692c8
|
7
|
+
data.tar.gz: 4156c6dbaafbd74ccca113e44aff8fe4760336c12b0965c05b4e805031d0cb5b133a782c3ccd690e6d70a0b875f25bccb557eb8fbd1c751570073ab42beafadb
|
data/Gemfile
CHANGED
@@ -5,11 +5,11 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in pycall_thread.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
8
|
gem "minitest", "~> 5.0"
|
9
|
+
gem "rake", "~> 13.0"
|
10
10
|
gem "rubocop", "~> 1.21"
|
11
11
|
|
12
12
|
# To use the local pycall, you must also run things with e.g.:
|
13
13
|
# bundle exec ruby -I/Users/seth/src/pycall.rb/ext/pycall
|
14
|
-
#
|
15
|
-
# gem 'pycall', path: '/Users/seth/src/pycall.rb', require: false
|
14
|
+
#
|
15
|
+
# gem 'pycall', path: '/Users/seth/src/pycall.rb', require: false
|
data/Gemfile.lock
CHANGED
data/examples/puma/Gemfile
CHANGED
data/examples/puma/Gemfile.lock
CHANGED
@@ -5,15 +5,15 @@ GEM
|
|
5
5
|
puma (6.4.2)
|
6
6
|
nio4r (~> 2.0)
|
7
7
|
pycall (1.5.2)
|
8
|
-
pycall_thread (0.1.
|
8
|
+
pycall_thread (0.1.2)
|
9
9
|
pycall
|
10
10
|
|
11
11
|
PLATFORMS
|
12
12
|
arm64-darwin-23
|
13
13
|
|
14
14
|
DEPENDENCIES
|
15
|
-
puma
|
16
|
-
pycall_thread
|
15
|
+
puma (~> 6.4.2)
|
16
|
+
pycall_thread (~> 0.1.2)
|
17
17
|
|
18
18
|
BUNDLED WITH
|
19
19
|
2.2.33
|
data/examples/puma/app.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
require
|
1
|
+
# require "pycall_thread"
|
2
|
+
require_relative "../../lib/pycall_thread"
|
2
3
|
|
3
4
|
PyCallThread.init do
|
4
5
|
# Setup our local venv (using pdm, in .venv)
|
5
|
-
ENV[
|
6
|
+
ENV["PYTHON"] = `pdm run which python`.strip
|
6
7
|
site_dir = `pdm run python -c 'import site; print(site.getsitepackages()[0])'`.strip
|
7
8
|
|
8
|
-
require
|
9
|
+
require "pycall"
|
9
10
|
|
10
11
|
# This is to setup our local venv
|
11
|
-
site = PyCall.import_module(
|
12
|
+
site = PyCall.import_module("site")
|
12
13
|
site.addsitedir(site_dir)
|
13
14
|
end
|
14
15
|
|
16
|
+
# Simple Puma App that demonstrates PyCallThread
|
15
17
|
class App
|
16
|
-
def call(
|
18
|
+
def call(_)
|
17
19
|
winequality = PyCallThread.run do
|
18
|
-
pandas = PyCall.import_module(
|
19
|
-
data = pandas.read_csv(
|
20
|
-
data.
|
20
|
+
pandas = PyCall.import_module("pandas")
|
21
|
+
data = pandas.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv", sep: ";")
|
22
|
+
data.to_html
|
21
23
|
end
|
22
24
|
|
23
|
-
[200, {
|
25
|
+
[200, { "Content-Type" => "text/html" }, [winequality]]
|
24
26
|
end
|
25
|
-
end
|
27
|
+
end
|
data/lib/pycall_thread.rb
CHANGED
@@ -12,17 +12,16 @@ module PyCallThread
|
|
12
12
|
|
13
13
|
# Start the thread we will use to run code invoked with PyCallThread.run
|
14
14
|
@py_thread = Thread.new { pycall_thread_loop }
|
15
|
+
@initialized = true
|
15
16
|
|
16
17
|
# If we've been passed a require_pycall_block, use that to require 'pycall'
|
17
18
|
# instead of doing it directly.
|
18
19
|
require_pycall(&require_pycall_block)
|
19
20
|
|
20
21
|
at_exit { stop_pycall_thread }
|
21
|
-
|
22
|
-
@initialized = true
|
23
22
|
end
|
24
23
|
|
25
|
-
def require_pycall(&require_pycall_block)
|
24
|
+
def self.require_pycall(&require_pycall_block)
|
26
25
|
# Only safe to use PyCallThread if PyCall hasn't already been loaded
|
27
26
|
raise "PyCall::LibPython already exists: PyCall can't have been initialized already" if defined?(PyCall::LibPython)
|
28
27
|
|
@@ -53,7 +52,7 @@ module PyCallThread
|
|
53
52
|
run_result(result_queue.pop)
|
54
53
|
end
|
55
54
|
|
56
|
-
def self.run_result
|
55
|
+
def self.run_result(result)
|
57
56
|
if result[:exception]
|
58
57
|
raise result[:exception]
|
59
58
|
elsif python_object?(result[:retval])
|