Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embedded_python_dummy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
skosukhin
embedded_python_dummy
Commits
e797b971
Commit
e797b971
authored
3 months ago
by
Nils-Arne Dreier
Browse files
Options
Downloads
Patches
Plain Diff
initial commit
parents
Branches
main
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+10
-0
10 additions, 0 deletions
CMakeLists.txt
embedded_python_dummy.cxx
+61
-0
61 additions, 0 deletions
embedded_python_dummy.cxx
test.py
+7
-0
7 additions, 0 deletions
test.py
with
78 additions
and
0 deletions
CMakeLists.txt
0 → 100644
+
10
−
0
View file @
e797b971
cmake_minimum_required
(
VERSION 3.20
)
project
(
embedded_python_dummy
LANGUAGES CXX
)
find_package
(
Python3 REQUIRED COMPONENTS Development
)
add_executable
(
embedded_python_dummy
embedded_python_dummy.cxx
)
target_link_libraries
(
embedded_python_dummy Python3::Python
)
This diff is collapsed.
Click to expand it.
embedded_python_dummy.cxx
0 → 100644
+
61
−
0
View file @
e797b971
#include
<iostream>
#include
<stdexcept>
#define PY_SSIZE_T_CLEAN
#include
<Python.h>
int
main
(
int
args
,
char
**
argv
){
using
namespace
std
::
string_literals
;
if
(
false
){
// <- false is the current behavior in libpython_adapter
Py_Initialize
();
}
else
{
PyStatus
status
;
PyConfig
config
;
PyConfig_InitPythonConfig
(
&
config
);
try
{
config
.
site_import
=
1
;
// <- en-/dis- able site module
status
=
PyConfig_SetBytesString
(
&
config
,
&
config
.
program_name
,
argv
[
0
]);
if
(
PyStatus_Exception
(
status
))
{
throw
status
;
}
// set the path to the venvs executable
status
=
PyConfig_SetBytesString
(
&
config
,
&
config
.
executable
,
"/home/nils/projects/comin/embedded_python_dummy/venv/bin/python3"
);
if
(
PyStatus_Exception
(
status
))
{
throw
status
;
}
status
=
Py_InitializeFromConfig
(
&
config
);
if
(
PyStatus_Exception
(
status
))
{
throw
status
;
}
}
catch
(...){
std
::
cerr
<<
status
.
err_msg
<<
std
::
endl
;
}
PyConfig_Clear
(
&
config
);
}
PyObject
*
globals
=
PyDict_New
();
FILE
*
file
=
fopen
(
argv
[
1
],
"r"
);
if
(
file
==
NULL
)
throw
std
::
runtime_error
(
"Cannot read "
s
+
std
::
string
(
argv
[
1
]));
else
{
PyObject
*
pyResult
=
PyRun_File
(
file
,
argv
[
1
],
Py_file_input
,
globals
,
globals
);
Py_XDECREF
(
pyResult
);
fclose
(
file
);
if
(
PyErr_Occurred
())
{
PyErr_Print
();
throw
std
::
runtime_error
(
"Error while executing "
s
+
std
::
string
(
argv
[
1
]));
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
test.py
0 → 100644
+
7
−
0
View file @
e797b971
import
sys
print
(
f
"
{
sys
.
prefix
=
}
"
)
print
(
f
"
{
sys
.
base_prefix
=
}
"
)
print
(
f
"
{
sys
.
exec_prefix
=
}
"
)
print
(
f
"
{
sys
.
executable
=
}
"
)
print
(
f
"
{
sys
.
path
=
}
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment