logic: make python environment path configurable in project settings
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
SOURCETRAIL_PYTHON_INDEXER_VERSION="v0_db23_p2"
|
||||
SOURCETRAIL_PYTHON_INDEXER_VERSION="v0_db23_p3"
|
||||
|
||||
# Determine current platform
|
||||
PLATFORM='unknown'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "SourceGroupSettingsCxxCodeblocks.h"
|
||||
|
||||
#include "ProjectSettings.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
SourceGroupSettingsCxxCodeblocks::SourceGroupSettingsCxxCodeblocks(const std::string& id, const ProjectSettings* projectSettings)
|
||||
: SourceGroupSettingsCxx(id, SOURCE_GROUP_CXX_CODEBLOCKS, projectSettings)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "SourceGroupSettingsPythonEmpty.h"
|
||||
|
||||
#include "FilePath.h"
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
SourceGroupSettingsPythonEmpty::SourceGroupSettingsPythonEmpty(const std::string& id, const ProjectSettings* projectSettings)
|
||||
: SourceGroupSettings(id, SOURCE_GROUP_PYTHON_EMPTY, projectSettings)
|
||||
@@ -20,6 +22,8 @@ void SourceGroupSettingsPythonEmpty::load(std::shared_ptr<const ConfigManager> c
|
||||
SourceGroupSettingsWithExcludeFilters::load(config, key);
|
||||
SourceGroupSettingsWithSourcePaths::load(config, key);
|
||||
SourceGroupSettingsWithSourceExtensions::load(config, key);
|
||||
|
||||
setEnvironmentDirectoryPath(config->getValueOrDefault(key + "/python_environment_directory_path", FilePath(L"")));
|
||||
}
|
||||
|
||||
void SourceGroupSettingsPythonEmpty::save(std::shared_ptr<ConfigManager> config)
|
||||
@@ -31,21 +35,39 @@ void SourceGroupSettingsPythonEmpty::save(std::shared_ptr<ConfigManager> config)
|
||||
SourceGroupSettingsWithExcludeFilters::save(config, key);
|
||||
SourceGroupSettingsWithSourcePaths::save(config, key);
|
||||
SourceGroupSettingsWithSourceExtensions::save(config, key);
|
||||
|
||||
config->setValue(key + "/python_environment_directory_path", getEnvironmentDirectoryPath().wstr());
|
||||
}
|
||||
|
||||
bool SourceGroupSettingsPythonEmpty::equals(std::shared_ptr<SourceGroupSettings> other) const
|
||||
{
|
||||
std::shared_ptr<SourceGroupSettingsPythonEmpty> otherJava = std::dynamic_pointer_cast<SourceGroupSettingsPythonEmpty>(other);
|
||||
std::shared_ptr<SourceGroupSettingsPythonEmpty> otherPython = std::dynamic_pointer_cast<SourceGroupSettingsPythonEmpty>(other);
|
||||
|
||||
return (
|
||||
otherJava &&
|
||||
otherPython &&
|
||||
SourceGroupSettings::equals(other) &&
|
||||
SourceGroupSettingsWithExcludeFilters::equals(otherJava) &&
|
||||
SourceGroupSettingsWithSourcePaths::equals(otherJava) &&
|
||||
SourceGroupSettingsWithSourceExtensions::equals(otherJava)
|
||||
SourceGroupSettingsWithExcludeFilters::equals(otherPython) &&
|
||||
SourceGroupSettingsWithSourcePaths::equals(otherPython) &&
|
||||
SourceGroupSettingsWithSourceExtensions::equals(otherPython) &&
|
||||
m_environmentDirectoryPath == otherPython->m_environmentDirectoryPath
|
||||
);
|
||||
}
|
||||
|
||||
FilePath SourceGroupSettingsPythonEmpty::getEnvironmentDirectoryPath() const
|
||||
{
|
||||
return m_environmentDirectoryPath;
|
||||
}
|
||||
|
||||
FilePath SourceGroupSettingsPythonEmpty::getEnvironmentDirectoryPathExpandedAndAbsolute() const
|
||||
{
|
||||
return m_projectSettings->makePathExpandedAndAbsolute(getEnvironmentDirectoryPath());
|
||||
}
|
||||
|
||||
void SourceGroupSettingsPythonEmpty::setEnvironmentDirectoryPath(const FilePath& environmentDirectoryPath)
|
||||
{
|
||||
m_environmentDirectoryPath = environmentDirectoryPath;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> SourceGroupSettingsPythonEmpty::getDefaultSourceExtensions() const
|
||||
{
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SOURCE_GROUP_SETTINGS_PYTHON_EMPTY_H
|
||||
#define SOURCE_GROUP_SETTINGS_PYTHON_EMPTY_H
|
||||
|
||||
#include "FilePath.h"
|
||||
#include "SourceGroupSettings.h"
|
||||
#include "SourceGroupSettingsWithExcludeFilters.h"
|
||||
#include "SourceGroupSettingsWithSourceExtensions.h"
|
||||
@@ -22,9 +23,14 @@ public:
|
||||
|
||||
bool equals(std::shared_ptr<SourceGroupSettings> other) const override;
|
||||
|
||||
FilePath getEnvironmentDirectoryPath() const;
|
||||
FilePath getEnvironmentDirectoryPathExpandedAndAbsolute() const;
|
||||
void setEnvironmentDirectoryPath(const FilePath& environmentDirectoryPath);
|
||||
|
||||
private:
|
||||
std::vector<std::wstring> getDefaultSourceExtensions() const override;
|
||||
|
||||
FilePath m_environmentDirectoryPath;
|
||||
};
|
||||
|
||||
#endif // SOURCE_GROUP_SETTINGS_PYTHON_EMPTY_H
|
||||
|
||||
@@ -412,6 +412,7 @@ namespace
|
||||
std::vector<QtSourceGroupWizzardPage<SourceGroupSettingsPythonEmpty>> pages;
|
||||
{
|
||||
QtSourceGroupWizzardPage<SourceGroupSettingsPythonEmpty> page("Indexed Paths", 750, 600);
|
||||
page.addContentCreatorWithSettings<QtProjectWizzardContentPathPythonEnvironment>(WIZZARD_CONTENT_CONTEXT_ALL);
|
||||
page.addContentCreatorWithSettings<QtProjectWizzardContentPathsSource>(WIZZARD_CONTENT_CONTEXT_ALL);
|
||||
page.addContentCreatorWithSettings<QtProjectWizzardContentPathsExclude>(WIZZARD_CONTENT_CONTEXT_ALL);
|
||||
page.addContentCreatorWithSettings<QtProjectWizzardContentExtensions>(WIZZARD_CONTENT_CONTEXT_ALL);
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
#include "QtProjectWizzardContentPaths.h"
|
||||
#include "ApplicationSettings.h"
|
||||
#include "SourceGroupSettingsCxxCdb.h"
|
||||
#include "SourceGroupSettingsCxxCodeblocks.h"
|
||||
#include "SourceGroupSettingsCxxSonargraph.h"
|
||||
#include "SourceGroupSettingsJavaMaven.h"
|
||||
#include "SourceGroupSettingsJavaGradle.h"
|
||||
#include "SourceGroupSettingsJavaSonargraph.h"
|
||||
#include "SourceGroupSettingsPythonEmpty.h"
|
||||
#include "SourceGroupSettingsWithSonargraphProjectPath.h"
|
||||
#include "SourceGroupSettingsCxxCodeblocks.h"
|
||||
#include "FileManager.h"
|
||||
#include "MessageStatus.h"
|
||||
#include "SonargraphProject.h"
|
||||
@@ -36,6 +37,7 @@
|
||||
QtProjectWizzardContentPath::QtProjectWizzardContentPath(QtProjectWizzardWindow* window)
|
||||
: QtProjectWizzardContent(window)
|
||||
, m_makePathRelativeToProjectFileLocation(true)
|
||||
, m_allowEmpty(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,6 +53,7 @@ void QtProjectWizzardContentPath::populate(QGridLayout* layout, int& row)
|
||||
|
||||
m_picker = new QtLocationPicker(this);
|
||||
m_picker->setPickDirectory(true);
|
||||
m_picker->setPlaceholderText(m_placeholderString);
|
||||
|
||||
if (m_makePathRelativeToProjectFileLocation)
|
||||
{
|
||||
@@ -69,8 +72,15 @@ bool QtProjectWizzardContentPath::check()
|
||||
{
|
||||
if (m_picker->getText().isEmpty())
|
||||
{
|
||||
error = "Please define a path at \"" + m_titleString + "\".";
|
||||
break;
|
||||
if (m_allowEmpty)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Please define a path at \"" + m_titleString + "\".";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FilePath path = getSourceGroupSettings()->makePathExpandedAndAbsolute(FilePath(m_picker->getText().toStdWString()));
|
||||
@@ -95,7 +105,7 @@ bool QtProjectWizzardContentPath::check()
|
||||
break;
|
||||
}
|
||||
|
||||
if (error.size())
|
||||
if (!error.isEmpty())
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(error);
|
||||
@@ -116,11 +126,20 @@ void QtProjectWizzardContentPath::setHelpString(const QString& help)
|
||||
m_helpString = help;
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPath::setPlaceholderString(const QString& placeholder)
|
||||
{
|
||||
m_placeholderString = placeholder;
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPath::setFileEndings(const std::set<std::wstring>& fileEndings)
|
||||
{
|
||||
m_fileEndings = fileEndings;
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPath::setAllowEmpty(bool allowEmpty)
|
||||
{
|
||||
m_allowEmpty = allowEmpty;
|
||||
}
|
||||
|
||||
QtProjectWizzardContentPathCDB::QtProjectWizzardContentPathCDB(
|
||||
std::shared_ptr<SourceGroupSettingsCxxCdb> settings, QtProjectWizzardWindow* window
|
||||
@@ -706,3 +725,36 @@ std::shared_ptr<SourceGroupSettings> QtProjectWizzardContentPathDependenciesGrad
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
|
||||
QtProjectWizzardContentPathPythonEnvironment::QtProjectWizzardContentPathPythonEnvironment(
|
||||
std::shared_ptr<SourceGroupSettingsPythonEmpty> settings, QtProjectWizzardWindow* window
|
||||
)
|
||||
: QtProjectWizzardContentPath(window)
|
||||
, m_settings(settings)
|
||||
{
|
||||
setTitleString("Python Environment Directory");
|
||||
setHelpString(
|
||||
"Here you can specify the path to the directory that contains the Python environment that should be used to resolve "
|
||||
"dependencies within the indexed source code. Leave blank to use the default Python environment.<br />"
|
||||
"<br />"
|
||||
"You can make use of environment variables with ${ENV_VAR}."
|
||||
);
|
||||
setPlaceholderString("Use Default");
|
||||
setAllowEmpty(true);
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPathPythonEnvironment::load()
|
||||
{
|
||||
m_picker->setText(QString::fromStdWString(m_settings->getEnvironmentDirectoryPath().wstr()));
|
||||
}
|
||||
|
||||
void QtProjectWizzardContentPathPythonEnvironment::save()
|
||||
{
|
||||
m_settings->setEnvironmentDirectoryPath(FilePath(m_picker->getText().toStdWString()));
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceGroupSettings> QtProjectWizzardContentPathPythonEnvironment::getSourceGroupSettings()
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class SourceGroupSettingsCxxCdb;
|
||||
class SourceGroupSettingsCxxCodeblocks;
|
||||
class SourceGroupSettingsCxxSonargraph;
|
||||
class SourceGroupSettingsJavaGradle;
|
||||
class SourceGroupSettingsPythonEmpty;
|
||||
class SourceGroupSettingsJavaMaven;
|
||||
class SourceGroupSettingsWithSonargraphProjectPath;
|
||||
|
||||
@@ -35,8 +36,10 @@ public:
|
||||
protected:
|
||||
void setTitleString(const QString& title);
|
||||
void setHelpString(const QString& help);
|
||||
void setPlaceholderString(const QString& placeholder);
|
||||
|
||||
void setFileEndings(const std::set<std::wstring>& fileEndings);
|
||||
void setAllowEmpty(bool allowEmpty);
|
||||
|
||||
QtLocationPicker* m_picker;
|
||||
|
||||
@@ -47,7 +50,9 @@ private:
|
||||
|
||||
QString m_titleString;
|
||||
QString m_helpString;
|
||||
QString m_placeholderString;
|
||||
std::set<std::wstring> m_fileEndings;
|
||||
bool m_allowEmpty;
|
||||
};
|
||||
|
||||
|
||||
@@ -231,4 +236,22 @@ private:
|
||||
std::shared_ptr<SourceGroupSettingsJavaGradle> m_settings;
|
||||
};
|
||||
|
||||
|
||||
class QtProjectWizzardContentPathPythonEnvironment
|
||||
: public QtProjectWizzardContentPath
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtProjectWizzardContentPathPythonEnvironment(std::shared_ptr<SourceGroupSettingsPythonEmpty> settings, QtProjectWizzardWindow* window);
|
||||
|
||||
// QtProjectWizzardContent implementation
|
||||
void load() override;
|
||||
void save() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
|
||||
|
||||
std::shared_ptr<SourceGroupSettingsPythonEmpty> m_settings;
|
||||
};
|
||||
|
||||
#endif // QT_PROJECT_WIZZARD_CONTENT_PATH_H
|
||||
|
||||
@@ -36,13 +36,23 @@ std::set<FilePath> SourceGroupPythonEmpty::getAllSourceFilePaths() const
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupPythonEmpty::getIndexerCommands(const std::set<FilePath>& filesToIndex) const
|
||||
{
|
||||
std::wstring args = L"";
|
||||
|
||||
args += L" --source-file-path=%{SOURCE_FILE_PATH}";
|
||||
args += L" --database-file-path=%{DATABASE_FILE_PATH}";
|
||||
|
||||
if (!m_settings->getEnvironmentDirectoryPath().empty())
|
||||
{
|
||||
args += L" --environment-directory-path=" + m_settings->getEnvironmentDirectoryPathExpandedAndAbsolute().wstr();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
|
||||
for (const FilePath& sourceFilePath : getAllSourceFilePaths())
|
||||
{
|
||||
if (filesToIndex.find(sourceFilePath) != filesToIndex.end())
|
||||
{
|
||||
indexerCommands.push_back(std::make_shared<IndexerCommandCustom>(
|
||||
L"\"" + ResourcePaths::getPythonPath().wstr() + L"SourcetrailPythonIndexer\" --source-file-path=%{SOURCE_FILE_PATH} --database-file-path=%{DATABASE_FILE_PATH}",
|
||||
L"\"" + ResourcePaths::getPythonPath().wstr() + L"SourcetrailPythonIndexer\"" + args,
|
||||
m_settings->getProjectSettings()->getProjectFilePath(),
|
||||
m_settings->getProjectSettings()->getTempDBFilePath(),
|
||||
std::to_wstring(SqliteIndexStorage::getStorageVersion()),
|
||||
|
||||
Reference in New Issue
Block a user