diff --git a/python/module/openstudio.py b/python/module/openstudio.py index 62e8260b440..ee9c1bad671 100644 --- a/python/module/openstudio.py +++ b/python/module/openstudio.py @@ -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 diff --git a/ruby/engine/embedded_help.rb b/ruby/engine/embedded_help.rb index 95e205dd9db..6a9666a982c 100644 --- a/ruby/engine/embedded_help.rb +++ b/ruby/engine/embedded_help.rb @@ -3,6 +3,8 @@ # See also https://openstudio.net/license ######################################################################################################################## +require 'stringio' + module EmbeddedScripting @@fileNames = EmbeddedScripting::allFileNamesAsString.split(';') @@ -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 @@ -329,7 +342,7 @@ 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 @@ -337,13 +350,13 @@ def open(name, *args, **options) 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 @@ -459,7 +472,7 @@ 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 @@ -467,13 +480,13 @@ def self.open(name, *args, **options) 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 diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index e79684fcdfc..74c557322a6 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -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 $ ${CMAKE_CURRENT_SOURCE_DIR}/test/ensure_uuid_can_be_loaded.rb + ) + add_test(NAME OpenStudioCLI.Classic.Run_RubyOnly COMMAND $ classic run -w compact_ruby_only.osw WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/resources/Examples/compact_osw/" diff --git a/src/cli/test/ensure_uuid_can_be_loaded.rb b/src/cli/test/ensure_uuid_can_be_loaded.rb new file mode 100644 index 00000000000..41e4cfd19b5 --- /dev/null +++ b/src/cli/test/ensure_uuid_can_be_loaded.rb @@ -0,0 +1,5 @@ +require 'uuid' + +u = UUID.new + +puts u.inspect