#!/usr/bin/env pythonfromdistutils.coreimportsetupfromdistutils.command.buildimportbuildfromdistutils.dep_utilimportnewer_group,newerfromdistutils.spawnimportspawnfromsubprocessimportPopen,PIPEfromreimportcompilefromfileinputimportinputfromosimportmkdir,removefromos.pathimportexistsfromsysimportexecutable,version_infopc_raw=Popen("parrot_config --dump",shell=True,stdout=PIPE).stdout.readlines()ifnotpc_raw:print("\nplease check parrot_config is in your PATH!")exit(1)pc={}rx=compile("(.*) => '(.*)'")forlinpc_raw:ifversion_info[0]==3:l=l.decode()m=rx.match(l)ifm:pc[m.group(1)]=m.group(2)pv=pc['VERSION'].split('.')ifint(pv[0])==0or(int(pv[0])==1andint(pv[1])<4):print("\nPlease use Parrot version 1.4 or higher")exit(1)PARROT="%s/parrot%s"%(pc['bindir'],pc['exe'])GRAMMAR_GEN="%s/%s/library/PGE/Perl6Grammar.pbc"%(pc['libdir'],pc['versiondir'])NQP="%s/%s/languages/nqp/nqp.pbc"%(pc['libdir'],pc['versiondir'])PCT="%s/library/PCT.pbc"%pc['libdir']PBC_TO_EXE="%s/pbc_to_exe%s"%(pc['bindir'],pc['exe'])GEN_SOURCES=['include/gen_grammar.pir','include/gen_actions.pir','include/gen_builtins.pir',]SOURCES=GEN_SOURCES+['pynie.pir','src/parser/indent.pir']BUILTINS_PIR=['src/builtins/funcs.pir','src/builtins/helper.pir','src/builtins/io.pir','src/builtins/lists.pir','src/builtins/oper.pir','Objects/typeobject.pir','Objects/listobject.pir','Objects/stringobject.pir','Objects/dictobject.pir',]CLEANUPS=GEN_SOURCES+['pynie.pbc','pynie.o','pynie.c','pynie%s'%pc['exe'],'installable_pynie%s'%pc['exe']]defreal_build():ifnotexists('include'):mkdir('include')ifnewer_group(BUILTINS_PIR,'include/gen_builtins.pir'):f=open('include/gen_builtins.pir','w')forlininput(BUILTINS_PIR):f.write(l)f.close()ifnewer('Grammar/Grammar.pg','include/gen_grammar.pir'):spawn([PARROT,GRAMMAR_GEN,'--output=include/gen_grammar.pir','Grammar/Grammar.pg'])ifnewer('Grammar/Actions.nqp','include/gen_actions.pir'):spawn([PARROT,NQP,'--output=include/gen_actions.pir','--encoding=fixed_8','--target=pir','Grammar/Actions.nqp'])ifnewer_group(SOURCES+BUILTINS_PIR,'pynie.pbc'):spawn([PARROT,'-o','pynie.pbc','pynie.pir'])ifnewer('pynie.pbc','pynie%s'%pc['exe']):spawn([PBC_TO_EXE,'pynie.pbc'])classbuild_pynie(build):defrun(self):real_build()build.run(self)classtest_pynie(build):defrun(self):real_build()spawn([executable,'runtests.py'])build.run(self)classclean_pynie(build):defrun(self):[remove(f)forfinCLEANUPSifexists(f)]build.run(self)classhelp_pynie(build):defrun(self):print(""" Following targets are available for the user: build: pynie.pbc and pynie executable This is the default. test: Run the test suite. clean: Basic cleaning up. help: Print this help message. """)setup(name='Pynie',version='0.1',description='Pynie - Python on Parrot',url='http://code.google.com/p/pynie/',cmdclass={'build':build_pynie,'clean':clean_pynie,'test':test_pynie,'help':help_pynie,})