Skip to content

Commit 45ff15f

Browse files
committed
Runtime: added various sys module constants
1 parent b54219b commit 45ff15f

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/runtime/modules/SysModule.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@
2020

2121
#include <bit>
2222
#include <filesystem>
23+
#include <format>
2324

2425
using namespace py;
2526

2627
static PyModule *s_sys_module = nullptr;
2728

29+
#if defined(__clang__)
30+
#define COMPILER_VERSION "[Clang " __clang_version__ "]"
31+
#elif defined(__GNUC__)
32+
#define COMPILER_VERSION "[GCC " __VERSION__ "]"
33+
#else
34+
static_assert(false, "Unknown compiler!");
35+
#endif
36+
2837
namespace {
2938
PyResult<PyList *> create_sys_paths(Interpreter &interpreter)
3039
{
@@ -414,6 +423,20 @@ PyModule *sys_module(Interpreter &interpreter)
414423

415424
s_sys_module->add_symbol(PyString::create("warnoptions").unwrap(), PyList::create().unwrap());
416425

426+
s_sys_module->add_symbol(PyString::create("executable").unwrap(),
427+
PyString::create(std::filesystem::canonical("/proc/self/exe").string()).unwrap());
428+
429+
s_sys_module->add_symbol(PyString::create("base_prefix").unwrap(),
430+
PyString::create(std::string{ kPythonInstallPath }).unwrap());
431+
432+
s_sys_module->add_symbol(PyString::create("executable").unwrap(),
433+
PyString::create(std::filesystem::canonical("/proc/self/exe").string()).unwrap());
434+
435+
std::string py_version = std::format("3.9.0 (main) {}", COMPILER_VERSION);
436+
437+
s_sys_module->add_symbol(
438+
PyString::create("version").unwrap(), PyString::create(py_version).unwrap());
439+
417440
return s_sys_module;
418441
}
419442

0 commit comments

Comments
 (0)