Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.1 Deployment #99

Merged
merged 9 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Python_Engine/Compute/DownloadPython.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -32,7 +32,6 @@ public static partial class Compute
[Description("Download a target version of Python.")]
[Input("version", "A Python version.")]
[Output("executablePath", "The path of the executable for the downloaded Python.")]
[PreviousVersion("5.3", "BH.Engine.Python.Compute.DownloadPython()")]
public static string DownloadPython(this BH.oM.Python.Enums.PythonVersion version)
{
string targetDirectory = Query.EnvironmentsDirectory();
Expand Down Expand Up @@ -63,3 +62,4 @@ public static string DownloadPython(this BH.oM.Python.Enums.PythonVersion versio
}
}


3 changes: 2 additions & 1 deletion Python_Engine/Compute/InstallBasePythonEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -118,3 +118,4 @@ public static oM.Python.PythonEnvironment InstallBasePythonEnvironment(bool run
}
}
}

7 changes: 4 additions & 3 deletions Python_Engine/Compute/InstallReferencedVirtualenv.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -67,12 +67,12 @@ public static oM.Python.PythonEnvironment InstallReferencedVirtualenv(
string bhomPythonExecutable = baseEnv.Executable;

// set location where virtual env will be created
string targetDirectory = Path.Combine(Query.EnvironmentsDirectory(), name);
string targetDirectory = Query.VirtualEnvDirectory(name);
if (!Directory.Exists(targetDirectory))
Directory.CreateDirectory(targetDirectory);

// return existing env if it already exists
oM.Python.PythonEnvironment env = new oM.Python.PythonEnvironment() { Name = name, Executable = Path.Combine(targetDirectory, "Scripts", "python.exe") };
oM.Python.PythonEnvironment env = new oM.Python.PythonEnvironment() { Name = name, Executable = Query.VirtualEnvPythonExePath(name) };
if (env.EnvironmentExists())
{
BH.Engine.Base.Compute.RecordNote($"The {name} environment already exists and is being returned here instead of installing it again. To install a fresh version of this environment, remove this environment first.");
Expand Down Expand Up @@ -113,3 +113,4 @@ public static oM.Python.PythonEnvironment InstallReferencedVirtualenv(
}
}
}

3 changes: 2 additions & 1 deletion Python_Engine/Compute/InstallVirtualenv.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -107,3 +107,4 @@ public static oM.Python.PythonEnvironment InstallVirtualenv(
}
}
}

6 changes: 3 additions & 3 deletions Python_Engine/Compute/Invoke.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -41,4 +41,4 @@ public static PyObject Invoke(PyObject module, string method, IEnumerable<object
return module;
}
}
}
}
3 changes: 2 additions & 1 deletion Python_Engine/Compute/IsValidEnvironmentName.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -50,3 +50,4 @@ public static bool IsValidEnvironmentName(string name)
}
}
}

5 changes: 3 additions & 2 deletions Python_Engine/Compute/Logging.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -51,3 +51,4 @@ public static string LoggingHeader(string text)
}
}
}

3 changes: 2 additions & 1 deletion Python_Engine/Compute/RemoveVirtualenv.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -76,3 +76,4 @@ public static bool RemoveVirtualenv(
}
}
}

5 changes: 2 additions & 3 deletions Python_Engine/Compute/Run.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -71,7 +71,6 @@ await Task.Run(() =>
[Input("startDirectory", "The directory in which the command should be run.")]
[Input("timeoutMinutes", "A number of minutes beyond which this command will timeout.")]
[Output("success", "True if successful and False if not.")]
[PreviousVersion("5.3", "BH.Engine.Python.Compute.RunCommandBool(System.String, System.Boolean, System.String)")]
public static bool RunCommandBool(string command, bool hideWindows = false, string startDirectory = null, double timeoutMinutes = 5)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
Expand Down Expand Up @@ -106,7 +105,6 @@ public static bool RunCommandBool(string command, bool hideWindows = false, stri
[Input("startDirectory", "The directory in which the command should be run.")]
[Input("timeoutMinutes", "A number of minutes beyond which this command will timeout.")]
[Output("stdout", "The StandardOutput from the command that was run. If the process failed, then StandardError will be returned here instead.")]
[PreviousVersion("5.3", "BH.Engine.Python.Compute.RunCommandStdout(System.String, System.Boolean, System.String)")]
public static string RunCommandStdout(string command, bool hideWindows = true, string startDirectory = null, double timeoutMinutes = 5)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
Expand Down Expand Up @@ -230,3 +228,4 @@ public static oM.Base.CustomObject RunPythonScript(this PythonEnvironment python
}
}
}

