Skip to content

Commit e94b0bc

Browse files
authored
Merge pull request #5 from kpeeters/master
Sync with upstream
2 parents 0f6ec03 + c3927f1 commit e94b0bc

File tree

22 files changed

+324
-83
lines changed

22 files changed

+324
-83
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ warned, it can easily take several hours, but at least it's automatic)::
388388
389389
vcpkg install mpir:x64-windows glibmm:x64-windows (go have a coffee)
390390
vcpkg install sqlite3:x64-windows boost:x64-windows (go for dinner)
391-
vcpkg install gtkmm:x64-windows (run overnight)
391+
vcpkg install gtkmm:x64-windows (run overnight)
392392
vcpkg integrate install
393393

394394
boost-system:x64-windows

client_server/Server.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ std::string Server::run_string(const std::string& blk, bool handle_output)
159159
std::string result;
160160

161161
// Preparse input block.
162-
auto newblk = cadabra::cdb2python(blk, true);
162+
auto newblk = cadabra::cdb2python_string(blk, true);
163163

164164
// std::cerr << "PREPARSED:\n" << newblk << std::endl;
165165
// snoop::log("preparsed") << newblk << snoop::flush;

client_server/cadabra-server.cc

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,52 @@
88
#include <Windows.h>
99
#endif
1010

11+
#ifdef _WIN32
12+
13+
std::string getRegKey(const std::string& location, const std::string& name, bool system)
14+
{
15+
HKEY key;
16+
TCHAR value[1024];
17+
DWORD bufLen = 1024*sizeof(TCHAR);
18+
long ret;
19+
ret = RegOpenKeyExA(system?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER, location.c_str(), 0, KEY_QUERY_VALUE, &key);
20+
if( ret != ERROR_SUCCESS ){
21+
return std::string();
22+
}
23+
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
24+
RegCloseKey(key);
25+
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
26+
return std::string();
27+
}
28+
std::string stringValue = std::string(value, (size_t)bufLen - 1);
29+
size_t i = stringValue.length();
30+
while( i > 0 && stringValue[i-1] == '\0' ){
31+
--i;
32+
}
33+
return stringValue.substr(0,i);
34+
}
35+
36+
#endif
37+
1138
// Run a simple Cadabra server on a local port.
1239

1340
int main()
1441
{
1542
#ifdef _WIN32
1643
// The Anaconda people _really_ do not understand packaging...
44+
// We are going to find out the installation path for Anaconda/Miniconda
45+
// by querying a registry key.
1746
std::string pythonhome=Glib::getenv("PYTHONHOME");
18-
std::string pythonpath=Glib::getenv("PYTHONPATH");
19-
Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + Glib::get_home_dir()+"/Anaconda3");
20-
Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + Glib::get_home_dir()+"/Anaconda3");
47+
std::string pythonpath=Glib::getenv("PYTHONPATH");
48+
49+
std::string s = getRegKey("SOFTWARE\\Python\\PythonCore\\3.7", "", false);
50+
if(s=="")
51+
s = getRegKey("SOFTWARE\\Python\\PythonCore\\3.7", "", true);
52+
53+
// Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + Glib::get_home_dir()+"/Anaconda3");
54+
// Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + Glib::get_home_dir()+"/Anaconda3");
55+
Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + s);
56+
Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + s);
2157
// std::cerr << "Server::init: using PYTHONPATH = " << Glib::getenv("PYTHONPATH")
2258
// << " and PYTHONHOME = " << Glib::getenv("PYTHONHOME") << "." << std::endl;
2359
#endif

cmake/packaging.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Logic to build packages (RPM/DEB) using CPack; see https://cmake.org/Wiki/CMake:Packaging_With_CPack
22
#
33

4+
if(MSVC)
5+
set(CPACK_GENERATOR "NSIS")
6+
message("-- This is a Windows system")
7+
endif()
8+
49
set(LINUX_NAME "")
510
if(EXISTS "/etc/redhat-release")
611
file(READ "/etc/redhat-release" LINUX_ISSUE)
@@ -149,7 +154,15 @@ else()
149154
endif()
150155
endif()
151156

157+
# Ensure that on Windows we also install the libraries provided
158+
# by Visual Studio, e.g. MSVCnnn.DLL. This does mean that the installer
159+
# will now contain both the normal and the debug libraries, but better
160+
# to have both than to have none.
161+
# set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
162+
# That didn't work... Commented out for future reference.
163+
152164
include (InstallRequiredSystemLibraries)
165+
153166
set(CPACK_SET_DESTDIR true)
154167
set(CPACK_INSTALL_PREFIX /usr)
155168
set(CPACK_PACKAGE_NAME "cadabra2")

config/install_script.iss

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "Cadabra2"
5-
#define MyAppVersion "2.1.9"
5+
#define MyAppVersion "2.2.7"
66
#define MyAppPublisher "Kasper Peeters"
7-
#define MyAppURL "http://www.cadabra.science/"
7+
#define MyAppURL "https://www.cadabra.science/"
88
#define MyAppExeName "cadabra2-gtk.exe"
99

