Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
3

multiple openstudio installations

asked 2020-02-12 23:06:48 -0600

ngkhanh gravatar image

updated 2020-02-14 10:51:16 -0600

I have both OpenStudio versions 2.8.1 and 2.9.1 installed on my Mac with rbenv Ruby 2.2.4 and .bash_ profile setup as follow:

## add openstudio 
export PATH="/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/bin:$PATH"
export RUBYLIB="/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/Ruby/"

wonder how to programtically jump between 2 versions (2.8.1 and 2.9.1) for scripting works?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2020-02-13 07:26:57 -0600

updated 2020-02-18 02:47:28 -0600

I do not ever set these variables in the .bash_profile. I just symlink the openstudio CLI you want to use in /usr/local/bin (or equivalent).

For use in interactive ruby, I use pry with a .pryrc personally. (gem install pry).

You can just write ruby code to be executed before the session starts.

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3")
  # Do something
else
  # Do something else
end

I have a prompt actually that allows me to select either openstudio installed or my local builds

print "Do you want OpenStudio (os) or os-debug (1) / os-release (2), or os-app-debug (3) / os-app-release (4): [os/1/2/3/4] "
input = gets.strip

# This typically loads a custom build installed on my computer
if input == '1'
  p = File.join(ENV["HOME"], "Software/Others/OS-build/Products/ruby/openstudio")
elsif input == '2'
  p = File.join(ENV["HOME"], "Software/Others/OS-build-release/Products/ruby/openstudio")
elseif ...

else
  p = 'openstudio' # Installed openstudio
end

require p
puts "Loading '#{p}': #{OpenStudio::openStudioLongVersion}"

In your case, you can revamp that easily to have that prompt require either 2.8.1 or 2.9.1

print "Do you want OpenStudio 2.8.1 (1) or 2.9.1 (2): [1/2] "
input = gets.strip

if input == '1':
  p = '/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_8_1/Ruby/openstudio'
else
  p = '/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/Ruby/openstudio'
end

require p
puts "Loading '#{p}': #{OpenStudio::openStudioLongVersion}"
edit flag offensive delete link more
0

answered 2020-02-13 10:30:39 -0600

ngkhanh gravatar image

updated 2020-02-13 10:33:04 -0600

Thanks Julien for useful code. While I just work with one or two versions at same time, I find out this setup lauch for VS Code (other IDE would be similar). My key concern is require 'openstudio' needs proper RUBYLIB path. Not sure how to setup RUBYLIB inside script

"configurations": [
        {
            "name": "RunFile",
            "type": "Ruby",
            "request": "launch",
            "cwd": "${fileDirname}",
            "program": "${file}",
            "env":
                {  
                    "OS_291": "/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/bin/openstudio",
                    "RUBYLIB":"/Users/home/Desktop/App/Run/OpenStudio/OpenStudio_2_9_1/Ruby"
                }
        }
    ]
edit flag offensive delete link more

Comments

I guess if you're trying to use ruby itself in that context, you probably need to find a way to call ruby -I ../openstudio.so. For eg try this in a terminal (adusting the path to openstudio.so): ruby -I /home/julien/Software/Others/OS-build/Products/openstudio.so -e "require 'openstudio'; puts OpenStudio::openStudioLongVersion". This is probably something you can do in vscode by adding a new key "args" : ["-I", "/home/julien/Software/Others/OS-build/Products/openstudio.so"] stuff.

Julien Marrec gravatar imageJulien Marrec ( 2020-02-18 02:54:58 -0600 )edit

The alternative is to use the CLI directly. something like "program" : "openstudio-2-9-1 ${file}" might work just fine too.

(I don't use VSCode so not 100% sure).

Julien Marrec gravatar imageJulien Marrec ( 2020-02-18 02:59:04 -0600 )edit

${file} probably goes into the args key too. See the example about RSpec which would be very similar here

Julien Marrec gravatar imageJulien Marrec ( 2020-02-18 03:01:56 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

 

Question Tools

2 followers

Stats

Asked: 2020-02-12 23:06:48 -0600

Seen: 53 times

Last updated: Feb 18