5 changes: 3 additions & 2 deletions Python_Engine/Convert/ToPython.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -38,3 +38,4 @@ public static bool ToPython<T>(this T[,] input)
}
}
}

3 changes: 2 additions & 1 deletion Python_Engine/Modify/AddQuotesIfRequired.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -45,3 +45,4 @@ public static string AddQuotesIfRequired(this string path)
}
}


5 changes: 3 additions & 2 deletions Python_Engine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -55,5 +55,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.0.0.0")]
[assembly: AssemblyFileVersion("6.1.0.0")]


3 changes: 3 additions & 0 deletions Python_Engine/Python_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<Compile Include="Compute\Logging.cs" />
<Compile Include="Convert\ToPython.cs" />
<Compile Include="Modify\AddQuotesIfRequired.cs" />
<Compile Include="Query\VirtualEnv.cs" />
<Compile Include="Query\VirtualEnvPythonExePath.cs" />
<Compile Include="Query\VirtualEnvDirectory.cs" />
<Compile Include="Query\ToString.cs" />
<Compile Include="Query\CodeDirectory.cs" />
<Compile Include="Query\EnvironmentExists.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Python_Engine/Query/CodeDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -31,11 +31,11 @@ public static partial class Query
{
[Description("The path where any BHoM generated Python code is placed prior to inclusion in a BHoM Python Environment.")]
[Output("The path where any BHoM generated Python code is placed prior to inclusion in a BHoM Python Environment.")]
[PreviousVersion("5.3", "BH.Engine.Python.Query.CodeDirectory(BH.oM.Python.PythonEnvironment)")]
public static string CodeDirectory()
{
return Path.Combine(Query.ExtensionsDirectory(), "PythonCode");
}
}
}


3 changes: 2 additions & 1 deletion Python_Engine/Query/EmbeddableURL.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -80,3 +80,4 @@ public static string EmbeddableURL(this PythonVersion version)
}
}
}

3 changes: 2 additions & 1 deletion Python_Engine/Query/EnvironmentExists.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -45,3 +45,4 @@ public static bool EnvironmentExists(this oM.Python.PythonEnvironment env)
}
}
}

3 changes: 2 additions & 1 deletion Python_Engine/Query/EnvironmentsDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -38,3 +38,4 @@ public static string EnvironmentsDirectory()
}
}


3 changes: 2 additions & 1 deletion Python_Engine/Query/ExtensionsDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -37,3 +37,4 @@ public static string ExtensionsDirectory()
}
}


3 changes: 2 additions & 1 deletion Python_Engine/Query/ToString.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -39,3 +39,4 @@ public static string ToString(this oM.Python.PythonEnvironment env)
}
}


3 changes: 2 additions & 1 deletion Python_Engine/Query/ToolkitName.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -37,3 +37,4 @@ public static string ToolkitName()
}
}


52 changes: 52 additions & 0 deletions Python_Engine/Query/VirtualEnv.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using BH.oM.Python;
using System.ComponentModel;
using System.IO;
using System.Xml.Linq;

namespace BH.Engine.Python
{
public static partial class Query
{
[Description("Get an installed environment without the overhead of attempting to install that environment.")]
[Input("envName","The virtual environment name to request.")]
[Output("The virtual environment, if it exists.")]
public static PythonEnvironment VirtualEnv(string envName)
{
string exePath = Query.VirtualEnvPythonExePath(envName);
if (File.Exists(exePath))
{
return new PythonEnvironment() { Name = envName, Executable = exePath };
}
else
{
BH.Engine.Base.Compute.RecordError($"No environment could be found for {envName}. Use the appropriate InstallPythonEnv to install this environment.");
return null;
}
}
}
}


Loading