pryx 0.2.1 → 0.3.1

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
  SHA256:
3
- metadata.gz: 9e9df58b33aa6664a4dde048917ca07b3bef6657887f375519e55b6af5057233
4
- data.tar.gz: 989c5847170b26ddc25b5df9bdefd57b7637fcfc6e35c2aa02ed9233611dfc53
3
+ metadata.gz: dcb416c6abf10f2f3445ba1f230cc22f2839fd2056e0eb789d292bc611a463c5
4
+ data.tar.gz: 560f480272bee2673cb6b415267dc224f30d618015123734f75d9a97ed3be311
5
5
  SHA512:
6
- metadata.gz: 62f46e7621471d1f1392df46414b0ca2b9547787f1fc59eed17fc1b67377bbe33c3a63688a643c0cc8da41b907ba92a4cf2c3df3668b07a4bfb8a404ab21f855
7
- data.tar.gz: 74a2b738793ac8000341f0828a9f13f22e54edbbcdb848050e7aa6554c2255d239951466261e7c28831d7a9456cdf2e376a0b77adea0a7ebfa09ca03e1155ffd
6
+ metadata.gz: f042cb7cbe7d0ca0ceec859a39ef85d90fe871ca45fe1d34151a4fb87f094a9658f0ee35ef70a4900bd1a0f7e957e766127c82e4083f219b46150ba7f9b07b2a
7
+ data.tar.gz: e695d828a869dd19a654e91d087ea3c3ad777a5c951b2f07cb54e832e721d7a4d0f4f3e54a993cde6dedc86a2957b5f51a0417d5393ef7f43c8d83934e8ec706
data/bin/irbx ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # irb.rb - interactive ruby
4
+ # $Release Version: 0.9.6 $
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+
9
+ require 'irb'
10
+ require 'pryx_irb'
11
+
12
+ IRB.start(__FILE__)
data/bin/pryx ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # (C) John Mair (banisterfiend)
5
+ # MIT license
6
+
7
+ $0 = 'pry'
8
+
9
+ require 'pry'
10
+ require 'pryx'
11
+
12
+ # Process command line options and run Pry
13
+ opts = Pry::CLI.parse_options
14
+ Pry::CLI.start(opts)
data/lib/pry-disasm.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'pry'
4
4
  require 'pry-disasm/commands'
5
- require 'pry-disasm/version'
6
5
 
7
6
  class PryDisasm
8
7
  def self.process(expr)
data/lib/pryx/ap_hack.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'awesome_print'
2
2
 
3
- AwesomePrint.defaults = {
4
- index: false
5
- }
3
+ # AwesomePrint.defaults = {
4
+ # index: false
5
+ # }
6
6
 
7
7
  if defined? AwesomePrint
8
8
  if defined? Pry
@@ -0,0 +1,20 @@
1
+ module Pryx::Background
2
+ # 如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)
3
+ # 否则,如果不等,那么就是后台进程。
4
+ # system("\\cat /proc/#{pid}/stat |awk '$5==$8 {exit 1}'")
5
+ def self.background?(pid=$$)
6
+ # 这个实现似乎有错, 因为针对 nohup 1.rb& 这种情况,返回为前台进程。
7
+ # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’
8
+ # ary = File.read("/proc/#{pid}/stat").split(' ').reverse
9
+ # is_bg = (ary[46] != ary[48])
10
+
11
+ # 这个实现依赖于一些 linux 下基本工具,但是准确
12
+ is_bg = system("ps -e -o pid,pgid,tpgid |grep '^\s*#{pid}' |awk '$2==$3 {exit 1}'")
13
+
14
+ is_bg && !$stdout.tty?
15
+ end
16
+
17
+ def self.foreground?(pid=$$)
18
+ not background?(pid)
19
+ end
20
+ end
@@ -1,2 +1,6 @@
1
1
  require 'break'
2
2
  load "#{__dir__}/../break/pry/extensions.rb"
3
+
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 's', 'step'
6
+ Pry.commands.alias_command 'w', 'watch' # watch is pry builtin
@@ -0,0 +1,46 @@
1
+ require 'binding_of_caller'
2
+
3
+ class Binding
4
+ def _irb(_host=nil)
5
+ warn 'loading irb ...'
6
+
7
+ if defined? Break and defined? IRB
8
+ # This is need for work with looksee better.
9
+ # See discuss on https://github.com/oggy/looksee/issues/57
10
+ IRB.conf[:USE_COLORIZE] = false
11
+ else
12
+ warn "For work with Break and Looksee, please set
13
+ export RUBYOPT='-rpryx_irb'
14
+ instead of
15
+ export RUBYOPT='-rpryx'
16
+ "
17
+ end
18
+
19
+ self.irb
20
+ end
21
+ end
22
+
23
+ module Kernel
24
+ def irb!
25
+ return unless ENV['IRB_was_started'].nil?
26
+
27
+ ENV['IRB_was_started'] = 'true'
28
+
29
+ binding.of_caller(1)._irb
30
+ end
31
+
32
+ def reirb!
33
+ ENV['IRB_was_started'] = nil
34
+ end
35
+
36
+ def irb1
37
+ ENV['IRB2_should_start'] = 'true'
38
+ end
39
+
40
+ def irb2(caller=1, remote: nil, port: 9876)
41
+ if ENV['IRB2_should_start'] == 'true'
42
+ ENV['IRB2_should_start'] = nil
43
+ binding.of_caller(caller)._irb
44
+ end
45
+ end
46
+ end
data/lib/pryx/pry_hack.rb CHANGED
@@ -29,36 +29,20 @@ class Binding
29
29
  self.pry