1010
[Setup]
@@ -46,6 +46,35 @@ Source: "C:\Cadabra\bin\cadabra2-gtk.exe"; DestDir: "{app}\bin"; Flags: ignoreve
4646
Source: "C:\Cadabra\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
4747
; Source: "C:\Users\kasper\Anaconda3\DLLs\sqlite3.dll"; DestDir: "{app}\bin"; Flags: ignoreversion
4848
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
49+
; VC++ redistributable runtime. Extracted by VC2019RedistNeedsInstall(), if needed.
50+
Source: "vcredist_x64.exe"; DestDir: {tmp}; Flags: dontcopy
51+
52+
[Run]
53+
Filename: "{tmp}\vcredist_x64.exe"; StatusMsg: "Installing VC++ redistributables..."; Parameters: "/quiet"; Check: VC2019RedistNeedsInstall ; Flags: waituntilterminated
54+
55+
; https://stackoverflow.com/questions/24574035/how-to-install-microsoft-vc-redistributables-silently-in-inno-setup
56+
[Code]
57+
function VC2019RedistNeedsInstall: Boolean;
58+
var
59+
Version: String;
60+
begin
61+
if (RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64', 'Version', Version)) then
62+
begin
63+
// Is the installed version at least 14.23 ?
64+
Log('VC Redist Version check : found ' + Version);
65+
Result := (CompareStr(Version, 'v14.23.27820.00')<0);
66+
end
67+
else
68+
begin
69+
// Not even an old version installed
70+
Result := True;
71+
end;
72+
if (Result) then
73+
begin
74+
ExtractTemporaryFile('vcredist_x64.exe');
75+
end;
76+
end;
77+
4978
5079
[Icons]
5180
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"

config/pre_install.rtf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Before installing Cadabra, you must make sure that you have installed the following:
22

3-
* Anaconda Python 3.x (64 bit)
3+
* Anaconda Python 3.7 (64 bit)
44

5-
You must have Anaconda Python installed on your system. This is available from https://www.anaconda.com/download/ . The Cadabra binary you are about to install does not work with other types of Python installations.
5+
You must have Anaconda or Miniconda Python 3.7 installed on your system. This is available from https://www.anaconda.com/download/ . The Cadabra binary you are about to install does not work with other types of Python installations.
66

77
* A working LaTeX distribution
88

core/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,17 @@ if (MSVC AND NOT INSTALL_TARGETS_ONLY)
420420
install_dlls_from("core")
421421
endif()
422422

423+
if(NOT MSVC)
423424
add_custom_target(deduplicate
424425
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra2.1"
425426
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra2cadabra.1"
426427
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra2html.1"
427428
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra2python.1"
428429
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra2-gtk.1"
429-
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra-server.1")
430+
COMMAND rm -f "\$(DESTDIR)${CMAKE_INSTALL_PREFIX}/man/man1/cadabra-server.1"
431+
COMMENT "Removing manual pages from old location."
432+
)
433+
endif()
430434

431435
# manual pages
432436
if(NOT MSVC)

core/CdbPython.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,34 @@ std::string cadabra::escape_quotes(const std::string& line)
1515
// return ret;
1616
}
1717

18+
std::string cadabra::cdb2python(const std::string& in_name, bool display)
19+
{
20+
// Read the file into a string.
21+
std::ifstream ifs(in_name);
22+
std::stringstream buffer;
23+
buffer << ifs.rdbuf();
24+
25+
std::time_t t = std::time(nullptr);
26+
std::tm tm = *std::localtime(&t);
27+
28+
std::ostringstream ofs;
29+
ofs << "# cadabra2 package, auto-compiled " << std::put_time(&tm, "%F %T") << '\n'
30+
<< "# Do not modify - changing the timestamp of this file may cause import errors\n"
31+
<< "# Original file location: " << in_name << '\n'
32+
<< "import cadabra2\n"
33+
<< "import imp\n"
34+
<< "from cadabra2 import *\n"
35+
<< "from cadabra2_defaults import *\n"
36+
<< "__cdbkernel__ = cadabra2.__cdbkernel__\n"
37+
<< "temp__all__ = dir() + ['temp__all__']\n\n"
38+
<< "def display(ex):\n"
39+
<< " pass\n\n";
40+
41+
ofs << cdb2python_string(buffer.str(), display);
42+
return ofs.str();
43+
}
1844

19-
std::string cadabra::cdb2python(const std::string& blk, bool display)
45+
std::string cadabra::cdb2python_string(const std::string& blk, bool display)
2046
{
2147
std::stringstream str(blk);
2248
std::string line;

core/CdbPython.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace cadabra {
1616

1717
std::string cdb2python(const std::string&, bool display);
1818

19+
std::string cdb2python_string(const std::string&, bool display);
20+
1921
/// \ingroup files
2022
/// As above, but for a single line; for private use only.
2123
/// If display is false, this will not make ';' characters

0 commit comments

Comments
 (0)