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

Ensure Pollination is installed to correct version #129

Closed
tg359 opened this issue Nov 10, 2023 · 0 comments · Fixed by #133
Closed

Ensure Pollination is installed to correct version #129

tg359 opened this issue Nov 10, 2023 · 0 comments · Fixed by #133
Assignees
Labels
type:feature New capability or enhancement

Comments

@tg359
Copy link
Contributor

tg359 commented Nov 10, 2023

Description:

Prior to running the environment installer or any other code within the toolkit, a check should be made to ensure that Pollination is installed, and the version installed is the one that the code has been tested against.

Not sure why I didn't do this sooner, but it would look something like this:

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)
        {
            // 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;
                }
            }

            // 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($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion}).");
                    return false;
                }
            }

            return true;
        }
    }
}
@tg359 tg359 added the type:feature New capability or enhancement label Nov 10, 2023
@tg359 tg359 self-assigned this Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New capability or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant