Temporarily installing Pry gem during plugin development

Hi everyone,

I come to Sketchup development from a background of about 5 years of development in pure Ruby and RoR. I’ve read a few threads on the forums about the trials and tribulations of trying to install gems for plugins, and followed suggestions in threads like this: https://forums.sketchup.com/t/keeping-gems-locally-inside-extension/59436/6

I’m working with a complicated existing codebase on a plugin, and would love to be able to work with my beloved Pry bindings to access program state while developing. There is no need to leave the gem installed outside of the development environment.

I tried including the gem install in a module I’m working with, following the approach in the above thread, and it seemed to install ok, but pry is giving me errors when I try to call it. Here is just the last line of the call stack:

Error: #<NoMethodError: undefined method `sync=' for #<Sketchup::Console:0x007fd0451a84d0>>
/Users/jessefarber/Library/Application Support/SketchUp 2018/SketchUp/Gems/gems/pry-0.11.3/lib/pry/config/default.rb:10:in `block (2 levels) in <class:Default>'`

I am aware that things like matching version numbers can be the issue, but I thought maybe someone here has looked at the ins and outs of getting the Pry gem to work here before. Does anyone have any ideas?

Thanks!

What is Pry ? What does it do ?
Why do you need it during development ?

The error might be due to the fact that SketchUp embedded Ruby redirects $stdin and $stdout to its singleton Sketchup::Console object, referenced by the global constant SKETCHUP_CONSOLE.

Thanks for the reply. In this context, Pry is a debugger that allows you to freeze program state during runtime, e.g. to check variable values interactively, try running other code on the current state, etc. It usually operates through the CLI, but using it in the SketchUp console would be perfectly fine, if I could figure out how to set this up.

Pry Gem

I doubt it will work very well if at all within SketchUp’s embedded Ruby.

You’d be better off installing SketchUp’s debugger hooks and using an external IDE of your choice.

1 Like

Thanks, I’ll give that a try.

No problem. Read the README at the GitHub repo for instructions.

There are some other specific threads around on using specific IDEs with the SketchUp debugger utility library.

Great, thanks.
So is it necessary to use an IDE for the debugger, as opposed to a text editor?

Sorry–just a saw a post of yours about connecting SublimeText. That’ll work for me!

Not mine. I’m on PC and use Notepad++ myself.

I think the debugger hooks are meant for full blown IDEs. ( Corrected by Thomas below. )

At one time I had installed a Notepad++ python extension that added a button which would reload the current rb document into the running SketchUp application process. (But I think this extension by Jim Foltz was PC only.)

From the GitHub project there are links to editor setup guides. For VSCode for instance you have this: VSCode Debugger Setup · SketchUp/sketchup-ruby-api-tutorials Wiki · GitHub

You can use it with any editor that support the rdebug-ide gem - either nativly or via extensions.

As for getting gems compiled and installed SketchUp, I’ve typically built them using standalone Ruby (with a matching version as SketchUp’s) and then manually copied them into the SketchUp gems directory.

I think @MSP_Greg have dug deeper into getting the developer kit to work from within SketchUp.

I generally prefer using the Ruby Debugger over Pry. Maybe I just didn’t get the hand of Pry, but you didn’t seem to be able to step through code. With the debugger you easily see the stack, with all the available variables. And you can eval things in the scope of your current breakpoint.

1 Like

Thanks, that’s helpful. I’ll need to see how to run the ruby debugger, and how to connect it to sublime text. I’d rather not switch my text editor, but I’ve never had to get Sublime Text connected to a port before, and I’m not finding it obvious so far.

@fleawig

I come to Sketchup development from a background of about 5 years of development in pure Ruby and RoR

That helps.

but I’ve never had to get Sublime Text connected to a port before, and I’m not finding it obvious so far.

Have you used debugging in Sublime from stand-alone Ruby? I (hopefully) can help after that’s working.

I suspect CLI based debuggers like Pry and ByeBug may not be usable in SketchUp.

MacOS or windows?

Greg

Did you try defining a sync method for the console object? I think sync just flushes the output on every write. You might get lucky.

Thanks Greg, thanks for helping!
I actually haven’t done that kind of debugging in Sublime before. I’ve generally used a mix of Pry in the CLI, and browser tools for web development.
I’m going to have to set this up in both Mac OS and Windows, but Mac is a little more urgent.
I’d probably be happy to use the debugger mentioned above if I can get it to work… but Windows seems to be a whole other can of worms.

Thanks Jim, I will definitely look into this approach.

I’d probably be happy to use the debugger mentioned above if I can get it to work

VSCode is cross-platform, and it doesn’t look like you need to compile anything (or install any gems), but yiu do need the files at sketchup-ruby-debugger

I may see if I can get it connected this weekend. FYI, I’m a windows type.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.