Adjust footprint() to return application and project footprint by marvinoe21 · Pull Request #631 · dlr-gtlab/python-module · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
28 changes: 19 additions & 9 deletions src/module/extensions/gtpy_pythonfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ gtpy::extension::func::envVars(PyObject* self)
}

/**
* @brief return footprint of GTlab
* @param only_active : true -> shows all active modules within the project
* false ->shows all available modules within GTlab
* @return map of module names and versions
* @brief By default, it returns the application footprint of GTlab, which is a
* map of loaded module names and their versions. If only_active is true,
* it returns only the modules that are part of the data model of the current
* project.
* @param only_active If true it returns the project footprint, otherwise
* it returns the application footprint. Defaults to false.
* @return A map of module names and their versions.
*/
PyObjectAPIReturn
gtpy::extension::func::footprint(PyObject* self, PyObject* args, PyObject* kwargs)
Expand All @@ -68,7 +71,7 @@ gtpy::extension::func::footprint(PyObject* self, PyObject* args, PyObject* kwarg
static const char* kwlist[] = {"only_active", nullptr};

// Parse the arguments
int onlyActive = 1; // Default value
int onlyActive = 0; // Default value

// Parse the arguments
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|p:footprint",
Expand All @@ -82,11 +85,18 @@ gtpy::extension::func::footprint(PyObject* self, PyObject* args, PyObject* kwarg
GT_VERSION_MINOR,
GT_VERSION_PATCH).toString()));

const auto modules = onlyActive > 0 ?
gtApp->moduleDatamodelInterfaceIds() :
gtApp->moduleIds();
QStringList modules{};

for (const auto& mod : modules)
if (onlyActive == 0)
{
modules = gtApp->moduleIds();
}
else if (auto* proj = gtApp->currentProject())
{
modules = proj->moduleIds();
}

for (const auto& mod : qAsConst(modules))
{
PyPPDict_SetItem(versionMap,
PyPPObject::fromQString(mod),
Expand Down
11 changes: 8 additions & 3 deletions src/module/extensions/gtpy_pythonfunctions.h