PhoenixGenerator  2.2.0
Set of tools to generate code
Loading...
Searching...
No Matches
NanobindTraitTestSetup.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
8
13
16
18void NanobindTraitTestSetup::headerTestInclude(std::ofstream & fs, const GeneratorMode & mode, const PString & baseFileName) const{
19 PString fileModule = baseFileName.toLower() + "_module";
20 fs << "#!/usr/bin/env python3" << std::endl;
21 fs << "\"\"\"Test script for " << fileModule << " nanobind wrapper\"\"\"" << std::endl << std::endl;
22 fs << "import sys" << std::endl;
23 fs << "import os" << std::endl << std::endl;
24
25 // Essayer d'abord l'import direct (environnement pixi), puis avec build_path
26 fs << "try:" << std::endl;
27 fs << "\timport " << fileModule << std::endl;
28 fs << "\tprint(\"✓ " << fileModule << " imported successfully from environment!\")" << std::endl;
29 fs << "except ImportError:" << std::endl;
30 fs << "\t# Try loading from build directory" << std::endl;
31 fs << "\tbuild_path = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build', 'src')" << std::endl;
32 fs << "\tsys.path.insert(0, build_path)" << std::endl;
33 fs << "\tprint(f\"Module search path: {build_path}\")" << std::endl;
34 fs << "\tprint(f\"Absolute path: {os.path.abspath(build_path)}\")" << std::endl;
35 fs << "\ttry:" << std::endl;
36 fs << "\t\timport " << fileModule << std::endl;
37 fs << "\t\tprint(\"✓ " << fileModule << " imported successfully from build!\")" << std::endl;
38 fs << "\texcept ImportError as e:" << std::endl;
39 fs << "\t\tprint(f\"✗ Import error: {e}\")" << std::endl;
40 fs << "\t\tprint(\"Verifications to do:\")" << std::endl;
41 fs << "\t\tprint(\"1. Have you compiled the project? (cmake .. && make)\")" << std::endl;
42 fs << "\t\tprint(\"2. Does the .so file exist?\")" << std::endl;
43 fs << "\t\tprint(f\" Check: ls -la {build_path}\")" << std::endl;
44 fs << "\t\tsys.exit(1)" << std::endl << std::endl;
45}
virtual void headerTestInclude(std::ofstream &fs, const GeneratorMode &mode, const PString &baseFileName) const
Registration of static method.
NanobindTraitTestSetup()
Constructor of NanobindTraitTestSetup.
virtual ~NanobindTraitTestSetup()
Destructor of NanobindTraitTestSetup.
All the genertor modes.