forked from jupyter-xeus/xeus-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpaths.cpp
79 lines (71 loc) · 2.91 KB
/
xpaths.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/***************************************************************************
* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and *
* Wolf Vollprecht *
* Copyright (c) 2018, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include <iostream>
#include <string>
#include <cstring>
#include "pybind11/pybind11.h"
#include "xeus/xsystem.hpp"
#include "xeus-python/xeus_python_config.hpp"
#include "xeus-python/xpaths.hpp"
namespace xpyt
{
std::string get_python_prefix()
{
// ------------------------------------------------------------------
// If the PYTHONHOME environment variable is defined, use that.
// ------------------------------------------------------------------
const char* pythonhome_environment = std::getenv("PYTHONHOME");
if (pythonhome_environment != nullptr && std::strlen(pythonhome_environment) != 0)
{
static const std::string pythonhome = pythonhome_environment;
return pythonhome;
}
// ------------------------------------------------------------------
// Otherwise, set the PYTHONHOME to the prefix path
// ------------------------------------------------------------------
else
{
// The XEUS_PYTHONHOME_RELPATH compile-time definition can be used.
// to specify the PYTHONHOME location as a relative path to the PREFIX.
#if defined(XEUS_PYTHONHOME_RELPATH)
static const std::string pythonhome = xeus::prefix_path() + XPYT_STRINGIFY(XEUS_PYTHONHOME_RELPATH);
#elif defined(XEUS_PYTHONHOME_ABSPATH)
static const std::string pythonhome = XPYT_STRINGIFY(XEUS_PYTHONHOME_ABSPATH);
#else
static const std::string pythonhome = xeus::prefix_path();
#endif
return pythonhome;
}
}
std::string get_python_path()
{
std::string python_prefix = get_python_prefix();
#ifdef _WIN32
if (python_prefix.back() != '\\')
{
python_prefix += '\\';
}
return python_prefix + "python.exe";
#else
if (python_prefix.back() != '/')
{
python_prefix += '/';
}
return python_prefix + "bin/python";
#endif
}
[[deprecated]]
void set_pythonhome()
{
// static const std::string pythonhome = get_python_prefix();
// static const std::wstring wstr(pythonhome.cbegin(), pythonhome.cend());;
// Py_SetPythonHome(const_cast<wchar_t*>(wstr.c_str()));
}
}