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 additional Pollination version check #133

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public static PythonEnvironment InstallPythonEnv_LBT(bool run = false, bool rein
{
// check if referenced Python is installed
string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe";
if (!File.Exists(referencedExecutable))

// NOTE - The version number below relates to the ProductVersion field of the "C:\Program Files\ladybug_tools\uninstall.exe" file, and doesn't necessarily reflect the version of the installer/uninstaller
// Pollination 1.35.14 has an uninstaller ProductVersion of 1.38.104
if (!Query.IsPollinationInstalled(targetPollinationVersion: "1.38.104", includeBuildNumber: false))
{
Base.Compute.RecordError($"Could not find referenced python executable at {referencedExecutable}. Please install Pollination try again.");
return null;
}

Expand Down
78 changes: 78 additions & 0 deletions LadybugTools_Engine/Query/IsPollinationInstalled.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.LadybugTools;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using BH.oM.Python;
using System.IO;
using System;
using System.Diagnostics;

namespace BH.Engine.LadybugTools
{
public static partial class Query
{
[Description("Return True if Pollination is installed to the currently supported version.")]
[Input("targetPollinationVersion", "The target Pollination build BHoM currently supports.")]
[Input("includeBuildNumber", "If true, the build number will be included in the comparison.")]
[Output("bool", "True if Pollination is installed to the currently supported version.")]
public static bool IsPollinationInstalled(string targetPollinationVersion, bool includeBuildNumber)
tg359 marked this conversation as resolved.
Show resolved Hide resolved
{
// check if referenced Python is installed
string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe";
if (!File.Exists(referencedExecutable))
{
Base.Compute.RecordError($"Could not find referenced python executable at {referencedExecutable}. Please install Pollination version {targetPollinationVersion} and try again.");
return false;
}

// obtain version of pollination installed
string referencedUninstaller = @"C:\Program Files\ladybug_tools\uninstall.exe";
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(referencedUninstaller);
if (includeBuildNumber)
{
if (versionInfo.ProductVersion != targetPollinationVersion)
{
Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion}).");
return false;
}
}
tg359 marked this conversation as resolved.
Show resolved Hide resolved

// check that version matches the target version
int major = int.Parse(targetPollinationVersion.Split('.')[0]);
int minor = int.Parse(targetPollinationVersion.Split('.')[1]);
if (versionInfo.ProductMajorPart != major || versionInfo.ProductMinorPart != minor)
{
if (versionInfo.ProductVersion != targetPollinationVersion)
{
Base.Compute.RecordError($"Pollination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion}).");
return false;
}
}

return true;
}
}
}