prremote 0.1.1 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d080a70a00d10af1e419cae964da017bbc6650f85f54f3a18223b81bb204fe7
4
- data.tar.gz: 158c193d72d4d414726f79183f6016017132077f37f0adc2f3238cd843e5672b
3
+ metadata.gz: 46762e433d6de80bfe8f614bbdd3ee25fdbf976a235d69b3aecfe2039bd180f8
4
+ data.tar.gz: bcff6b310ed0056d0298a6511cdefe9ffb77aadbcbf0522a379b62d6e3fcc872
5
5
  SHA512:
6
- metadata.gz: 47d36cf128e0106b732273bad92aeb3af77c97a4e93f167e77d3ea34999578976a75f7babe8e3e910c6cf364422821cca6e5886cc7c7e5fa327a032a7d3bafb9
7
- data.tar.gz: a63fae436f971e92d97386933706f99396dfcfc1ecf105c4ded5215aa1410d3ba3fadeb49805a9735a7285c1b6202da51dad325438d9b13d444756d48d88906e
6
+ metadata.gz: 9ad10419ea1caafefbdbbeaf803dc80d2a39caf148d0ad545f069661acd46010ba45eecba4c1325235b06d0e43d8cc695bc042e03906d48a820fd6c14b658f53
7
+ data.tar.gz: 40ba90421406056fdde9b2849b46a849bd6d642c00784c14f03b62ce12e09724d343b61d89eb97d6d9a035350f1dbd445b253cefe602a5faacc56698df36ff4c
data/README.md CHANGED
@@ -6,15 +6,24 @@
6
6
 
7
7
  Inspired by [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) for MicroPython.
8
8
 
