Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into ghe-borehole-top-d…
Browse files Browse the repository at this point in the history
…epth
  • Loading branch information
jmarrec committed Dec 23, 2024
2 parents 4639c7e + f19c71b commit 1ff4566
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/module/openstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
# When we're using system python to load the **installed** C:\openstudio-X.Y-Z\Python stuff (not PyPi package)
# This allows finding openstudiolib.dll and the msvc ones in the bin/ folder while we're in the Python/ folder
# Otherwise you'd have to manually copy these DLLs from bin/ to Python/
os.add_dll_directory(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'bin')))
bin_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'bin'))
if os.path.isdir(bin_dir):
os.add_dll_directory(bin_dir)

import openstudioairflow as airflow
import openstudioenergyplus as energyplus
import openstudioepjson as epjson
Expand Down
25 changes: 19 additions & 6 deletions ruby/engine/embedded_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# See also https://openstudio.net/license
########################################################################################################################

require 'stringio'

module EmbeddedScripting
@@fileNames = EmbeddedScripting::allFileNamesAsString.split(';')

Expand Down Expand Up @@ -56,6 +58,17 @@ def self.preprocess_ruby_script(s)
# DLM: ignore for now
#Encoding.default_external = Encoding::ASCII

# We patch Kernel.open, and IO.open
# to read embedded files as a StringIO, not as a FileIO
# But Gem.open_file for eg expects it to be a File, not a StringIO, and on
# Windows it will call File::flock (file lock) to protect access, but StringIO
# does not have this method
class FakeFileAsStringIO < StringIO
def flock(operation)
return 0
end
end

module Kernel
# ":" is our root path to the embedded file system
# make sure it is in the ruby load path
Expand Down Expand Up @@ -329,21 +342,21 @@ def open(name, *args, **options)
#puts "string = #{string}"
if block_given?
# if a block is given, then a new IO is created and closed
io = StringIO.open(string)
io = FakeFileAsStringIO.open(string)
begin
result = yield(io)
ensure
io.close
end
return result
else
return StringIO.open(string)
return FakeFileAsStringIO.open(string)
end
else
#puts "IO.open cannot find embedded file '#{absolute_path}' for '#{name}'"
if block_given?
# if a block is given, then a new IO is created and closed
io = StringIO.open("")
io = FakeFileAsStringIO.open("")
begin
result = yield(io)
ensure
Expand Down Expand Up @@ -459,21 +472,21 @@ def self.open(name, *args, **options)
#puts "string = #{string}"
if block_given?
# if a block is given, then a new IO is created and closed
io = StringIO.open(string)
io = FakeFileAsStringIO.open(string)
begin
result = yield(io)
ensure
io.close
end
return result
else
return StringIO.open(string)
return FakeFileAsStringIO.open(string)
end
else
puts "IO.open cannot find embedded file '#{absolute_path}' for '#{name}'"
if block_given?
# if a block is given, then a new IO is created and closed
io = StringIO.open("")
io = FakeFileAsStringIO.open("")
begin
result = yield(io)
ensure
Expand Down
5 changes: 5 additions & 0 deletions src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ if(BUILD_TESTING)
PASS_REGULAR_EXPRESSION "Hello from -x, at National Renewable Energy Laboratory"
)

# Test for 5315
add_test(NAME OpenStudioCLI.EmbeddedScripting.uuid
COMMAND $<TARGET_FILE:openstudio> ${CMAKE_CURRENT_SOURCE_DIR}/test/ensure_uuid_can_be_loaded.rb
)

add_test(NAME OpenStudioCLI.Classic.Run_RubyOnly
COMMAND $<TARGET_FILE:openstudio> classic run -w compact_ruby_only.osw
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/resources/Examples/compact_osw/"
Expand Down
5 changes: 5 additions & 0 deletions src/cli/test/ensure_uuid_can_be_loaded.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'uuid'

u = UUID.new

puts u.inspect

0 comments on commit 1ff4566

Please sign in to comment.