MCPcopy Create free account
hub / github.com/catboost/catboost / main

Function main

tools/py3cc/main.cpp:36–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36int main(int argc, char** argv) {
37 if (argc != 6) {
38 Cerr << "Usage:\n\t" << argv[0] << " --slow-py3cc <slow-py3cc> SRC_PATH_X- SRC OUT" << Endl;
39 return 1;
40 }
41
42 PyConfig cfg{};
43 PyConfig_InitIsolatedConfig(&cfg);
44 cfg._install_importlib = 0;
45 Y_SCOPE_EXIT(&cfg) {PyConfig_Clear(&cfg);};
46
47 const char* slowPy3cc{argv[2]};
48 TString srcpath{argv[3]};
49 srcpath.pop_back();
50 const TFsPath inPath{argv[4]};
51 const char* outPath = argv[5];
52
53 const auto status = Py_InitializeFromConfig(&cfg);
54 if (PyStatus_Exception(status)) {
55 Py_ExitStatusException(status);
56 }
57 Y_SCOPE_EXIT() {Py_Finalize();};
58
59 TPyObject bytecode{Py_CompileString(
60 TFileInput{inPath}.ReadAll().c_str(),
61 srcpath.c_str(),
62 Py_file_input
63 )};
64 if (!bytecode) {
65 int rc = runSlowPy3cc(slowPy3cc, argv[3], argv[4], argv[5]);
66 return rc;
67 }
68
69 if (FILE* out = fopen(outPath, "wb")) {
70 PyMarshal_WriteObjectToFile(bytecode.Get(), out, Py_MARSHAL_VERSION);
71 fclose(out);
72 if (PyErr_Occurred()) {
73 Cerr << "Failed to marshal " << outPath << Endl;
74 PyErr_Print();
75 return 1;
76 }
77 } else {
78 Cerr << "Failed to write " << outPath << ": " << std::error_code{errno, std::system_category()}.message() << Endl;
79 return 1;
80 }
81
82 return 0;
83}

Callers

nothing calls this directly

Calls 7

runSlowPy3ccFunction · 0.85
ReadAllMethod · 0.80
fopenFunction · 0.50
pop_backMethod · 0.45
c_strMethod · 0.45
GetMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected