Skip to content

Commit

Permalink
Merge pull request #88 from NREL/extension_gem
Browse files Browse the repository at this point in the history
Configure OSW with extension gems if present
  • Loading branch information
Dan Macumber committed Sep 4, 2019
2 parents 6757815 + 576051d commit cf62056
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/openstudio/workflow/adapters/input/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ def initialize(osw_path = './workflow.osw')
if File.exist? @osw_abs_path
@workflow = ::JSON.parse(File.read(@osw_abs_path), symbolize_names: true)
end


begin
# configure the OSW with paths for loaded extension gems
# Bundler.require is called in the CLI to load extension gems
@workflow = OpenStudio::Extension::configure_osw(@workflow)
rescue NameError => e
end

@workflow_json = nil
@run_options = nil
if @workflow
Expand Down
16 changes: 16 additions & 0 deletions lib/openstudio/workflow/jobs/run_initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ def perform
@registry.register(:root_dir) { workflow_json.absoluteRootDir }
@logger.debug "The root_dir for the datapoint is #{@registry[:root_dir]}"

generated_files_dir = "#{@registry[:root_dir]}/generated_files"
if File.exist?(generated_files_dir)
@logger.debug "Removing existing generated files directory: #{generated_files_dir}"
FileUtils.rm_rf(generated_files_dir)
end
@logger.debug "Creating generated files directory: #{generated_files_dir}"
FileUtils.mkdir_p(generated_files_dir)

# insert the generated files directory in the first spot so all generated ExternalFiles go here
file_paths = @registry[:workflow_json].filePaths
@registry[:workflow_json].resetFilePaths
@registry[:workflow_json].addFilePath(generated_files_dir)
file_paths.each do |file_path|
@registry[:workflow_json].addFilePath(file_path)
end

reports_dir = "#{@registry[:root_dir]}/reports"
if File.exist?(reports_dir)
@logger.debug "Removing existing reports directory: #{reports_dir}"
Expand Down
11 changes: 11 additions & 0 deletions lib/openstudio/workflow_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ def absoluteFilePaths
end
result
end

def addFilePath(path)
if !@workflow[:file_paths]
@workflow[:file_paths] = []
end
@workflow[:file_paths] << path
end

def resetFilePaths()
@workflow[:file_paths] = []
end

# Attempts to find a file by name, searches through filePaths in order and returns first match.
# boost::optional<openstudio::path> findFile(const openstudio::path& file);
Expand Down

0 comments on commit cf62056

Please sign in to comment.