From 46abe886d214b34d22d9cb191319120db58c10a9 Mon Sep 17 00:00:00 2001 From: Lu Zhen Date: Mon, 18 Mar 2024 17:02:29 +0800 Subject: [PATCH] fix: open python project crashed in v23 Log: Change-Id: I0e64493e703cf22c1d48c1e7f36369f3ece3d855 --- src/common/util/environment.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/common/util/environment.cpp b/src/common/util/environment.cpp index 3a9d39a90..9f836bb33 100644 --- a/src/common/util/environment.cpp +++ b/src/common/util/environment.cpp @@ -32,10 +32,10 @@ Version completion(Category category, Kit kit, const Version &version) program += QString::number(version.major.value()); } ProcessUtil::execute(program, {"-V"}, [&](const QByteArray &data){ - QRegularExpression regExp {"Python\\s(?<" + RK_Major +">[0-9])" - + "\\.(?<"+ RK_Minor +">[0-9])" - + "\\.(?<"+ RK_Revision +">[0-9])" - + "(\\.(?<"+ RK_Build + ">[0-9]))?"}; + QRegularExpression regExp {"Python\\s(?<" + RK_Major +">[0-9]+)" + + "\\.(?<"+ RK_Minor +">[0-9]+)" + + "\\.(?<"+ RK_Revision +">[0-9]+)" + + "(\\.(?<"+ RK_Build + ">[0-9]+))?"}; auto matchs = regExp.match(data); if (matchs.hasMatch()) { auto major = matchs.captured(RK_Major); @@ -73,14 +73,16 @@ Program search(Category category, Kit kit, const Version &version) if (executeVersion.major) { program + QString::number(executeVersion.major.value()); } - ret.pkgsPath = QDir::homePath() + QDir::separator() - + ".local" + QDir::separator() - + "lib" + QDir::separator() - + QString("python") + QString::number(executeVersion.major.value()) - + "." - + QString::number(executeVersion.minor.value()) - + QDir::separator() - + "site-packages"; + + if (executeVersion.major.has_value() && executeVersion.minor.has_value()) + ret.pkgsPath = QDir::homePath() + QDir::separator() + + ".local" + QDir::separator() + + "lib" + QDir::separator() + + QString("python") + QString::number(executeVersion.major.value()) + + "." + + QString::number(executeVersion.minor.value()) + + QDir::separator() + + "site-packages"; } } }