Skip to content

Commit

Permalink
Fix CodeInspection test by moving PythonInstaller strings from ToolsU…
Browse files Browse the repository at this point in the history
…IResources into ToolsResources
  • Loading branch information
Nicholas Shulman committed Aug 22, 2024
1 parent b3b08a1 commit b1a342a
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 538 deletions.
59 changes: 29 additions & 30 deletions pwiz_tools/Skyline/Model/Tools/PythonInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using pwiz.Common.Collections;
using pwiz.Common.SystemUtil;
using pwiz.Skyline.Properties;
using pwiz.Skyline.ToolsUI;
using pwiz.Skyline.Util;
using pwiz.Skyline.Util.Extensions;

Expand Down Expand Up @@ -139,45 +138,45 @@ private PythonTask GetPythonTask(PythonTaskName pythonTaskName)
{
case PythonTaskName.download_python_embeddable_package:
var task1 = new PythonTask(DownloadPythonEmbeddablePackage);
task1.InProgressMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Downloading_Python_embeddable_package;
task1.FailureMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_download_Python_embeddable_package;
task1.InProgressMessage = ToolsResources.PythonInstaller_GetPythonTask_Downloading_Python_embeddable_package;
task1.FailureMessage = ToolsResources.PythonInstaller_GetPythonTask_Failed_to_download_Python_embeddable_package;
return task1;
case PythonTaskName.unzip_python_embeddable_package:
var task2 = new PythonTask(UnzipPythonEmbeddablePackage);
task2.InProgressMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Unzipping_Python_embeddable_package;
task2.FailureMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_unzip_Python_embeddable_package;
task2.InProgressMessage = ToolsResources.PythonInstaller_GetPythonTask_Unzipping_Python_embeddable_package;
task2.FailureMessage = ToolsResources.PythonInstaller_GetPythonTask_Failed_to_unzip_Python_embeddable_package;
return task2;
case PythonTaskName.enable_search_path_in_python_embeddable_package:
var task3 = new PythonTask(EnableSearchPathInPythonEmbeddablePackage);
task3.InProgressMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Enabling_search_path_in_Python_embeddable_package;
task3.FailureMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_enable_search_path_in_Python_embeddable_package;
task3.InProgressMessage = ToolsResources.PythonInstaller_GetPythonTask_Enabling_search_path_in_Python_embeddable_package;
task3.FailureMessage = ToolsResources.PythonInstaller_GetPythonTask_Failed_to_enable_search_path_in_Python_embeddable_package;
return task3;
case PythonTaskName.download_getpip_script:
var task4 = new PythonTask(DownloadGetPipScript);
task4.InProgressMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Downloading_the_get_pip_py_script;
task4.FailureMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_download_the_get_pip_py_script;
task4.InProgressMessage = ToolsResources.PythonInstaller_GetPythonTask_Downloading_the_get_pip_py_script;
task4.FailureMessage = ToolsResources.PythonInstaller_GetPythonTask_Failed_to_download_the_get_pip_py_script;
return task4;
case PythonTaskName.run_getpip_script:
var task5 = new PythonTask(RunGetPipScript);
task5.InProgressMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Running_the_get_pip_py_script;
task5.FailureMessage = ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_run_the_get_pip_py_script;
task5.InProgressMessage = ToolsResources.PythonInstaller_GetPythonTask_Running_the_get_pip_py_script;
task5.FailureMessage = ToolsResources.PythonInstaller_GetPythonTask_Failed_to_run_the_get_pip_py_script;
return task5;
case PythonTaskName.pip_install_virtualenv:
var virtualEnvPackage = new PythonPackage { Name = VIRTUALENV, Version = null };
var task6 = new PythonTask(() => PipInstall(BasePythonExecutablePath, new[] { virtualEnvPackage }));
task6.InProgressMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Running_pip_install__0_, VIRTUALENV);
task6.FailureMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_run_pip_install__0_, VIRTUALENV);
task6.InProgressMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Running_pip_install__0_, VIRTUALENV);
task6.FailureMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Failed_to_run_pip_install__0_, VIRTUALENV);
return task6;
case PythonTaskName.create_virtual_environment:
var task7 = new PythonTask(() => RunPythonModule(
BasePythonExecutablePath, PythonVersionDir, VIRTUALENV, new[] { VirtualEnvironmentName }));
task7.InProgressMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Creating_virtual_environment__0_, VirtualEnvironmentName);
task7.FailureMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_create_virtual_environment__0_, VirtualEnvironmentName);
task7.InProgressMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Creating_virtual_environment__0_, VirtualEnvironmentName);
task7.FailureMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Failed_to_create_virtual_environment__0_, VirtualEnvironmentName);
return task7;
case PythonTaskName.pip_install_packages:
var task8 = new PythonTask(() => PipInstall(VirtualEnvironmentPythonExecutablePath, PythonPackages));
task8.InProgressMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Installing_Python_packages_in_virtual_environment__0_, VirtualEnvironmentName);
task8.FailureMessage = string.Format(ToolsUIResources.PythonInstaller_GetPythonTask_Failed_to_install_Python_packages_in_virtual_environment__0_, VirtualEnvironmentName);
task8.InProgressMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Installing_Python_packages_in_virtual_environment__0_, VirtualEnvironmentName);
task8.FailureMessage = string.Format(ToolsResources.PythonInstaller_GetPythonTask_Failed_to_install_Python_packages_in_virtual_environment__0_, VirtualEnvironmentName);
return task8;
default:
throw new PythonInstallerUnsupportedTaskNameException(pythonTaskName);
Expand All @@ -189,7 +188,7 @@ private void DownloadPythonEmbeddablePackage(IProgressMonitor progressMonitor)
using var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(progressMonitor, 1);
if (!webClient.DownloadFileAsync(PythonEmbeddablePackageUri, PythonEmbeddablePackageDownloadPath, out var downloadException))
throw new ToolExecutionException(
ToolsUIResources.PythonInstaller_Download_failed__Check_your_network_connection_or_contact_Skyline_team_for_help_, downloadException);
ToolsResources.PythonInstaller_Download_failed__Check_your_network_connection_or_contact_Skyline_team_for_help_, downloadException);
}

