Skip to main content

Thread: ironpython: compile .py file?


i've searched google , had no luck this. have file called test.py contents:
code:
#!/usr/bin/python  print "this test..."
how can compile using ironpython?

so anywho... problem having ipy <ironpython> didn't ship pyc.py found this:
code:
##################################################################################### # #  copyright (c) microsoft corporation. rights reserved. # # source code subject terms , conditions of microsoft public license.  # copy of license can found in license.html file @ root of distribution. if  # cannot locate  microsoft public license, please send email  # ironpy@microsoft.com. using source code in fashion, agreeing bound  # terms of microsoft public license. # # must not remove notice, or other, software. # # #####################################################################################  """ pyc: command-line python compiler  usage: ipy.exe pyc.py [options] file [file ...]  options:     /out:output_file                          output file name (default main_file.<extenstion>)     /target:dll                               compile dll.  default     /target:exe                               generate console executable stub startup in addition dll.     /target:winexe                            generate windows executable stub startup in addition dll.     /? /h                                     message      exe/winexe specific options:     /main:main_file.py                        main file of project (module executed first)     /platform:x86                             compile x86     /platform:x64                             compile x64   example:     ipy.exe pyc.py /main:program.py form.py /target:winexe """  import sys import clr clr.addreferencebypartialname("ironpython")  system.collections.generic import list import ironpython.hosting hosting ironpython.runtime.operations import pythonops import system system.reflection import emit system.reflection.emit import opcodes, assemblybuilderaccess system.reflection import assemblyname, typeattributes, methodattributes  def generateexe(name, targetkind, platform, machine, main_module):     """generates stub .exe file starting app"""         aname = assemblyname(system.io.fileinfo(name).name)     ab = pythonops.definedynamicassembly(aname, assemblybuilderaccess.runandsave)     mb = ab.definedynamicmodule(name,  aname.name + '.exe')     tb = mb.definetype('pythonmain', typeattributes.public)     mainmethod = tb.definemethod('main', methodattributes.public | methodattributes.static, int, ())     gen = mainmethod.getilgenerator()          # scriptcode assembly...         gen.emit(opcodes.ldstr, name + ".dll")     gen.emitcall(opcodes.call, clr.getclrtype(system.io.path).getmethod("getfullpath", (clr.getclrtype(str), )), ())     gen.emitcall(opcodes.call, clr.getclrtype(system.reflection.assembly).getmethod("loadfile", (clr.getclrtype(str), )), ())          # emit module name     gen.emit(opcodes.ldstr, system.io.path.getfilenamewithoutextension(main_module))          gen.emit(opcodes.ldnull)          # call initializemodule     gen.emitcall(opcodes.call, clr.getclrtype(pythonops).getmethod("initializemodule"), ())         gen.emit(opcodes.ret)          tb.createtype()     ab.setentrypoint(mainmethod, targetkind)     ab.save(aname.name + '.exe', platform, machine)      def main(args):     files = []     main = none          # main file start execution (passed pythoncompiler)     main_name = none     # file drive name of assembly if "output" not provided     output = none        # output assembly name     target = system.reflection.emit.pefilekinds.dll     platform = system.reflection.portableexecutablekinds.ilonly     machine  = system.reflection.imagefilemachine.i386      arg in args:         if arg.startswith("/main:"):             main_name = main = arg[6:]             target = system.reflection.emit.pefilekinds.consoleapplication                  elif arg.startswith("/out:"):             output = arg[5:]                      elif arg.startswith("/target:"):             tgt = arg[8:]             if tgt == "exe": target = system.reflection.emit.pefilekinds.consoleapplication             elif tgt == "winexe": target = system.reflection.emit.pefilekinds.windowapplication             else: target = system.reflection.emit.pefilekinds.dll          elif arg.startswith("/platform:"):             pform = arg[10:]             if pform == "x86":                 platform = system.reflection.portableexecutablekinds.ilonly | system.reflection.portableexecutablekinds.required32bit                 machine  = system.reflection.imagefilemachine.i386             elif pform == "x64":                 platform = system.reflection.portableexecutablekinds.ilonly | system.reflection.portableexecutablekinds.pe32plus                 machine  = system.reflection.imagefilemachine.amd64             else:                 platform = system.reflection.portableexecutablekinds.ilonly                 machine  = system.reflection.imagefilemachine.i386          elif arg in ["/?", "-?", "/h", "-h"]:             print __doc__             sys.exit(0)          else:             files.append(arg)      if not files , not main_name:         print __doc__         sys.exit(0)      if not output , main_name:         output = system.io.path.getfilenamewithoutextension(main_name)     elif not output , files:         output = system.io.path.getfilenamewithoutextension(files[0])              print "input files:"     file in files:         print "\t%s" % file      print "output:\n\t%s" % output     print "target:\n\t%s" % target     print 'platform:\n\t%s' % platform     print 'machine:\n\t%s' % machine      print 'compiling...'         clr.compilemodules(output + '.dll', mainmodule = main_name, *files)          if target != system.reflection.emit.pefilekinds.dll:         generateexe(output, target, platform, machine, main_name)          print 'saved %s' % (output, )  if __name__ == "__main__":     main(sys.argv[1:])
you can chmod , run:
code:
ipy pyc.py input.py /target:exe


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] ironpython: compile .py file?


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support