diff --git a/script/download_python_indexer.sh b/script/download_python_indexer.sh index 1e25330e..2ede4b1d 100755 --- a/script/download_python_indexer.sh +++ b/script/download_python_indexer.sh @@ -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' diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp index 3b556166..af974c70 100644 --- a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp @@ -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) diff --git a/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp b/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp index 0e1aa776..45c807f9 100644 --- a/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp +++ b/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp @@ -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 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 config) @@ -31,21 +35,39 @@ void SourceGroupSettingsPythonEmpty::save(std::shared_ptr 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 other) const { - std::shared_ptr otherJava = std::dynamic_pointer_cast(other); + std::shared_ptr otherPython = std::dynamic_pointer_cast(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 SourceGroupSettingsPythonEmpty::getDefaultSourceExtensions() const { return { diff --git a/src/lib/settings/SourceGroupSettingsPythonEmpty.h b/src/lib/settings/SourceGroupSettingsPythonEmpty.h index 4bab6886..4e6e76cb 100644 --- a/src/lib/settings/SourceGroupSettingsPythonEmpty.h +++ b/src/lib/settings/SourceGroupSettingsPythonEmpty.h @@ -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 other) const override; + FilePath getEnvironmentDirectoryPath() const; + FilePath getEnvironmentDirectoryPathExpandedAndAbsolute() const; + void setEnvironmentDirectoryPath(const FilePath& environmentDirectoryPath); + private: std::vector getDefaultSourceExtensions() const override; + FilePath m_environmentDirectoryPath; }; #endif // SOURCE_GROUP_SETTINGS_PYTHON_EMPTY_H diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 178ac2a3..88397af4 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -412,6 +412,7 @@ namespace std::vector> pages; { QtSourceGroupWizzardPage page("Indexed Paths", 750, 600); + page.addContentCreatorWithSettings(WIZZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZZARD_CONTENT_CONTEXT_ALL); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp index 819d1ea1..dad11a35 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.cpp @@ -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& fileEndings) { m_fileEndings = fileEndings; } +void QtProjectWizzardContentPath::setAllowEmpty(bool allowEmpty) +{ + m_allowEmpty = allowEmpty; +} QtProjectWizzardContentPathCDB::QtProjectWizzardContentPathCDB( std::shared_ptr settings, QtProjectWizzardWindow* window @@ -706,3 +725,36 @@ std::shared_ptr QtProjectWizzardContentPathDependenciesGrad { return m_settings; } + + +QtProjectWizzardContentPathPythonEnvironment::QtProjectWizzardContentPathPythonEnvironment( + std::shared_ptr 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.
" + "
" + "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 QtProjectWizzardContentPathPythonEnvironment::getSourceGroupSettings() +{ + return m_settings; +} diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h index 4ca6c394..543ad006 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPath.h @@ -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& fileEndings); + void setAllowEmpty(bool allowEmpty); QtLocationPicker* m_picker; @@ -47,7 +50,9 @@ private: QString m_titleString; QString m_helpString; + QString m_placeholderString; std::set m_fileEndings; + bool m_allowEmpty; }; @@ -231,4 +236,22 @@ private: std::shared_ptr m_settings; }; + +class QtProjectWizzardContentPathPythonEnvironment + : public QtProjectWizzardContentPath +{ + Q_OBJECT +public: + QtProjectWizzardContentPathPythonEnvironment(std::shared_ptr settings, QtProjectWizzardWindow* window); + + // QtProjectWizzardContent implementation + void load() override; + void save() override; + +private: + std::shared_ptr getSourceGroupSettings() override; + + std::shared_ptr m_settings; +}; + #endif // QT_PROJECT_WIZZARD_CONTENT_PATH_H diff --git a/src/lib_python/project/SourceGroupPythonEmpty.cpp b/src/lib_python/project/SourceGroupPythonEmpty.cpp index 7c1474d0..79b5a4a7 100644 --- a/src/lib_python/project/SourceGroupPythonEmpty.cpp +++ b/src/lib_python/project/SourceGroupPythonEmpty.cpp @@ -36,13 +36,23 @@ std::set SourceGroupPythonEmpty::getAllSourceFilePaths() const std::vector> SourceGroupPythonEmpty::getIndexerCommands(const std::set& 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> indexerCommands; for (const FilePath& sourceFilePath : getAllSourceFilePaths()) { if (filesToIndex.find(sourceFilePath) != filesToIndex.end()) { indexerCommands.push_back(std::make_shared( - 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()),