forked from qt-creator/qt-creator
Python: Use FilePath::searchInPath instead of Environment::findInPath
That's the last remaining users. Change-Id: I14ce380b9c96b2197e478600a46ca725ed1acfbf Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -653,17 +653,15 @@ static void addPythonsFromRegistry(QList<Interpreter> &pythons)
|
|||||||
|
|
||||||
static void addPythonsFromPath(QList<Interpreter> &pythons)
|
static void addPythonsFromPath(QList<Interpreter> &pythons)
|
||||||
{
|
{
|
||||||
const auto &env = Environment::systemEnvironment();
|
|
||||||
|
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
for (const FilePath &executable : env.findAllInPath("python")) {
|
for (const FilePath &executable : FilePath("python").searchAllInPath()) {
|
||||||
// Windows creates empty redirector files that may interfere
|
// Windows creates empty redirector files that may interfere
|
||||||
if (executable.toFileInfo().size() == 0)
|
if (executable.toFileInfo().size() == 0)
|
||||||
continue;
|
continue;
|
||||||
if (executable.exists() && !alreadyRegistered(pythons, executable))
|
if (executable.exists() && !alreadyRegistered(pythons, executable))
|
||||||
pythons << createInterpreter(executable, "Python from Path");
|
pythons << createInterpreter(executable, "Python from Path");
|
||||||
}
|
}
|
||||||
for (const FilePath &executable : env.findAllInPath("pythonw")) {
|
for (const FilePath &executable : FilePath("pythonw").searchAllInPath()) {
|
||||||
if (executable.exists() && !alreadyRegistered(pythons, executable))
|
if (executable.exists() && !alreadyRegistered(pythons, executable))
|
||||||
pythons << createInterpreter(executable, "Python from Path", "(Windowed)");
|
pythons << createInterpreter(executable, "Python from Path", "(Windowed)");
|
||||||
}
|
}
|
||||||
@@ -672,7 +670,8 @@ static void addPythonsFromPath(QList<Interpreter> &pythons)
|
|||||||
"python[1-9].[0-9]",
|
"python[1-9].[0-9]",
|
||||||
"python[1-9].[1-9][0-9]",
|
"python[1-9].[1-9][0-9]",
|
||||||
"python[1-9]"};
|
"python[1-9]"};
|
||||||
for (const FilePath &path : env.path()) {
|
const FilePaths dirs = Environment::systemEnvironment().path();
|
||||||
|
for (const FilePath &path : dirs) {
|
||||||
const QDir dir(path.toString());
|
const QDir dir(path.toString());
|
||||||
for (const QFileInfo &fi : dir.entryInfoList(filters)) {
|
for (const QFileInfo &fi : dir.entryInfoList(filters)) {
|
||||||
const FilePath executable = Utils::FilePath::fromFileInfo(fi);
|
const FilePath executable = Utils::FilePath::fromFileInfo(fi);
|
||||||
@@ -685,9 +684,9 @@ static void addPythonsFromPath(QList<Interpreter> &pythons)
|
|||||||
|
|
||||||
static QString idForPythonFromPath(const QList<Interpreter> &pythons)
|
static QString idForPythonFromPath(const QList<Interpreter> &pythons)
|
||||||
{
|
{
|
||||||
FilePath pythonFromPath = Environment::systemEnvironment().searchInPath("python3");
|
FilePath pythonFromPath = FilePath("python3").searchInPath();
|
||||||
if (pythonFromPath.isEmpty())
|
if (pythonFromPath.isEmpty())
|
||||||
pythonFromPath = Environment::systemEnvironment().searchInPath("python");
|
pythonFromPath = FilePath("python").searchInPath();
|
||||||
if (pythonFromPath.isEmpty())
|
if (pythonFromPath.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
const Interpreter &defaultInterpreter
|
const Interpreter &defaultInterpreter
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ FilePath detectPython(const FilePath &documentPath)
|
|||||||
if (!project)
|
if (!project)
|
||||||
project = ProjectManager::startupProject();
|
project = ProjectManager::startupProject();
|
||||||
|
|
||||||
Environment env = Environment::systemEnvironment();
|
FilePaths dirs = Environment::systemEnvironment().path();
|
||||||
|
|
||||||
if (project) {
|
if (project) {
|
||||||
if (auto target = project->activeTarget()) {
|
if (auto target = project->activeTarget()) {
|
||||||
@@ -44,7 +44,7 @@ FilePath detectPython(const FilePath &documentPath)
|
|||||||
if (auto interpreter = runConfig->aspect<InterpreterAspect>())
|
if (auto interpreter = runConfig->aspect<InterpreterAspect>())
|
||||||
return interpreter->currentInterpreter().command;
|
return interpreter->currentInterpreter().command;
|
||||||
if (auto environmentAspect = runConfig->aspect<EnvironmentAspect>())
|
if (auto environmentAspect = runConfig->aspect<EnvironmentAspect>())
|
||||||
env = environmentAspect->environment();
|
dirs = environmentAspect->environment().path();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +62,9 @@ FilePath detectPython(const FilePath &documentPath)
|
|||||||
if (defaultInterpreter.exists())
|
if (defaultInterpreter.exists())
|
||||||
return defaultInterpreter;
|
return defaultInterpreter;
|
||||||
|
|
||||||
auto pythonFromPath = [=](const QString toCheck) {
|
auto pythonFromPath = [dirs](const FilePath &toCheck) {
|
||||||
for (const FilePath &python : env.findAllInPath(toCheck)) {
|
const FilePaths found = toCheck.searchAllInDirectories(dirs);
|
||||||
|
for (const FilePath &python : found) {
|
||||||
// Windows creates empty redirector files that may interfere
|
// Windows creates empty redirector files that may interfere
|
||||||
if (python.exists() && python.osType() == OsTypeWindows && python.fileSize() != 0)
|
if (python.exists() && python.osType() == OsTypeWindows && python.fileSize() != 0)
|
||||||
return python;
|
return python;
|
||||||
|
|||||||
Reference in New Issue
Block a user