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

[WIP] supporting cppyy #248

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Vipul-Cariappa
Copy link

@Vipul-Cariappa Vipul-Cariappa commented Jan 30, 2025

@Vipul-Cariappa
Copy link
Author

Requesting @mcbarton & @anutosh491 to have a look at this.
Please let me know if the build instructions do not work.

@anutosh491
Copy link
Collaborator

anutosh491 commented Jan 30, 2025

Hey Vipul thanks for this !

This might be interesting but as far as I know this was not planned/intended just as of now. As in I know xeus-clang-repl was/is working towards going back and forth between cpp and python and I am not sure we want this in xeus-cpp already !

I'll cc @JohanMabille here. Johan so xeus-clang-repl used to support magics which allows us to do something like this. Is this something we want to do to ?

image

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 8.33333% with 22 lines in your changes missing coverage. Please review.

Project coverage is 78.97%. Comparing base (5076c46) to head (2b29bc6).

Files with missing lines Patch % Lines
src/xmagics/pythonexec.cpp 0.00% 22 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
- Coverage   80.72%   78.97%   -1.75%     
==========================================
  Files          19       21       +2     
  Lines         970      994      +24     
  Branches       93       96       +3     
==========================================
+ Hits          783      785       +2     
- Misses        187      209      +22     
Files with missing lines Coverage Δ
src/xinterpreter.cpp 91.25% <100.00%> (+0.04%) ⬆️
src/xmagics/pythonexec.hpp 100.00% <100.00%> (ø)
src/xmagics/pythonexec.cpp 0.00% <0.00%> (ø)
Files with missing lines Coverage Δ
src/xinterpreter.cpp 91.25% <100.00%> (+0.04%) ⬆️
src/xmagics/pythonexec.hpp 100.00% <100.00%> (ø)
src/xmagics/pythonexec.cpp 0.00% <0.00%> (ø)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

#include <string>

#include "Python.h"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header Python.h is not used directly [misc-include-cleaner]

Suggested change

initialize();
if (!is_initalized) {
// initializing failed
std::cout << Cpp::EndStdStreamCapture();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::cout" is directly included [misc-include-cleaner]

src/xmagics/pythonexec.cpp:10:

- #include <string>
+ #include <iostream>
+ #include <string>

if (!is_initalized) {
// initializing failed
std::cout << Cpp::EndStdStreamCapture();
std::cerr << Cpp::EndStdStreamCapture();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::cerr" is directly included [misc-include-cleaner]

            std::cerr << Cpp::EndStdStreamCapture();
                 ^

Cpp::BeginStdStreamCapture(Cpp::kStdErr);
Cpp::BeginStdStreamCapture(Cpp::kStdOut);

PyRun_SimpleString(code.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "PyRun_SimpleString" is directly included [misc-include-cleaner]

src/xmagics/pythonexec.cpp:13:

+ #include "pythonrun.h"

std::cerr << Cpp::EndStdStreamCapture();
}

void pythonexec::initialize() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'initialize' can be made static [readability-convert-member-functions-to-static]

src/xmagics/pythonexec.hpp:24:

-         void initialize();
+         static void initialize();

}
PyConfig_Clear(&config);
#else
Py_Initialize();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Py_Initialize" is directly included [misc-include-cleaner]

src/xmagics/pythonexec.cpp:13:

+ #include "pylifecycle.h"

************************************************************************************/

#ifndef XEUS_CPP_PYTHONEXEC_MAGIC_HPP
#define XEUS_CPP_PYTHONEXEC_MAGIC_HPP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header guard does not follow preferred style [llvm-header-guard]

Suggested change
#define XEUS_CPP_PYTHONEXEC_MAGIC_HPP
#ifndef GITHUB_WORKSPACE_SRC_XMAGICS_PYTHONEXEC_HPP
#define GITHUB_WORKSPACE_SRC_XMAGICS_PYTHONEXEC_HPP

src/xmagics/pythonexec.hpp:29:

- #endif //XEUS_CPP_PYTHONEXEC_MAGIC_HPP
+ #endif // GITHUB_WORKSPACE_SRC_XMAGICS_PYTHONEXEC_HPP

class pythonexec : public xmagic_cell
{
public:
XEUS_CPP_API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "XEUS_CPP_API" is directly included [misc-include-cleaner]

src/xmagics/pythonexec.hpp:13:

- #include "xeus-cpp/xmagics.hpp"
+ #include "xeus-cpp/xeus_cpp_config.hpp"
+ #include "xeus-cpp/xmagics.hpp"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants