18 wrapper.
name =
"Py"+projectConfig.
name;
31 body +=
"\n\n";
33 body +=
"# Remarks\n\n";
34 body +=
"This project was generated automatically by [phoenix_filegenerator](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixFileGenerator)\n";
35 body +=
"using [phoenix_generator](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixGenerator) library\n\n";
38 body +=
"Version : " + projectConfig.
version +
"\n\n";
39 body += projectConfig.
url +
"\n\n";
40 body +=
"# Description\n\n";
41 body +=
"Python wrapper version.\n";
59 body +=
"from setuptools import setup\n";
60 body +=
"from setuptools import Extension\n";
61 body +=
"import sys\n";
62 body +=
"import numpy as np\n";
63 body +=
"import subprocess\n";
65 body +=
"dataStreamIncludeDir = subprocess.run(['phoenixdatastream-config', '--include'], capture_output = True, text = True).stdout.strip(\"\\n\")\n";
66 body +=
"dataStreamLibDir = subprocess.run(['phoenixdatastream-config', '--lib'], capture_output = True, text = True).stdout.strip(\"\\n\")\n";
68 body +=
"ext_modules = [\n";
69 body +=
"\tExtension(\""+moduleName+
"\", sources=([\n";
70 body +=
"\t\t\""+moduleName+
"/"+baseImplInclude+
"_wrapper.cpp\",\n";
71 body +=
"\t\t\""+moduleName+
"/"+projectConfig.
name.
toLower()+
"_module.cpp\"\n";
73 body +=
"\textra_compile_args = [\"-O3\", \"-Werror\", \"-g\"],\n";
75 body +=
"\tinclude_dirs = [np.get_include(), dataStreamIncludeDir, \"./\", \""+moduleName+
"/\"],\n";
76 body +=
"\tlibraries=[\"phoenix_data_stream\"],\n";
77 body +=
"\tlibrary_dirs=[dataStreamLibDir],\n";
83 body +=
"\t\tname=\""+moduleName+
"\",\n";
84 body +=
"\t\tversion=\""+projectConfig.
version+
"\",\n";
85 body +=
"\t\text_modules=ext_modules,\n";
87 body +=
"except Exception as e:\n";
88 body +=
"\tprint(str(e))\n";
89 body +=
"\tsys.exit(-1)\n";
106 body +=
"[project]\n";
107 body +=
"name = \"py"+projectConfig.
name.
toLower()+
"\"\n";
108 body +=
"version = \""+projectConfig.
version+
"\"\n";
110 body +=
"readme = \"README.md\"\n";
111 body +=
"license = \"CeCILL-C\"\n";
112 body +=
"dependencies = [\n";
113 body +=
"\t\"numpy\"\n";
116 body +=
"[build-system]\n";
117 body +=
"requires = [\n";
118 body +=
"\t\"numpy\",\n";
119 body +=
"\t\"setuptools >= 74.1\",\n";
120 body +=
"\t\"cython\"\n";
122 body +=
"build-backend = \"setuptools.build_meta\"\n";
144 std::map<std::string, std::string> mapEnum;
145 for(std::vector<PClassConfig>::iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
147 mapEnum[it->getName() +
"::" + it->getName()] = it->getName();
149 std::vector<PClassAttribute> & vecAttr = it->getListAttribute();
150 for(std::vector<PClassAttribute>::iterator itAttr(vecAttr.begin()); itAttr != vecAttr.end(); ++itAttr){
151 if(itAttr->getDefaultValue() ==
""){
158 for(std::vector<PClassConfig>::iterator itClass(vecClassConfig.begin()); itClass != vecClassConfig.end(); ++itClass){
159 std::vector<PClassAttribute> & vecAttr = itClass->getListAttribute();
160 for(std::vector<PClassAttribute>::iterator itAttr(vecAttr.begin()); itAttr != vecAttr.end(); ++itAttr){
161 std::map<std::string, std::string>::iterator it(mapEnum.find(itAttr->getType()));
162 if(it != mapEnum.end()){
163 itAttr->setType(it->second);
164 itAttr->setIsEnum(
true);
166 if(itAttr->getType() ==
"PPath" || itAttr->getType() ==
"PString"){
167 itAttr->setType(
"std::string");
181 std::vector<PClassConfig> vecClassConfig;
183 std::cerr <<
"project_wrapper_generator : can't load file '" << configFile <<
"'" << std::endl;
190 PPath mainProjectDir(wrapperConfig.
name);
192 std::cerr <<
"project_wrapper_generator : cannot create main directory of project '"<<mainProjectDir<<
"'" << std::endl;
198 std::cerr <<
"project_generator : cannot create module directory of project '"<<mainProjectModule<<
"'" << std::endl;
202 PPath readmeFile(mainProjectDir /
PPath(
"README.md"));
207 PPath setupFile(mainProjectDir /
PPath(
"setup.py"));
210 PPath pyprojectFile(mainProjectDir /
PPath(
"pyproject.toml"));
std::vector< PPath > PVecPath
Path of a directory or a file.
bool saveFileContent(const PString &content) const
Save a PString in a file.
PPath & eraseExtension()
Erase the extension of the PPath.
bool createDirectory(mode_t mode=0755) const
Create the current directory.
PPath getFileName() const
Get the name of the file, from last char to /.
static PString toString(const T &value)
Convert a value to a PString.
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
PString toLower() const
Convert PString in lower case.
PString getCMakeListsHeader()
Get the CMakeLists.txt header.
bool parserClassConfig(std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
Parser list class config.
Configuration of the project.
PString description
Description of the project.
PString name
Name of the project.
PString version
Project version.
bool project_wrapper_generator_setuppy(const PPath &fileName, const ProjectConfig &projectConfig, const PString &baseImplInclude, const std::vector< PClassConfig > &vecClassConfig, const PVecPath &vecInclude)
Create the readme of the project directory.
bool project_wrapper_generator_readme(const PPath &fileName, const ProjectConfig &projectConfig)
Create the readme of the project directory.
bool project_wrapper_generator_pyprojectToml(const PPath &fileName, const ProjectConfig &projectConfig, const PString &baseImplInclude, const std::vector< PClassConfig > &vecClassConfig, const PVecPath &vecInclude)
Create the readme of the project directory.
ProjectConfig project_createWrapperConfig(const ProjectConfig &projectConfig)
Create the config of the wrapper.
void updateVecClassConfig(std::vector< PClassConfig > &vecClassConfig)
Update the vector of class configuration.
bool project_wrapper_generator(const ProjectConfig &projectConfig, const PPath &configFile)
Generate a full python wrapper project with PhoenixDataStream and PhoenixTypeStream.
bool project_wrapper_moduleGenerator(const PPath &modulePath, const ProjectConfig &projectConfig, const PString &baseImplInclude, const std::vector< PClassConfig > &vecClassConfig, const PVecPath &vecInclude)
Create the wrapper module.
bool project_wrapper_moduleGeneratorTest(const PPath &projectPath, const ProjectConfig &projectConfig, const PString &moduleName, const std::vector< PClassConfig > &vecClassConfig, const PVecPath &vecInclude)
Generate the unit tests of the project.