9
+
10
+ [![Gem Version](https://img.shields.io/gem/v/prremote)](https://rubygems.org/gems/prremote)
11
+ [![CI](https://github.com/lumbermill/prremote/actions/workflows/ci.yml/badge.svg)](https://github.com/lumbermill/prremote/actions/workflows/ci.yml)
12
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
13
+ [![Ruby](https://img.shields.io/badge/ruby-3.4%20%7C%204.0-red)](https://github.com/lumbermill/prremote)
14
+
9
15
  ---
10
16
 
11
17
  ## Requirements
12
18
 
13
- - Ruby 3.x or later
19
+ - Ruby 3.4 or later
14
20
  - Raspberry Pi Pico W
15
- - `mrbc` in your PATH (for `run`, `deploy`, and `eval`)
21
+ - `mrbc` (mruby 4.x) for `run`, `deploy`, and `eval`
16
22
  - macOS: `brew install mruby`
17
- - Ubuntu / Raspberry Pi OS: `sudo apt install mruby`
23
+ - Linux: build from source [github.com/mruby/mruby/releases](https://github.com/mruby/mruby/releases)
24
+ (`sudo apt install mruby` installs mruby 3.x which is **not compatible**)
25
+ - If `mrbc` is not on your PATH, set the `MRBC` environment variable:
26
+ `MRBC=/path/to/mrbc prremote run app.rb`
18
27
 
19
28
  ---
20
29
 
@@ -71,6 +80,8 @@ prremote run blink.rb --port /dev/tty.usbmodem101
71
80
 
72
81
  The device responds with `RUNNING`, streams any output, then `DONE`.
73
82
 
83
+ You can find some examples in [test/samples](test/samples/).
84
+
74
85
  ---
75
86
 
76
87
  ### `deploy FILE`
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
data/lib/prremote/cli.rb CHANGED
@@ -20,11 +20,13 @@ module Prremote
20
20
  true
21
21
  end
22
22
 
23
+ remove_command :tree
24
+
23
25
  desc 'install', 'Flash prremote runtime firmware to Pico W or Pico'
24
- option :version, type: :string, desc: "Firmware version to install (default: #{RUNTIME_VERSION})"
26
+ option :version, type: :string, desc: "Firmware version to install (default: #{VERSION})"
25
27
  option :board, type: :string, desc: 'Board type: pico or picow (default: picow)'
26
28
  def install
27
- version = options[:version] || RUNTIME_VERSION
29
+ version = options[:version] || VERSION
28
30
  board = options[:board] || 'picow'
29
31
  unless RuntimeManager::BOARDS.include?(board)
30
32
  raise Thor::Error, "Unknown board '#{board}'. Valid values: #{RuntimeManager::BOARDS.join(', ')}"
@@ -102,14 +104,19 @@ module Prremote
102
104
  desc 'version', 'Show prremote, mrbc, and device firmware version'
103
105
  def version
104
106
  puts "prremote: #{VERSION}"
107
+ puts "runtime: #{fetch_runtime_version}"
105
108
 
106
109
  begin
107
- puts "mrbc: #{Mrbc.version} (#{Mrbc.bin})"
110
+ major = Mrbc.major_version
111
+ puts "mrbc: #{Mrbc.version} (#{Mrbc.bin})"
112
+ unless major && major >= Mrbc::REQUIRED_MAJOR
113
+ puts " ** mrbc is too old (need #{Mrbc::REQUIRED_MAJOR}.x) **"
114
+ puts " Hint: the path can be set via MRBC environment variable."
115
+ end
108
116
  rescue StandardError => e
109
117
  puts "mrbc: (#{e.message})"
110
118
  end
111
119
 
112
- puts "runtime: #{fetch_runtime_version}"
113
120
  end
114
121
 
115
122
  private
@@ -153,7 +160,7 @@ module Prremote
153
160
  next
154
161
  end
155
162
 
156
- return ::Regexp.last_match(1) if buf =~ %r{READY prremote-runtime/([\d.]+)}
163
+ return "#{::Regexp.last_match(1)} (#{port})" if buf =~ %r{READY prremote-runtime/([\d.]+)}
157
164
  return '(not responding)' if Time.now > deadline
158
165
 
159
166
  sleep 0.05
@@ -26,6 +26,7 @@ module Prremote
26
26
  private
27
27
 
28
28
  def compile(rb_path)
29
+ Mrbc.check_version!
29
30
  tmp = Tempfile.new(['prremote', '.mrb'])
30
31
  out, status = Open3.capture2e(Mrbc.bin, '-o', tmp.path, rb_path)
31
32
  raise "mrbc failed:\n#{out.chomp}" unless status.success?
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  module Prremote
4
4
  module Commands
5
5
  class Install
6
- def initialize(version: RUNTIME_VERSION, board: 'picow')
6
+ def initialize(version: VERSION, board: 'picow')
7
7
  @version = version
8
8
  @board = board
9
9
  end
@@ -23,6 +23,7 @@ module Prremote
23
23
  private
24
24
 
25
25
  def compile(rb_path)
26
+ Mrbc.check_version!
26
27
  tmp = Tempfile.new(['prremote', '.mrb'])
27
28
  out, status = Open3.capture2e(Mrbc.bin, '-o', tmp.path, rb_path)
28
29
  raise "mrbc failed:\n#{out.chomp}" unless status.success?
data/lib/prremote/mrbc.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  require 'open3'
2
2
 
3
3
  module Prremote
4
+ # mrbc lookup order:
5
+ # 1. MRBC env var if set (use this to point at a non-PATH binary)
6
+ # 2. PATH entries, excluding rbenv shims — shims delegate to the project's
7
+ # .ruby-version (typically CRuby) and do not work as a standalone mrbc
8
+ # 3. rbenv direct installs (~/.rbenv/versions/mruby-*/bin/mrbc)
9
+ # The first candidate wins; version compatibility is checked in check_version!.
4
10
  module Mrbc
5
11
  SHIMS_RE = %r{\.rbenv/shims}
12
+ REQUIRED_MAJOR = 4
6
13
 
7
14
  def self.bin
8
15
  return ENV['MRBC'] if ENV['MRBC'] && File.executable?(ENV['MRBC'])
9
16
 
10
- found = ENV['PATH'].split(File::PATH_SEPARATOR)
11
- .grep_v(SHIMS_RE)
12
- .map { |d| File.join(d, 'mrbc') }
13
- .find { |f| File.executable?(f) }
14
-
15
- found || raise('mrbc not found. Install mruby: brew install mruby')
17
+ (path_candidates + rbenv_candidates).first ||
18
+ raise('mrbc not found. Install mruby 4.x: brew install mruby')
16
19
  end
17
20
 
18
21
  def self.version
@@ -21,5 +24,35 @@ module Prremote
21
24
  rescue RuntimeError
22
25
  '(mrbc not found)'
23
26
  end
27
+
28
+ def self.major_version
29
+ version[/\bmruby (\d+)\./, 1]&.to_i
30
+ end
31
+
32
+ def self.check_version!
33
+ return if @version_ok
34
+
35
+ major = major_version
36
+ unless major && major >= REQUIRED_MAJOR
37
+ raise "mrbc is mruby #{major || '?'}.x but mruby #{REQUIRED_MAJOR}.x or newer is required.\n" \
38
+ "Installed: #{version}\n" \
39
+ "Install mruby 4.x: brew install mruby\n" \
40
+ "On Linux: build from source (https://github.com/mruby/mruby/releases)"
41
+ end
42
+
43
+ @version_ok = true
44
+ end
45
+
46
+ private_class_method def self.path_candidates
47
+ ENV['PATH'].split(File::PATH_SEPARATOR)
48
+ .grep_v(SHIMS_RE)
49
+ .map { |d| File.join(d, 'mrbc') }
50
+ .select { |f| File.executable?(f) }
51
+ end
52
+
53
+ private_class_method def self.rbenv_candidates
54
+ Dir.glob(File.expand_path('~/.rbenv/versions/mruby-*/bin/mrbc'))
55
+ .select { |f| File.executable?(f) }
56
+ end
24
57
  end
25
58
  end
@@ -1,4 +1,3 @@
1
1
  module Prremote
2
- VERSION = '0.1.1'.freeze
3
- RUNTIME_VERSION = '0.1.3'.freeze
2
+ VERSION = File.read(File.expand_path('../../VERSION', __dir__)).strip
4
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prremote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITO Yosei
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - LICENSE
105
105
  - README.md
106
+ - VERSION
106
107
  - bin/prremote
107
108
  - lib/prremote.rb
108
109
  - lib/prremote/cli.rb