Skip to content

Commit 2ee1cfc

Browse files
author
Fraser Greenroyd
authored
7.0 Deployment (#129)
2 parents f60a02c + 53d2762 commit 2ee1cfc

17 files changed

+143
-337
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>BHoM.Interop.Python</id>
5+
<version></version>
6+
<authors>BHoM</authors>
7+
<projectUrl>https://github.com/BHoM/Python_Toolkit</projectUrl>
8+
<license type="file">licence.txt</license>
9+
<icon>icon.png</icon>
10+
<readme>readme.md</readme>
11+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12+
<description>Interact with Python via BHoM</description>
13+
<releaseNotes></releaseNotes>
14+
<copyright></copyright>
15+
<tags>BHoM engine aec Python</tags>
16+
<title></title>
17+
<dependencies>
18+
<group targetFramework="netstandard2.0">
19+
<dependency id="NETStandard.Library" version="2.0.3" />
20+
</group>
21+
</dependencies>
22+
</metadata>
23+
<files>
24+
<file src="licence/licence.txt" target="" />
25+
<file src="images/icon.png" target="" />
26+
<file src="docs/readme.md" target="" />
27+
</files>
28+
</package>

Python_Engine/Compute/BasePythonEnvironment.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ public static partial class Compute
3535
{
3636
[Description("Retrieve or reinstall the base Python Environment for BHoM workflows.")]
3737
[Input("reload", "Reload the base Python environment rather than recreating it, if it already exists.")]
38+
[Input("run", "Start the installation/retrieval of the BHoM Base Python Environment.")]
3839
[Output("env", "The base Python Environment for all BHoM workflows.")]
39-
[PreviousVersion("6.3", "BH.Engine.Python.Compute.InstallBasePythonEnvironment(System.Boolean)")]
40+
[PreviousVersion("7.0", "BH.Engine.Python.Compute.BasePythonEnvironment(System.Boolean)")]
4041
public static PythonEnvironment BasePythonEnvironment(
41-
bool reload = true
42+
bool reload = true,
43+
bool run = false
4244
)
4345
{
46+
if (!run)
47+
{
48+
return null;
49+
}
50+
4451
if (!Directory.Exists(Query.DirectoryEnvironments()))
4552
{
4653
// create PythonEnvironments directory if it doesnt already exist

Python_Engine/Compute/Download.cs

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public static string DownloadFile(
9191
[Input("version", "A Python version.")]
9292
[Input("name", "Name of target exe file.")]
9393
[Output("executablePath", "The path of the executable for the downloaded Python.")]
94-
[PreviousVersion("6.3", "BH.Engine.Python.Compute.DownloadPython(BH.oM.Python.Enums.PythonVersion)")]
9594
public static string DownloadPython(this PythonVersion version, string name = null)
9695
{
9796
string url = version.EmbeddableURL();

Python_Engine/Compute/InstallPackage.cs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
using System.ComponentModel;
2828
using System.Diagnostics;
2929
using System.IO;
30-
using System.Windows.Forms;
3130
using System.Xml.Linq;
3231

3332
namespace BH.Engine.Python

Python_Engine/Compute/VirtualEnvironment.cs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using BH.oM.Base.Attributes;
2424
using BH.oM.Python;
2525
using BH.oM.Python.Enums;
26-
using Microsoft.SqlServer.Server;
2726
using System.Collections.Generic;
2827
using System.ComponentModel;
2928
using System.Diagnostics;

Python_Engine/Properties/AssemblyInfo.cs

-60
This file was deleted.

Python_Engine/Python_Engine.csproj

+24-102
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{4A6B3805-35EE-4278-9701-CC1E0CD641F9}</ProjectGuid>
8-
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<AssemblyVersion>7.0.0.0</AssemblyVersion>
6+
<Description>https://github.com/BHoM/Python_Toolkit</Description>
7+
<Version>6.0.0</Version>
8+
<Authors>BHoM</Authors>
9+
<Copyright>Copyright © https://github.com/BHoM</Copyright>
1010
<RootNamespace>BH.Engine.Python</RootNamespace>
11-
<AssemblyName>Python_Engine</AssemblyName>
12-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<Deterministic>true</Deterministic>
15-
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<DebugSymbols>true</DebugSymbols>
18-
<DebugType>full</DebugType>
19-
<Optimize>false</Optimize>
20-
<OutputPath>..\Build\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
22-
<ErrorReport>prompt</ErrorReport>
23-
<WarningLevel>0</WarningLevel>
24-
</PropertyGroup>
25-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<DebugType>pdbonly</DebugType>
27-
<Optimize>true</Optimize>
11+
<FileVersion>7.0.0.0</FileVersion>
2812
<OutputPath>..\Build\</OutputPath>
29-
<DefineConstants>TRACE</DefineConstants>
30-
<ErrorReport>prompt</ErrorReport>
31-
<WarningLevel>4</WarningLevel>
3213
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\Python_oM\Python_oM.csproj" />
17+
</ItemGroup>
18+
3319
<ItemGroup>
3420
<Reference Include="BHoM">
3521
<SpecificVersion>False</SpecificVersion>
@@ -41,10 +27,6 @@
4127
<Private>False</Private>
4228
<SpecificVersion>False</SpecificVersion>
4329
</Reference>
44-
<Reference Include="Python.Runtime, Version=3.7.4.0, Culture=neutral, processorArchitecture=MSIL">
45-
<SpecificVersion>False</SpecificVersion>
46-
<HintPath>..\libs\Python.Runtime.dll</HintPath>
47-
</Reference>
4830
<Reference Include="Reflection_Engine">
4931
<SpecificVersion>False</SpecificVersion>
5032
<HintPath>$(ProgramData)\BHoM\Assemblies\Reflection_Engine.dll</HintPath>
@@ -55,74 +37,14 @@
5537
<HintPath>$(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll</HintPath>
5638
<Private>False</Private>
5739
</Reference>
58-
<Reference Include="System" />
59-
<Reference Include="System.Core" />
60-
<Reference Include="System.IO.Compression.FileSystem" />
61-
<Reference Include="System.Windows.Forms" />
62-
<Reference Include="System.Xml.Linq" />
63-
<Reference Include="System.Data.DataSetExtensions" />
64-
<Reference Include="Microsoft.CSharp" />
65-
<Reference Include="System.Data" />
66-
<Reference Include="System.Net.Http" />
67-
<Reference Include="System.Xml" />
68-
</ItemGroup>
69-
<ItemGroup>
70-
<Compile Include="Compute\Run.cs" />
71-
<Compile Include="Compute\BasePythonEnvironment.cs" />
72-
<Compile Include="Compute\Remove.cs" />
73-
<Compile Include="Compute\InstallPackage.cs" />
74-
<Compile Include="Compute\RequirementsTxt.cs" />
75-
<Compile Include="Compute\VirtualEnvironment.cs" />
76-
<Compile Include="Compute\UnzipFile.cs" />
77-
<Compile Include="Compute\Download.cs" />
78-
<Compile Include="Convert\ToPython.cs" />
79-
<Compile Include="Modify\AddQuotesIfRequired.cs" />
80-
<Compile Include="Query\VirtualEnvironment.cs" />
81-
<Compile Include="Query\Version.cs" />
82-
<Compile Include="Query\Directory.cs" />
83-
<Compile Include="Query\IsValidEnvironmentName.cs" />
84-
<Compile Include="Query\EmbeddableURL.cs" />
85-
<Compile Include="Query\ToolkitName.cs" />
86-
<Compile Include="Properties\AssemblyInfo.cs" />
87-
</ItemGroup>
88-
<ItemGroup>
89-
<None Include="packages.config" />
90-
<None Include="Versioning_53.json" />
9140
</ItemGroup>
92-
<ItemGroup>
93-
<ProjectReference Include="..\Python_oM\Python_oM.csproj">
94-
<Project>{3BF9F725-F1CA-432F-A549-557324CAFB91}</Project>
95-
<Name>Python_oM</Name>
96-
<Private>False</Private>
97-
</ProjectReference>
98-
</ItemGroup>
99-
<ItemGroup>
100-
<Folder Include="Create\" />
101-
</ItemGroup>
102-
<ItemGroup>
103-
<Content Include="Python\src\python_toolkit\bhomutil\__init__.py" />
104-
<Content Include="Python\src\python_toolkit\__init__.py" />
105-
<None Include="Python\README.md" />
106-
<Content Include="Python\setup.py" />
107-
<Content Include="Python\requirements.txt" />
108-
</ItemGroup>
109-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
110-
<PropertyGroup>
111-
<PostBuildEvent>
112-
xcopy "$(TargetDir)$(TargetFileName)" "C:\\ProgramData\\BHoM\\Assemblies" /Y
113-
xcopy "$(TargetDir)Python.Runtime.dll" "C:\\ProgramData\\BHoM\\Assemblies" /Y
114-
</PostBuildEvent>
115-
</PropertyGroup>
116-
<PropertyGroup>
117-
<PreBuildEvent>
118-
if not exist "C:\ProgramData\BHoM\Extensions\PythonEnvironments" mkdir "C:\ProgramData\BHoM\Extensions\PythonEnvironments"
119-
if not exist "C:\ProgramData\BHoM\Extensions\PythonCode" mkdir "C:\ProgramData\BHoM\Extensions\PythonCode"
120-
121-
if exist "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" rmdir "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" /S /Q
122-
mkdir "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)"
123-
124-
robocopy "$(ProjectDir)Python" "C:\ProgramData\BHoM\Extensions\PythonCode\$(SolutionName)" /mir /xf "*.pyc" "*.ipynb" /xd "__*__" ".*" &gt; output.log
125-
del output.log
126-
</PreBuildEvent>
127-
</PropertyGroup>
128-
</Project>
41+
42+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
43+
<Exec Command="xcopy $(TargetDir)$(TargetFileName) $(ProgramData)\BHoM\Assemblies /Y" />
44+
</Target>
45+
46+
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
47+
<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" />
48+
</Target>
49+
50+
</Project>

Python_Engine/Query/Directory.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,38 @@ public static partial class Query
3333
[Output("The location where BHoM extensions reside.")]
3434
public static string DirectoryExtensions()
3535
{
36-
return @"C:\ProgramData\BHoM\Extensions";
36+
return Path.Combine(System.IO.Directory.GetParent(BH.Engine.Base.Query.BHoMFolder()).FullName, "Extensions");
3737
}
3838

3939
[Description("The location where any BHoM-related Python kernels reside.")]
4040
[Output("The location where any BHoM-related Python kernels reside.")]
4141
public static string DirectoryKernels()
4242
{
43-
return @"C:\ProgramData\jupyter\kernels";
43+
44+
string dir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "jupyter", "kernels");
45+
if (!Directory.Exists(dir))
46+
Directory.CreateDirectory(dir);
47+
return dir;
4448
}
4549

4650
[Description("The location where any BHoM-related Python code resides.")]
4751
[Output("The location where any BHoM-related Python code resides.")]
4852
public static string DirectoryCode()
4953
{
50-
return Path.Combine(Query.DirectoryExtensions(), "PythonCode");
54+
string dir = Path.Combine(Query.DirectoryExtensions(), "PythonCode");
55+
if (!Directory.Exists(dir))
56+
Directory.CreateDirectory(dir);
57+
return dir;
5158
}
5259

5360
[Description("The location where any BHoM-related Python environment (or virtualenv) resides.")]
5461
[Output("The location where any BHoM-related Python environment (or virtualenv) resides.")]
5562
public static string DirectoryEnvironments()
5663
{
57-
return Path.Combine(Query.DirectoryExtensions(), "PythonEnvironments");
64+
string dir = Path.Combine(Query.DirectoryExtensions(), "PythonEnvironments");
65+
if (!Directory.Exists(dir))
66+
Directory.CreateDirectory(dir);
67+
return dir;
5868
}
5969

6070
[Description("The location where the base Python environment exists.")]

Python_Engine/Query/IsValidEnvironmentName.cs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public static partial class Query
3737
[Description("Check whether a string is valid as BHoM Python Environment name.")]
3838
[Input("name", "The name given to the BHoM Python Environment.")]
3939
[Output("valid", "True if valid, False if not.")]
40-
[PreviousVersion("6.3","BH.Engine.Python.Compute.IsValidEnvironmentName(System.String)")]
4140
public static bool IsValidEnvironmentName(string name)
4241
{
4342
List<char> invalidChars = new List<char>() { ' ' };

Python_Engine/Query/Version.cs

+21-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public static partial class Query
3636
[Output("version", "Python version of the requested Python executable.")]
3737
public static PythonVersion Version(string pythonExecutable)
3838
{
39+
if (!File.Exists(pythonExecutable))
40+
{
41+
return PythonVersion.Undefined;
42+
}
43+
3944
Process process = new Process()
4045
{
4146
StartInfo = new ProcessStartInfo()
@@ -47,16 +52,25 @@ public static PythonVersion Version(string pythonExecutable)
4752
UseShellExecute = false,
4853
}
4954
};
50-
string versionString;
51-
using (Process p = Process.Start(process.StartInfo))
55+
56+
try
57+
{
58+
string versionString;
59+
using (Process p = Process.Start(process.StartInfo))
60+
{
61+
p.WaitForExit();
62+
if (p.ExitCode != 0)
63+
BH.Engine.Base.Compute.RecordError($"Error getting Python version.\n{p.StandardError.ReadToEnd()}");
64+
versionString = p.StandardOutput.ReadToEnd().TrimEnd();
65+
}
66+
67+
return (PythonVersion)Enum.Parse(typeof(PythonVersion), "v" + versionString.Replace("Python ", "").Replace(".", "_"));
68+
}
69+
catch
5270
{
53-
p.WaitForExit();
54-
if (p.ExitCode != 0)
55-
BH.Engine.Base.Compute.RecordError($"Error getting Python version.\n{p.StandardError.ReadToEnd()}");
56-
versionString = p.StandardOutput.ReadToEnd().TrimEnd();
71+
return PythonVersion.Undefined;
5772
}
5873

59-
return (PythonVersion) Enum.Parse(typeof(PythonVersion), "v" + versionString.Replace("Python ", "").Replace(".", "_"));
6074
}
6175
}
6276
}

0 commit comments

Comments
 (0)