30
30
  end
31
31
  end
32
-
33
- def _irb(_host=nil)
34
- warn 'loading irb ...'
35
-
36
- self.irb
37
- end
38
32
  end
39
33
 
40
34
  module Kernel
41
35
  # 运行 pry! 会被拦截, 且只会被拦截一次.
42
- def pry!(caller=2, remote: nil, port: 9876)
36
+ def pry!(remote: nil, port: 9876)
43
37
  return unless ENV['Pry_was_started'].nil?
44
38
 
45
39
  ENV['Pry_was_started'] = 'true'
46
40
 
47
- if background?
48
- remote = '0.0.0.0'
49
- port = 9876
50
- end
51
-
52
- pry3(caller, remote: remote, port: port)
41
+ pry3(2, remote: remote, port: port)
53
42
 
54
43
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
55
44
  end
56
45
 
57
- # 注意:pryr 总是会被拦截。
58
- def pryr
59
- pry3(caller=2, remote: '0.0.0.0', port: 9876)
60
- end
61
-
62
46
  # 在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!
63
47
  def repry!
64
48
  ENV['Pry_was_started'] = nil
@@ -66,13 +50,13 @@ module Kernel
66
50
 
67
51
  # 和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。
68
52
  # 注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。
69
- def pry?(caller=2, remote: nil, port: 9876)
53
+ def pry?(remote: nil, port: 9876)
70
54
  return unless ENV['Pry_was_started'].nil?
71
55
 
72
56
  require 'pry-state'
73
57
  ENV['Pry_was_started'] = 'true'
74
58
 
75
- pry3(caller, remote: remote, port: port)
59
+ pry3(2, remote: remote, port: port)
76
60
 
77
61
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
78
62
  end
@@ -80,6 +64,8 @@ module Kernel
80
64
  # 等价于默认的 binding.pry, 会反复被拦截。
81
65
  # 起成 pry3 这个名字,也是为了方便直接使用。
82
66
  def pry3(caller=1, remote: nil, port: 9876)
67
+ remote = '0.0.0.0' if Pryx::Background.background?
68
+
83
69
  binding.of_caller(caller)._pry(remote, port)
84
70
  end
85
71
 
@@ -92,75 +78,49 @@ module Kernel
92
78
 
93
79
  def pry2(caller=1, remote: nil, port: 9876)
94
80
  if ENV['Pry2_should_start'] == 'true'
95
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
96
81
  ENV['Pry2_should_start'] = nil
97
82
  binding.of_caller(caller)._pry(remote, port)
98
83
  end
99
84
  end
100
85
 
101
- def reirb!
102
- ENV['IRB_was_started'] = nil
103
- end
104
-
105
- def irb!
106
- return unless ENV['IRB_was_started'].nil?
107
-
108
- ENV['IRB_was_started'] = 'true'
109
-
110
- binding.of_caller(1)._irb
111
- end
86
+ def notify_send(msg)
87
+ system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'
112
88
 
113
- def irb1
114
- ENV['IRB2_should_start'] = 'true'
89
+ system('aplay "#{__dir__}/drip.wav" &>/dev/null') if system 'which aplay &>/dev/null'
90
+ warn "#{msg}"
115
91
  end
92
+ end
116
93
 
117
- def irb2(caller=1, remote: nil, port: 9876)
118
- if ENV['IRB2_should_start'] == 'true'
119
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
120
- ENV['IRB2_should_start'] = nil
121
- binding.of_caller(caller)._irb
122
- end
123
- end
94
+ # Hack for roda/rails, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
95
+ # 这可以确保,pry! 总是会被拦截,但是仅仅只会被拦截一次。
124
96
 
125
- # 如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)
126
- # 否则,如果不等,那么就是后台进程。
127
- # system("ps -e -o pid,pgid,tpgid |grep '^\s*#{pid}' |awk '$2==$3 {exit 1}'")
128
- # system("\\cat /proc/#{pid}/stat |awk '$5==$8 {exit 1}'")
129
- def background?(pid=$$)
130
- # 考虑是否需要验证
131
- ary = File.read("/proc/#{pid}/stat").split(' ').reverse
132
- # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’
133
- (ary[46] != ary[48]) && !$stdout.tty?
134
- end
97
+ class Pryx::PryHackForRodaRailsMiddleware
98
+ attr_reader :app
135
99
 
