Skip to content

Commit

Permalink
Adapter: made LBT PythonEnvironment a private property (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Greenroyd authored Feb 1, 2024
2 parents f0627c1 + b4aec62 commit c39f290
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 6 additions & 10 deletions LadybugTools_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public List<object> IRunCommand(IExecuteCommand command)

private List<object> RunCommand(GetMaterialCommand command)
{
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
LadybugConfig config = new LadybugConfig()
{
JsonFile = new FileSettings()
Expand All @@ -88,7 +87,7 @@ private List<object> RunCommand(GetMaterialCommand command)
{
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py");

string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";

Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
}
Expand All @@ -103,7 +102,6 @@ private List<object> RunCommand(GetMaterialCommand command)

private List<object> RunCommand(GetTypologyCommand command)
{
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
LadybugConfig config = new LadybugConfig()
{
JsonFile = new FileSettings()
Expand All @@ -117,7 +115,7 @@ private List<object> RunCommand(GetTypologyCommand command)
{
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py");

string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";

Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
}
Expand Down Expand Up @@ -179,12 +177,11 @@ private List<object> RunCommand(RunSimulationCommand command)
// push object to json file
Push(new List<SimulationResult>() { simulationResult }, actionConfig: config);

// locate the Python executable and file containing the simulation code
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
// locate the Python file containing the simulation code
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "simulation_result.py");

// run the simulation
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

// reload from Python results
Expand Down Expand Up @@ -232,12 +229,11 @@ private List<object> RunCommand(RunExternalComfortCommand command)
// push objects to json file
Push(new List<ExternalComfort>() { externalComfort }, actionConfig: config);

// locate the Python executable and file containing the simulation code
PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true);
// locate the Python file containing the simulation code
string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "external_comfort.py");

// run the calculation
string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

// reload from Python results
Expand Down
10 changes: 7 additions & 3 deletions LadybugTools_Adapter/LadybugTools_Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

using System.ComponentModel;
using BH.oM.Base.Attributes;

using BH.oM.Python;

namespace BH.Adapter.LadybugTools
{
Expand All @@ -33,7 +33,11 @@ public partial class LadybugToolsAdapter : BHoMAdapter
public LadybugToolsAdapter()
{
m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.CreateOnly;

//get the base python environment first, as LBT is dependant on it.
BH.Engine.Python.Compute.BasePythonEnvironment(run: true);
m_environment = BH.Engine.LadybugTools.Compute.InstallPythonEnv_LBT(run: true);
}
private readonly PythonEnvironment m_environment;
}
}

}

0 comments on commit c39f290

Please sign in to comment.