-a, --annotate Produce a colorized HTML version of the source.
--line-directives Produce #line directives pointing to the .pyx source
--cplus Output a c++ rather than c file.
+ --embed Embed the Python interpreter in a main() method.
--directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
options = CompilationOptions(default_options)
sources = []
while args:
+ print args
if args[0].startswith("-"):
option = pop_arg()
if option in ("-V", "--version"):
options.obj_only = 0
elif option in ("-+", "--cplus"):
options.cplus = 1
+ elif option == "--embed":
+ Options.embed = True
elif option.startswith("-I"):
options.include_path.append(get_param(option))
elif option == "--include-dir":
self.generate_module_init_func(modules[:-1], env, code)
code.mark_pos(None)
self.generate_module_cleanup_func(env, code)
+ if Options.embed:
+ self.generate_main_method(env, code)
self.generate_filename_table(code)
self.generate_utility_functions(env, code, h_code)
code.putln("Py_INCREF(Py_None); return Py_None;")
code.putln('}')
+ def generate_main_method(self, env, code):
+ code.globalstate.use_utility_code(main_method.specialize(module_name=env.module_name))
+
def generate_filename_init_call(self, code):
code.putln("%s();" % Naming.fileinit_cname)
#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r)
#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r)
""")
+
+main_method = UtilityCode(
+impl = """
+int main(int argc, char** argv) {
+ int r;
+ Py_Initialize();
+ PySys_SetArgv(argc, argv);
+#if PY_MAJOR_VERSION < 3
+ init%(module_name)s();
+#else
+ PyInit_%(module_name)s(name);
+#endif
+ r = PyErr_Occurred();
+ Py_Finalize();
+ return r;
+}
+""")
\ No newline at end of file
# Append the c file and line number to the traceback for exceptions.
c_line_in_traceback = 1
+# Whether or not to embed the Python interpreter, for use in making a
+# standalone executable. This will provide a main() method which simply
+# executes the body of this module.
+embed = False
+
# Declare pragmas
option_defaults = {