private void UnzipPythonEmbeddablePackage(IProgressMonitor progressMonitor)
Expand All @@ -201,7 +200,7 @@ private void UnzipPythonEmbeddablePackage(IProgressMonitor progressMonitor)
private void EnableSearchPathInPythonEmbeddablePackage()
{
var files = Directory.GetFiles(PythonEmbeddablePackageExtractDir, "python*._pth");
Assume.IsTrue(files.Length == 1, ToolsUIResources.PythonInstaller_EnableSearchPathInPythonEmbeddablePackage_Found_0_or_more_than_one_files_with__pth_extension__this_is_unexpected);
Assume.IsTrue(files.Length == 1, ToolsResources.PythonInstaller_EnableSearchPathInPythonEmbeddablePackage_Found_0_or_more_than_one_files_with__pth_extension__this_is_unexpected);
var oldFilePath = files[0];
var newFilePath = Path.ChangeExtension(oldFilePath, @".pth");
File.Move(oldFilePath, newFilePath);
Expand All @@ -212,7 +211,7 @@ private void DownloadGetPipScript(IProgressMonitor progressMonitor)
if (!webClient.DownloadFileAsync(GetPipScriptDownloadUri, GetPipScriptDownloadPath, out var downloadException))
{
throw new ToolExecutionException(
ToolsUIResources.PythonInstaller_Download_failed__Check_your_network_connection_or_contact_Skyline_team_for_help_, downloadException);
ToolsResources.PythonInstaller_Download_failed__Check_your_network_connection_or_contact_Skyline_team_for_help_, downloadException);
}
}

