Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring some utilities #636

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/xeus-python/xutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ namespace xpyt

XEUS_PYTHON_API bool holding_gil();

XEUS_PYTHON_API
std::string extract_parameter(std::string param, int argc, char* argv[]);

XEUS_PYTHON_API
bool extract_option(std::string short_opt, std::string long_opt, int argc, char* argv[]);

Expand All @@ -62,9 +59,6 @@ namespace xpyt
XEUS_PYTHON_API
void sigkill_handler(int sig);

XEUS_PYTHON_API
bool should_print_version(int argc, char* argv[]);

XEUS_PYTHON_API
void print_pythonhome();

Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "xeus/xkernel.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus/xinterpreter.hpp"
#include "xeus/xhelper.hpp"

#include "xeus-zmq/xserver_zmq_split.hpp"
#include "xeus-zmq/xzmq_context.hpp"
Expand All @@ -43,7 +44,7 @@ namespace py = pybind11;

int main(int argc, char* argv[])
{
if (xpyt::should_print_version(argc, argv))
if (xeus::should_print_version(argc, argv))
{
std::clog << "xpython " << XPYT_VERSION << std::endl;
return 0;
Expand Down Expand Up @@ -133,7 +134,7 @@ int main(int argc, char* argv[])
using history_manager_ptr = std::unique_ptr<xeus::xhistory_manager>;
history_manager_ptr hist = xeus::make_in_memory_history_manager();

std::string connection_filename = xpyt::extract_parameter("-f", argc, argv);
std::string connection_filename = xeus::extract_filename(argc, argv);

#ifdef XEUS_PYTHON_PYPI_WARNING
std::clog <<
Expand Down
5 changes: 3 additions & 2 deletions src/xpython_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "xeus/xkernel.hpp"
#include "xeus/xkernel_configuration.hpp"
#include "xeus/xhelper.hpp"

#include "xeus-zmq/xserver_zmq_split.hpp"
#include "xeus-zmq/xzmq_context.hpp"
Expand All @@ -48,7 +49,7 @@ void launch(const py::list args_list)
argv[i] = (char*)PyUnicode_AsUTF8(args_list[i].ptr());
}

if (xpyt::should_print_version(argc, argv.data()))
if (xeus::should_print_version(argc, argv.data()))
{
std::clog << "xpython " << XPYT_VERSION << std::endl;
return;
Expand All @@ -65,7 +66,7 @@ void launch(const py::list args_list)
signal(SIGINT, xpyt::sigkill_handler);

bool raw_mode = xpyt::extract_option("-r", "--raw", argc, argv.data());
std::string connection_filename = xpyt::extract_parameter("-f", argc, argv.data());
std::string connection_filename = xeus::extract_filename(argc, argv.data());

std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();

Expand Down
31 changes: 0 additions & 31 deletions src/xutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,6 @@ namespace xpyt
return py::eval(code, scope);
}

std::string extract_parameter(std::string param, int argc, char* argv[])
{
std::string res = "";
for (int i = 0; i < argc; ++i)
{
if ((std::string(argv[i]) == param) && (i + 1 < argc))
{
res = argv[i + 1];
for (int j = i; j < argc - 2; ++j)
{
argv[j] = argv[j + 2];
}
argc -= 2;
break;
}
}
return res;
}

bool extract_option(std::string short_opt, std::string long_opt, int argc, char* argv[])
{
bool res = false;
Expand Down Expand Up @@ -124,18 +105,6 @@ namespace xpyt
exit(0);
}

bool should_print_version(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
{
if (std::string(argv[i]) == "--version")
{
return true;
}
}
return false;
}

void print_pythonhome()
{
std::setlocale(LC_ALL, "en_US.utf8");
Expand Down