Skip to content

Commit

Permalink
#1037 Indigo Toolkit information in the 'About' section that is not r…
Browse files Browse the repository at this point in the history
…elevant for the users (#1192)
  • Loading branch information
Dmitry Malysh authored Jul 31, 2023
1 parent 711337d commit 5bbda74
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef unsigned char byte;
/* System */

CEXPORT const char* indigoVersion();
CEXPORT const char* indigoVersionInfo();

// Allocate a new session. Each session has its own
// set of objects created and options set up.
Expand Down
34 changes: 34 additions & 0 deletions api/c/indigo/src/indigo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ CEXPORT const char* indigoVersion()
return INDIGO_VERSION "-" INDIGO_PLATFORM;
}

CEXPORT const char* indigoVersionInfo()
{
INDIGO_BEGIN
{
std::string version = indigoVersion();

const std::string digits = "0123456789";
const auto parse = [&](const auto& shift) { return version.substr(shift, version.find_first_of("-\\")); };
const auto slice = [&](const auto& value) {
version.erase(0, value.size() + 1);
return value;
};

const std::string base_version = slice(parse(0));
const std::string major_version = base_version.substr(0, base_version.find_last_of(".\\"));
const std::string minor_version = base_version.substr(base_version.find_last_of(".\\") + 1);
const std::string dev_tag = slice(parse(0));
const std::string commit_hash = slice(parse(0));
std::string complier_platform = slice(parse(1));

const std::string os = parse(0);
complier_platform.append(slice(os));

char buf[1024];
snprintf(buf, sizeof(buf),
R"({"majorVersion": "%s", "minorVersion": "%s", "devTag": "%s", "commitHash": "%s", "compilerPlatform": "%s", "compilerVersion": "%s"})",
major_version.c_str(), minor_version.c_str(), dev_tag.c_str(), commit_hash.c_str(), complier_platform.c_str(), version.c_str());
auto& tmp = self.getThreadTmpData();
tmp.string.readString(buf, true);
return tmp.string.ptr();
}
INDIGO_END(0);
}

void Indigo::init()
{
error_handler() = nullptr;
Expand Down
6 changes: 6 additions & 0 deletions api/cpp/src/IndigoSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ std::string IndigoSession::version() const
return _checkResultString(indigoVersion());
}

std::string IndigoSession::versionInfo() const
{
setSessionId();
return _checkResultString(indigoVersionInfo());
}

IndigoMolecule IndigoSession::loadMolecule(const std::string& data)
{
setSessionId();
Expand Down
1 change: 1 addition & 0 deletions api/cpp/src/IndigoSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace indigo_cpp
void setOption(const std::string& key, bool value) const;

std::string version() const;
std::string versionInfo() const;

static IndigoSessionPtr create();

Expand Down
5 changes: 5 additions & 0 deletions api/dotnet/src/Indigo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ public string version()
return checkResult(IndigoLib.indigoVersion());
}

public string versionInfo()
{
return checkResult(IndigoLib.indigoVersionInfo());
}