136
- def foreground?(pid=$$)
137
- not background?(pid)
100
+ def initialize(app)
101
+ @app = app
138
102
  end
139
103
 
140
- def notify_send(msg)
141
- system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'
142
-
143
- system('aplay "#{__dir__}/drip.wav" &>/dev/null') if system 'which aplay &>/dev/null'
144
- warn "#{msg}"
104
+ def call(env)
105
+ ENV['Pry_was_started'] = nil
106
+ @app.call(env)
145
107
  end
146
108
  end
147
109
 
148
- # Hack roda, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
149
- # 这可以确保,pry! 总是会被拦截,但是仅仅只会被拦截一次。
150
110
  begin
151
111
  require 'roda'
152
- class PryHackRodaMiddleware
153
- attr_reader :app
154
-
155
- def initialize(app)
156
- @app = app
157
- end
112
+ Roda.use Pryx::PryHackForRodaRailsMiddleware
113
+ rescue LoadError
114
+ end
158
115
 
159
- def call(env)
160
- ENV['Pry_was_started'] = nil
161
- @app.call(env)
162
- end
116
+ begin
117
+ require 'active_support/lazy_load_hooks'
118
+ ActiveSupport.on_load(:before_configuration) do
119
+ # because exits less command error when use in container, use irb instead.
120
+ # require 'pry'
121
+ # require 'pryx'
122
+ # Rails.application.config.console = Pry
123
+ Rails.application.config.middleware.use Pryx::PryHackForRodaRailsMiddleware
163
124
  end
164
- Roda.use PryHackRodaMiddleware
165
125
  rescue LoadError
166
126
  end
data/lib/pryx/version.rb CHANGED
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pryx
4
- VERSION = '0.2.1'
4
+ VERSION = [0, 3, 1]
5
+
6
+ class << VERSION
7
+ include Comparable
8
+
9
+ def to_s
10
+ join('.')
11
+ end
12
+ end
5
13
  end
data/lib/pryx.rb CHANGED
@@ -1,9 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pryx/version'
4
+ require 'pryx/background'
4
5
  require 'pryx/trap_backtrace'
5
6
  require 'pryx/looksee_hack'
6
7
  require 'pryx/pry_hack'
8
+ require 'pryx/irb_hack'
7
9
 
10
+ # Add the non-bundler managermented gems back
11
+ # this step is necessory when install pryx in docker-compose
12
+ ENV['RUBYLIB'] = $LOAD_PATH.grep(/gems/).join(':')
13
+
14
+ # set export RUBYOPT+=" -rpryx" to work with pryx.
8
15
  module Pryx
9
16
  end
data/lib/pryx_irb.rb CHANGED
@@ -1,3 +1,14 @@
1
+ # We need apply those hack before irb was loaded for work with irb.
2
+ # So we have to add it here, same hacks for Pry is add to method
3
+ # Binding#_pry which defined in lib/pryx/pry_hack.rb
4
+
5
+ # we need set `export RUBYOPT+=" -rpryx_irb"` instead of `-rpryx` to make
6
+ # irb work with break and ap gem.
7
+
8
+ # ap_hack 可以确保,当时用 irb! 的时候,输入代码是彩色的,并且 looksee 也正常显示
9
+ # 但是,ap_hack 不可以放到 break_hack 后面,否则会失效。
10
+ # WARN: 下面两行代码顺序不要换。
1
11
  require 'pryx/ap_hack'
2
12
  require 'pryx/break_hack'
13
+
3
14
  require 'pryx'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pryx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -140,13 +140,17 @@ description: ''
140
140
  email:
141
141
  - vil963@gmail.com
142
142
  executables:
143
+ - irbx
143
144
  - pry!
145
+ - pryx
144
146
  extensions: []
145
147
  extra_rdoc_files: []
146
148
  files:
147
149
  - LICENSE
148
150
  - README.md
151
+ - bin/irbx
149
152
  - bin/pry!
153
+ - bin/pryx
150
154
  - lib/break/pry/extensions.rb
151
155
  - lib/pry-byebug.rb
152
156
  - lib/pry-byebug/WARN
@@ -159,8 +163,10 @@ files:
159
163
  - lib/pry-remote.rb
160
164
  - lib/pryx.rb
161
165
  - lib/pryx/ap_hack.rb
166
+ - lib/pryx/background.rb
162
167
  - lib/pryx/break_hack.rb
163
168
  - lib/pryx/drip.wav
169
+ - lib/pryx/irb_hack.rb
164
170
  - lib/pryx/looksee_hack.rb
165
171
  - lib/pryx/pry_hack.rb
166
172
  - lib/pryx/trap_backtrace.rb
@@ -189,5 +195,5 @@ requirements: []
189
195
  rubygems_version: 3.3.3
190
196
  signing_key:
191
197
  specification_version: 4
192
- summary: ''
198
+ summary: pry extension tools!
193
199
  test_files: []