Expand All @@ -222,11 +221,11 @@ private void RunGetPipScript(IProgressMonitor progressMonitor)
cmdBuilder.Append(BasePythonExecutablePath)
.Append(SPACE)
.Append(GetPipScriptDownloadPath);
var cmd = string.Format(ToolsUIResources.PythonInstaller__0__Running_command____1____2__, ECHO, cmdBuilder, CMD_PROCEEDING_SYMBOL);
var cmd = string.Format(ToolsResources.PythonInstaller__0__Running_command____1____2__, ECHO, cmdBuilder, CMD_PROCEEDING_SYMBOL);
cmd += cmdBuilder;
var pipedProcessRunner = TestPipeSkylineProcessRunner ?? new SkylineProcessRunnerWrapper();
if (pipedProcessRunner.RunProcess(cmd, false, Writer) != 0)
throw new ToolExecutionException(string.Format(ToolsUIResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
throw new ToolExecutionException(string.Format(ToolsResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
}

private void PipInstall(string pythonExecutablePath, IEnumerable<PythonPackage> packages)
Expand All @@ -246,12 +245,12 @@ private void PipInstall(string pythonExecutablePath, IEnumerable<PythonPackage>
cmdBuilder.Append(arg)
.Append(TextUtil.SEPARATOR_SPACE);
}
var cmd = string.Format(ToolsUIResources.PythonInstaller__0__Running_command____1____2__, ECHO, cmdBuilder, CMD_PROCEEDING_SYMBOL);
cmd += string.Format(ToolsUIResources.PythonInstaller_PipInstall__0__This_sometimes_could_take_3_5_minutes__Please_be_patient___1__, ECHO, CMD_PROCEEDING_SYMBOL);
var cmd = string.Format(ToolsResources.PythonInstaller__0__Running_command____1____2__, ECHO, cmdBuilder, CMD_PROCEEDING_SYMBOL);
cmd += string.Format(ToolsResources.PythonInstaller_PipInstall__0__This_sometimes_could_take_3_5_minutes__Please_be_patient___1__, ECHO, CMD_PROCEEDING_SYMBOL);
cmd += cmdBuilder;
var pipedProcessRunner = TestPipeSkylineProcessRunner ?? new SkylineProcessRunnerWrapper();
if (pipedProcessRunner.RunProcess(cmd, false, Writer) != 0)
throw new ToolExecutionException(string.Format(ToolsUIResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
throw new ToolExecutionException(string.Format(ToolsResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
}

private void RunPythonModule(string pythonExecutablePath, string changeDir, string moduleName, string[] arguments)
Expand All @@ -277,11 +276,11 @@ private void RunPythonModule(string pythonExecutablePath, string changeDir, stri
cmdBuilder.Append(argument)
.Append(SPACE);
}
var cmd = string.Format(ToolsUIResources.PythonInstaller__0__Running_command____1____2__, ECHO, GetEscapedCmdString(cmdBuilder.ToString()), CMD_PROCEEDING_SYMBOL);
var cmd = string.Format(ToolsResources.PythonInstaller__0__Running_command____1____2__, ECHO, GetEscapedCmdString(cmdBuilder.ToString()), CMD_PROCEEDING_SYMBOL);
cmd += cmdBuilder;
var pipedProcessRunner = TestPipeSkylineProcessRunner ?? new SkylineProcessRunnerWrapper();
if (pipedProcessRunner.RunProcess(cmd, false, Writer) != 0)
throw new ToolExecutionException(string.Format(ToolsUIResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
throw new ToolExecutionException(string.Format(ToolsResources.PythonInstaller_Failed_to_execute_command____0__, cmdBuilder));
}

private string GetEscapedCmdString(string cmdString)
Expand Down Expand Up @@ -600,7 +599,7 @@ private bool ValidatePipInstallPackages()
foreach (var line in lines)
{
var words = line.Split(EQUALS.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
Assume.IsTrue(words.Length.Equals(2), string.Format(ToolsUIResources.PythonInstallerTaskValidator_ValidatePipInstallPackages_Failed_to_parse_package_name_and_version_from_entry___0__, line));
Assume.IsTrue(words.Length.Equals(2), string.Format(ToolsResources.PythonInstallerTaskValidator_ValidatePipInstallPackages_Failed_to_parse_package_name_and_version_from_entry___0__, line));
packageToVersionMap.Add(words[0], words[1]);
}

Expand Down Expand Up @@ -670,13 +669,13 @@ public PythonInstallerException(string message, Exception inner = null) : base(m
internal class PythonInstallerUnsupportedTaskException : PythonInstallerException
{
public PythonInstallerUnsupportedTaskException(PythonTask pythonTask)
: base(string.Format(ToolsUIResources.PythonInstallerUnsupportedTaskException_Task_with_action_type__0__is_not_supported_by_PythonInstaller_yet, pythonTask.ActionType)) { }
: base(string.Format(ToolsResources.PythonInstallerUnsupportedTaskException_Task_with_action_type__0__is_not_supported_by_PythonInstaller_yet, pythonTask.ActionType)) { }
}

internal class PythonInstallerUnsupportedTaskNameException : PythonInstallerException
{
public PythonInstallerUnsupportedTaskNameException(PythonTaskName pythonTaskName)
: base(string.Format(ToolsUIResources.PythonInstallerUnsupportedTaskNameException_Task_with_task_name__0__is_not_supported_by_PythonInstaller_yet, pythonTaskName)) { }
: base(string.Format(ToolsResources.PythonInstallerUnsupportedTaskNameException_Task_with_task_name__0__is_not_supported_by_PythonInstaller_yet, pythonTaskName)) { }
}
}

Loading

0 comments on commit b1a342a

Please sign in to comment.