public Indigo(string lib_path)
{
init(lib_path);
Expand Down
3 changes: 3 additions & 0 deletions api/dotnet/src/IndigoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern byte* indigoVersion();

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern byte* indigoVersionInfo();

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern long indigoAllocSessionId();

Expand Down
4 changes: 4 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/Indigo.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ public String version() {
return lib.indigoVersion();
}

public String versionInfo() {
return lib.indigoVersionInfo();
}

public int countReferences() {
setSessionID();
return checkResult(this, lib.indigoCountReferences());
Expand Down
2 changes: 2 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/IndigoLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
public interface IndigoLib extends Library {
String indigoVersion();

String indigoVersionInfo();

long indigoAllocSessionId();

void indigoSetSessionId(long id);
Expand Down
9 changes: 9 additions & 0 deletions api/python/indigo/indigo/indigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ def version(self):

return IndigoLib.checkResultString(self._lib().indigoVersion())

def versionInfo(self):
"""Returns Indigo version info
Returns:
str: version info string
"""

return IndigoLib.checkResultString(self._lib().indigoVersionInfo())

def countReferences(self):
"""Returns the number of objects in pool
Expand Down
2 changes: 2 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self) -> None:
IndigoLib.lib = Lib.load("indigo")
IndigoLib.lib.indigoVersion.restype = c_char_p
IndigoLib.lib.indigoVersion.argtypes = []
IndigoLib.lib.indigoVersionInfo.restype = c_char_p
IndigoLib.lib.indigoVersionInfo.argtypes = []
IndigoLib.lib.indigoAllocSessionId.restype = c_ulonglong
IndigoLib.lib.indigoAllocSessionId.argtypes = []
IndigoLib.lib.indigoSetSessionId.restype = None
Expand Down
10 changes: 10 additions & 0 deletions api/r/R/indigo.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Indigo$methods(
return(checkResultPtr(.Call("r_indigoVersion")));
})

Indigo$methods(
version = function(){
setSession()
return(checkResultPtr(.Call("r_indigoVersionInfo")));
})

Indigo$methods(
finalize = function(){
.Call("r_indigoReleaseSessionId", id)
Expand Down Expand Up @@ -117,6 +123,10 @@ version <- function() {
.Call("r_indigoVersion")
}

versionInfo <- function() {
.Call("r_indigoVersionInfo")
}

setOption <- function(option, value){
stopifnot(is.character(option))
stopifnot(length(option) == 1, length(value) == 1)
Expand Down
8 changes: 8 additions & 0 deletions api/r/src/rindigo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ REXPORT SEXP r_indigoVersion()
return result;
}

REXPORT SEXP r_indigoVersionInfo()
{
SEXP result = PROTECT(allocVector(STRSXP, 1));
_setStringToSTRSXP(&result, indigoVersionInfo());
UNPROTECT(1);
return result;
}

REXPORT SEXP r_indigoGetLastError()
{
SEXP result = PROTECT(allocVector(STRSXP, 1));
Expand Down
47 changes: 47 additions & 0 deletions api/tests/integration/tests/basic/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
import os
import sys

sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import *

indigo = Indigo()


def test_string_is_readable():
print("*** Testing string is readable ***")
try:
print(indigo.versionInfo())
except:
print("String can't be read")


def test_string_is_valid_json():
print("*** Testing string is valid json ***")
try:
json_object = json.loads(indigo.versionInfo())
print(json.dumps(json_object, indent=2))
except:
print("String is not valid json")


def test_string_has_specific_key(key):
print("*** Testing string contains '{}' key ***".format(key))
try:
print(json.loads(indigo.versionInfo())[key])
except:
print("String does not contain '{}' key".format(key))


test_string_is_readable()
test_string_is_valid_json()
test_string_has_specific_key("majorVersion")
test_string_has_specific_key("minorVersion")
test_string_has_specific_key("devTag")
test_string_has_specific_key("commitHash")
test_string_has_specific_key("compilerVersion")
test_string_has_specific_key("compilerPlatform")
6 changes: 6 additions & 0 deletions api/wasm/indigo-ketcher/indigo-ketcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ namespace indigo
return _checkResultString(indigoVersion());
}

std::string versionInfo()
{
return _checkResultString(indigoVersionInfo());
}

std::string convert(const std::string& data, const std::string& outputFormat, const std::map<std::string, std::string>& options)
{
const IndigoSession session;
Expand Down Expand Up @@ -757,6 +762,7 @@ namespace indigo
EMSCRIPTEN_BINDINGS(module)
{
emscripten::function("version", &version);
emscripten::function("versionInfo", &versionInfo);
emscripten::function("convert", &convert);
emscripten::function("aromatize", &aromatize);
emscripten::function("dearomatize", &dearomatize);
Expand Down
7 changes: 7 additions & 0 deletions api/wasm/indigo-ketcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ M END
});
}

// Version Info
{
test("versionInfo", "basic", () => {
assert(indigo.versionInfo().indexOf("wasm") !== -1);
});
}

// reactionComponents
{
test("reactionComponents", "basic", () => {
Expand Down

0 comments on commit 5bbda74

Please sign in to comment.