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

Added version check to existing environment query #126

Merged
Merged
Show file tree
Hide file tree
Changes from all 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/Python_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;C:\\ProgramData\\BHoM\\Assemblies&quot; /Y" />
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
</Target>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="if not exist &quot;C:\ProgramData\BHoM\Extensions\PythonEnvironments&quot; mkdir &quot;C:\ProgramData\BHoM\Extensions\PythonEnvironments&quot;&#xD;&#xA;if not exist &quot;C:\ProgramData\BHoM\Extensions\PythonCode&quot; mkdir &quot;C:\ProgramData\BHoM\Extensions\PythonCode&quot;&#xD;&#xA; &#xD;&#xA;if exist &quot;C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)&quot; rmdir &quot;C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)&quot; /S /Q&#xD;&#xA;mkdir &quot;C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)&quot;&#xD;&#xA; &#xD;&#xA;robocopy &quot;$(ProjectDir)Python&quot; &quot;C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)&quot; /mir /xf &quot;*.pyc&quot; &quot;*.ipynb&quot; /xd &quot;__*__&quot; &quot;.*&quot; &amp;gt; output.log&#xD;&#xA;del output.log" />
<Exec Command="if not exist $(ProgramData)\BHoM\Extensions\PythonEnvironments mkdir $(ProgramData)\BHoM\Extensions\PythonEnvironments&#xD;&#xA;if not exist $(ProgramData)\BHoM\Extensions\PythonCode mkdir $(ProgramData)\BHoM\Extensions\PythonCode&#xD;&#xA; &#xD;&#xA;if exist $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) rmdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /S /Q&#xD;&#xA;mkdir $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName)&#xD;&#xA; &#xD;&#xA;robocopy $(ProjectDir)Python $(ProgramData)\BHoM\Extensions\PythonCode\$(SolutionName) /mir /xf &quot;*.pyc&quot; &quot;*.ipynb&quot; /xd &quot;__*__&quot; &quot;.*&quot; &gt; output.log&#xD;&#xA;del output.log" />
</Target>

</Project>
18 changes: 14 additions & 4 deletions Python_Engine/Query/Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,38 @@ public static partial class Query
[Output("The location where BHoM extensions reside.")]
public static string DirectoryExtensions()
{
return @"C:\ProgramData\BHoM\Extensions";
return Path.Combine(System.IO.Directory.GetParent(BH.Engine.Base.Query.BHoMFolder()).FullName, "Extensions");
}

[Description("The location where any BHoM-related Python kernels reside.")]
[Output("The location where any BHoM-related Python kernels reside.")]
public static string DirectoryKernels()
{
return @"C:\ProgramData\jupyter\kernels";

string dir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "jupyter", "kernels");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
return dir;
}

[Description("The location where any BHoM-related Python code resides.")]
[Output("The location where any BHoM-related Python code resides.")]
public static string DirectoryCode()
{
return Path.Combine(Query.DirectoryExtensions(), "PythonCode");
string dir = Path.Combine(Query.DirectoryExtensions(), "PythonCode");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
return dir;
}

[Description("The location where any BHoM-related Python environment (or virtualenv) resides.")]
[Output("The location where any BHoM-related Python environment (or virtualenv) resides.")]
public static string DirectoryEnvironments()
{
return Path.Combine(Query.DirectoryExtensions(), "PythonEnvironments");
string dir = Path.Combine(Query.DirectoryExtensions(), "PythonEnvironments");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
return dir;
}

[Description("The location where the base Python environment exists.")]
Expand Down
14 changes: 12 additions & 2 deletions Python_Engine/Query/VirtualEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,20 @@ public static partial class Query
{
[Description("Check whether a named BHoM Python virtual environment exists.")]
[Input("envName", "The name given to the BHoM Python Environment.")]
[Input("pythonVersion", "The version to check against.")]
[Output("exists", "True if exists, False if not.")]
public static bool VirtualEnvironmentExists(string envName)
[PreviousVersion("7.0", "BH.Engine.Python.Query.VirtualEnvironmentExists(System.String)")]
public static bool VirtualEnvironmentExists(string envName, PythonVersion pythonVersion = PythonVersion.Undefined)
FraserGreenroyd marked this conversation as resolved.
Show resolved Hide resolved
{
return Directory.Exists(VirtualEnvironmentDirectory(envName)) && File.Exists(VirtualEnvironmentExecutable(envName)) && Directory.Exists(VirtualEnvironmentKernel(envName));
bool directoryExists = Directory.Exists(VirtualEnvironmentDirectory(envName));
bool executableExists = File.Exists(VirtualEnvironmentExecutable(envName));
bool kernelExists = Directory.Exists(VirtualEnvironmentKernel(envName));
bool versionMatches = Version(VirtualEnvironmentExecutable(envName)) == pythonVersion;

if (pythonVersion == PythonVersion.Undefined)
return directoryExists && executableExists && kernelExists;

return directoryExists && executableExists && kernelExists && versionMatches;
}

[Description("Get the path to the named BHoM Python virtual environment kernel.")]
Expand Down
2 changes: 1 addition & 1 deletion Python_oM/Python_oM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;C:\ProgramData\BHoM\Assemblies&quot; /Y" />
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
</Target>

</Project>