pynie / setup.py

#!/usr/bin/env python

from distutils.core import setup
from distutils.command.build import build
from distutils.dep_util import newer_group, newer
from distutils.spawn import spawn
from subprocess import Popen,PIPE
from re import compile
from fileinput import input
from os import mkdir, remove
from os.path import exists
from sys import executable, version_info

pc_raw = Popen("parrot_config --dump", shell=True, stdout=PIPE).stdout.readlines()
if not pc_raw:
    print("\nplease check parrot_config is in your PATH!")
    exit(1)

pc = {}
rx = compile("(.*) => '(.*)'")

for l in pc_raw:
    if version_info[0] == 3:
        l = l.decode()
    m = rx.match(l)
    if m:
        pc[m.group(1)] = m.group(2)

pv = pc['VERSION'].split('.')
if int(pv[0]) == 0 or (int(pv[0]) == 1 and int(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',
  'src/classes/pynietype.pir',
  'src/classes/pynielist.pir',
  'src/classes/pyniestr.pir',
  ]

CLEANUPS = GEN_SOURCES + [
  'pynie.pbc',
  'pynie%s' % pc['exe'],
  'installable_pynie%s' % pc['exe'] ]

def real_build():
    if not exists('include'):
        mkdir('include')

    if newer_group(BUILTINS_PIR, 'include/gen_builtins.pir'):
        f = open('include/gen_builtins.pir', 'w')
        for l in input(BUILTINS_PIR): f.write(l)
        f.close()

    if newer('Grammar/Grammar.pg', 'include/gen_grammar.pir'):
        spawn([PARROT, GRAMMAR_GEN, '--output=include/gen_grammar.pir', 'Grammar/Grammar.pg'])

    if newer('Grammar/Actions.nqp','include/gen_actions.pir'):
        spawn([PARROT, NQP, '--output=include/gen_actions.pir', '--encoding=fixed_8', '--target=pir', 'Grammar/Actions.nqp'])

    if newer_group(SOURCES + BUILTINS_PIR, 'pynie.pbc'):
        spawn([PARROT, '-o', 'pynie.pbc', 'pynie.pir'])

    if newer('pynie.pbc', 'pynie%s' % pc['exe']):
        spawn([PBC_TO_EXE, 'pynie.pbc'])

class build_pynie(build):
    def run(self):
        real_build()
        build.run(self)

class test_pynie(build):
    def run(self):
        real_build()
        spawn([executable, 'runtests.py'])
        build.run(self)

class clean_pynie(build):
    def run(self):
        [remove(f) for f in CLEANUPS if exists(f)]
        build.run(self)


class help_pynie(build):
    def run(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,
      }
)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.