Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial

  • Loading branch information...
commit 995bd7b2c9035c44acc84508518bcffef5219e6e 0 parents
shomah4a authored
260 bootstrap.py
... ... @@ -0,0 +1,260 @@
  1 +##############################################################################
  2 +#
  3 +# Copyright (c) 2006 Zope Foundation and Contributors.
  4 +# All Rights Reserved.
  5 +#
  6 +# This software is subject to the provisions of the Zope Public License,
  7 +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8 +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9 +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10 +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11 +# FOR A PARTICULAR PURPOSE.
  12 +#
  13 +##############################################################################
  14 +"""Bootstrap a buildout-based project
  15 +
  16 +Simply run this script in a directory containing a buildout.cfg.
  17 +The script accepts buildout command-line options, so you can
  18 +use the -c option to specify an alternate configuration file.
  19 +"""
  20 +
  21 +import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
  22 +from optparse import OptionParser
  23 +
  24 +if sys.platform == 'win32':
  25 + def quote(c):
  26 + if ' ' in c:
  27 + return '"%s"' % c # work around spawn lamosity on windows
  28 + else:
  29 + return c
  30 +else:
  31 + quote = str
  32 +
  33 +# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
  34 +stdout, stderr = subprocess.Popen(
  35 + [sys.executable, '-Sc',
  36 + 'try:\n'
  37 + ' import ConfigParser\n'
  38 + 'except ImportError:\n'
  39 + ' print 1\n'
  40 + 'else:\n'
  41 + ' print 0\n'],
  42 + stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  43 +has_broken_dash_S = bool(int(stdout.strip()))
  44 +
  45 +# In order to be more robust in the face of system Pythons, we want to
  46 +# run without site-packages loaded. This is somewhat tricky, in
  47 +# particular because Python 2.6's distutils imports site, so starting
  48 +# with the -S flag is not sufficient. However, we'll start with that:
  49 +if not has_broken_dash_S and 'site' in sys.modules:
  50 + # We will restart with python -S.
  51 + args = sys.argv[:]
  52 + args[0:0] = [sys.executable, '-S']
  53 + args = map(quote, args)
  54 + os.execv(sys.executable, args)
  55 +# Now we are running with -S. We'll get the clean sys.path, import site
  56 +# because distutils will do it later, and then reset the path and clean
  57 +# out any namespace packages from site-packages that might have been
  58 +# loaded by .pth files.
  59 +clean_path = sys.path[:]
  60 +import site
  61 +sys.path[:] = clean_path
  62 +for k, v in sys.modules.items():
  63 + if k in ('setuptools', 'pkg_resources') or (
  64 + hasattr(v, '__path__') and
  65 + len(v.__path__)==1 and
  66 + not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
  67 + # This is a namespace package. Remove it.
  68 + sys.modules.pop(k)
  69 +
  70 +is_jython = sys.platform.startswith('java')
  71 +
  72 +setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
  73 +distribute_source = 'http://python-distribute.org/distribute_setup.py'
  74 +
  75 +# parsing arguments
  76 +def normalize_to_url(option, opt_str, value, parser):
  77 + if value:
  78 + if '://' not in value: # It doesn't smell like a URL.
  79 + value = 'file://%s' % (
  80 + urllib.pathname2url(
  81 + os.path.abspath(os.path.expanduser(value))),)
  82 + if opt_str == '--download-base' and not value.endswith('/'):
  83 + # Download base needs a trailing slash to make the world happy.
  84 + value += '/'
  85 + else:
  86 + value = None
  87 + name = opt_str[2:].replace('-', '_')
  88 + setattr(parser.values, name, value)
  89 +
  90 +usage = '''\
  91 +[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
  92 +
  93 +Bootstraps a buildout-based project.
  94 +
  95 +Simply run this script in a directory containing a buildout.cfg, using the
  96 +Python that you want bin/buildout to use.
  97 +
  98 +Note that by using --setup-source and --download-base to point to
  99 +local resources, you can keep this script from going over the network.
  100 +'''
  101 +
  102 +parser = OptionParser(usage=usage)
  103 +parser.add_option("-v", "--version", dest="version",
  104 + help="use a specific zc.buildout version")
  105 +parser.add_option("-d", "--distribute",
  106 + action="store_true", dest="use_distribute", default=False,
  107 + help="Use Distribute rather than Setuptools.")
  108 +parser.add_option("--setup-source", action="callback", dest="setup_source",
  109 + callback=normalize_to_url, nargs=1, type="string",
  110 + help=("Specify a URL or file location for the setup file. "
  111 + "If you use Setuptools, this will default to " +
  112 + setuptools_source + "; if you use Distribute, this "
  113 + "will default to " + distribute_source +"."))
  114 +parser.add_option("--download-base", action="callback", dest="download_base",
  115 + callback=normalize_to_url, nargs=1, type="string",
  116 + help=("Specify a URL or directory for downloading "
  117 + "zc.buildout and either Setuptools or Distribute. "
  118 + "Defaults to PyPI."))
  119 +parser.add_option("--eggs",
  120 + help=("Specify a directory for storing eggs. Defaults to "
  121 + "a temporary directory that is deleted when the "
  122 + "bootstrap script completes."))
  123 +parser.add_option("-t", "--accept-buildout-test-releases",
  124 + dest='accept_buildout_test_releases',
  125 + action="store_true", default=False,
  126 + help=("Normally, if you do not specify a --version, the "
  127 + "bootstrap script and buildout gets the newest "
  128 + "*final* versions of zc.buildout and its recipes and "
  129 + "extensions for you. If you use this flag, "
  130 + "bootstrap and buildout will get the newest releases "
  131 + "even if they are alphas or betas."))
  132 +parser.add_option("-c", None, action="store", dest="config_file",
  133 + help=("Specify the path to the buildout configuration "
  134 + "file to be used."))
  135 +
  136 +options, args = parser.parse_args()
  137 +
  138 +# if -c was provided, we push it back into args for buildout's main function
  139 +if options.config_file is not None:
  140 + args += ['-c', options.config_file]
  141 +
  142 +if options.eggs:
  143 + eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
  144 +else:
  145 + eggs_dir = tempfile.mkdtemp()
  146 +
  147 +if options.setup_source is None:
  148 + if options.use_distribute:
  149 + options.setup_source = distribute_source
  150 + else:
  151 + options.setup_source = setuptools_source
  152 +
  153 +if options.accept_buildout_test_releases:
  154 + args.append('buildout:accept-buildout-test-releases=true')
  155 +args.append('bootstrap')
  156 +
  157 +try:
  158 + import pkg_resources
  159 + import setuptools # A flag. Sometimes pkg_resources is installed alone.
  160 + if not hasattr(pkg_resources, '_distribute'):
  161 + raise ImportError
  162 +except ImportError:
  163 + ez_code = urllib2.urlopen(
  164 + options.setup_source).read().replace('\r\n', '\n')
  165 + ez = {}
  166 + exec ez_code in ez
  167 + setup_args = dict(to_dir=eggs_dir, download_delay=0)
  168 + if options.download_base:
  169 + setup_args['download_base'] = options.download_base
  170 + if options.use_distribute:
  171 + setup_args['no_fake'] = True
  172 + ez['use_setuptools'](**setup_args)
  173 + if 'pkg_resources' in sys.modules:
  174 + reload(sys.modules['pkg_resources'])
  175 + import pkg_resources
  176 + # This does not (always?) update the default working set. We will
  177 + # do it.
  178 + for path in sys.path:
  179 + if path not in pkg_resources.working_set.entries:
  180 + pkg_resources.working_set.add_entry(path)
  181 +
  182 +cmd = [quote(sys.executable),
  183 + '-c',
  184 + quote('from setuptools.command.easy_install import main; main()'),
  185 + '-mqNxd',
  186 + quote(eggs_dir)]
  187 +
  188 +if not has_broken_dash_S:
  189 + cmd.insert(1, '-S')
  190 +
  191 +find_links = options.download_base
  192 +if not find_links:
  193 + find_links = os.environ.get('bootstrap-testing-find-links')
  194 +if find_links:
  195 + cmd.extend(['-f', quote(find_links)])
  196 +
  197 +if options.use_distribute:
  198 + setup_requirement = 'distribute'
  199 +else:
  200 + setup_requirement = 'setuptools'
  201 +ws = pkg_resources.working_set
  202 +setup_requirement_path = ws.find(
  203 + pkg_resources.Requirement.parse(setup_requirement)).location
  204 +env = dict(
  205 + os.environ,
  206 + PYTHONPATH=setup_requirement_path)
  207 +
  208 +requirement = 'zc.buildout'
  209 +version = options.version
  210 +if version is None and not options.accept_buildout_test_releases:
  211 + # Figure out the most recent final version of zc.buildout.
  212 + import setuptools.package_index
  213 + _final_parts = '*final-', '*final'
  214 + def _final_version(parsed_version):
  215 + for part in parsed_version:
  216 + if (part[:1] == '*') and (part not in _final_parts):
  217 + return False
  218 + return True
  219 + index = setuptools.package_index.PackageIndex(
  220 + search_path=[setup_requirement_path])
  221 + if find_links:
  222 + index.add_find_links((find_links,))
  223 + req = pkg_resources.Requirement.parse(requirement)
  224 + if index.obtain(req) is not None:
  225 + best = []
  226 + bestv = None
  227 + for dist in index[req.project_name]:
  228 + distv = dist.parsed_version
  229 + if _final_version(distv):
  230 + if bestv is None or distv > bestv:
  231 + best = [dist]
  232 + bestv = distv
  233 + elif distv == bestv:
  234 + best.append(dist)
  235 + if best:
  236 + best.sort()
  237 + version = best[-1].version
  238 +if version:
  239 + requirement = '=='.join((requirement, version))
  240 +cmd.append(requirement)
  241 +
  242 +if is_jython:
  243 + import subprocess
  244 + exitcode = subprocess.Popen(cmd, env=env).wait()
  245 +else: # Windows prefers this, apparently; otherwise we would prefer subprocess
  246 + exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
  247 +if exitcode != 0:
  248 + sys.stdout.flush()
  249 + sys.stderr.flush()
  250 + print ("An error occurred when trying to install zc.buildout. "
  251 + "Look above this message for any errors that "
  252 + "were output by easy_install.")
  253 + sys.exit(exitcode)
  254 +
  255 +ws.add_entry(eggs_dir)
  256 +ws.require(requirement)
  257 +import zc.buildout.buildout
  258 +zc.buildout.buildout.main(args)
  259 +if not options.eggs: # clean up temporary egg directory
  260 + shutil.rmtree(eggs_dir)
88 buildout.cfg
... ... @@ -0,0 +1,88 @@
  1 +[buildout]
  2 +parts = env ipython sphinx nose pylint epydoc
  3 +develop =
  4 + .
  5 +
  6 +pkgname = metapy
  7 +
  8 +
  9 +[env]
  10 +recipe = zc.recipe.egg
  11 +
  12 +eggs =
  13 + zc.recipe.egg
  14 + metapy
  15 +
  16 +
  17 +interpreter = python
  18 +
  19 +[ipython]
  20 +recipe = zc.recipe.egg
  21 +eggs =
  22 + ${env:eggs}
  23 + ipython
  24 +
  25 +
  26 +[sphinx]
  27 +recipe = collective.recipe.sphinxbuilder
  28 +build = ${buildout:directory}/docs
  29 +source = ${buildout:directory}/sphinx
  30 +outputs = html
  31 +script-name = make-docs
  32 +extra-paths = ${buildout:directory}
  33 +
  34 +
  35 +[noseenv]
  36 +recipe = zc.recipe.egg
  37 +eggs =
  38 + ${env:eggs}
  39 + coverage==3.4
  40 +
  41 +
  42 +[nose]
  43 +recipe = pbp.recipe.noserunner
  44 +eggs =
  45 + ${noseenv:eggs}
  46 + nosexcover==1.0.5
  47 + nosecolor
  48 + unittest-xml-reporting
  49 + pbp.recipe.noserunner
  50 +
  51 +working-directory = ${buildout:directory}/test
  52 +
  53 +defaults =
  54 + --verbosity=3
  55 + --with-doctest
  56 + --doctest-extension=txt
  57 + --cover-erase
  58 + --cover-package=${buildout:pkgname}
  59 + --cover-html
  60 + --cover-html-dir=${buildout:directory}/docs/coverage
  61 + --with-xcoverage
  62 + --with-xunit
  63 +
  64 +
  65 +[pylint]
  66 +recipe = zc.recipe.egg
  67 +eggs =
  68 + ${env:eggs}
  69 + pylint
  70 +
  71 +entry-points = pylint=pylint.lint:Run
  72 +arguments = sys.argv[1:]+[
  73 + '--output-format=html',
  74 + '--import-graph=${buildout:directory}/docs/pylint_${buildout:pkgname}.dot',
  75 + '--ext-import-graph=${buildout:directory}/docs/pylint_${buildout:pkgname}_external.dot',
  76 + '--int-import-graph=${buildout:directory}/docs/pylint_${buildout:pkgname}_internal.dot',
  77 + '--init-import=y',
  78 + '${buildout:directory}/${buildout:pkgname}']
  79 +
  80 +
  81 +[epydoc]
  82 +recipe = z3c.recipe.epydoc
  83 +eggs =
  84 + ${env:eggs}
  85 + z3c.recipe.epydoc
  86 +doc = ${buildout:pkgname}
  87 +
  88 +
2  metapy/__init__.py
... ... @@ -0,0 +1,2 @@
  1 +#-*- coding:utf-8 -*-
  2 +
43 metapy/base.py
... ... @@ -0,0 +1,43 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +
  4 +import sys
  5 +
  6 +
  7 +def make_environ(globals, locals):
  8 +
  9 + frame = sys._getframe()
  10 +
  11 + if globals is None:
  12 + globals = frame.f_back.f_back.f_globals
  13 +
  14 + if locals is None:
  15 + locals = frame.f_back.f_back.f_locals
  16 +
  17 +
  18 + return globals, locals
  19 +
  20 +
  21 +
  22 +class Element(object):
  23 + u'''
  24 + 構文オブジェクト
  25 + '''
  26 +
  27 + def evaluate(self, globals=None, locals=None):
  28 +
  29 + g, l = make_environ(globals, locals)
  30 +
  31 + return eval(self._make_string({}), g, l)
  32 +
  33 +
  34 + def execute(self, globals=None, locals=None):
  35 +
  36 + g, l = make_environ(globals, locals)
  37 +
  38 + exec self._make_string({}) in g, l
  39 +
  40 +
  41 +
  42 +
  43 +
73 metapy/blocks.py
... ... @@ -0,0 +1,73 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import base
  4 +import expressions
  5 +
  6 +import statements
  7 +
  8 +
  9 +class Block(statements.Statement):
  10 + u'''
  11 + ブロック要素
  12 +
  13 + :param statements: 複数文
  14 + :param
  15 +
  16 + '''
  17 +
  18 + def __init__(self, statements):
  19 +
  20 + self.statements = statements
  21 +
  22 +
  23 +
  24 + def _make_block(self, env):
  25 +
  26 + state = self.statements
  27 +
  28 + if isinstance(state, statements.Statement):
  29 + state = [state]
  30 +
  31 +
  32 + return '\n'.join(sum((
  33 + [' ' + y for y in x._make_string(env).splitlines()]
  34 + for x in state), []))
  35 +
  36 +
  37 +
  38 + def _make_string(self, env):
  39 +
  40 + head = self._make_head(env)
  41 +
  42 + return head + '\n' + self._make_block(env)
  43 +
  44 +
  45 +
  46 +
  47 +class For(Block):
  48 + u'''
  49 + for 文
  50 +
  51 + :param var: イテレート変数
  52 + :type var: :py:class:`expressions.Symbol`
  53 + :param iterable: 式
  54 + :type iterable: :py:class:`base.Expression`
  55 + :param statements: 文
  56 + :type statements: :py:class:`base.Statements`
  57 + '''
  58 +
  59 +
  60 + def __init__(self, var, iterable, statements=statements.Pass()):
  61 +
  62 + super(For, self).__init__(statements)
  63 +
  64 + self.var = var
  65 + self.iterable = iterable
  66 +
  67 +
  68 +
  69 + def _make_head(self, env):
  70 +
  71 + return 'for {0} in {1}:'.format(self.var._make_string(env),
  72 + self.iterable._make_string(env))
  73 +
227 metapy/expressions.py
... ... @@ -0,0 +1,227 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import base
  4 +
  5 +import statements
  6 +
  7 +
  8 +
  9 +class Expression(statements.Statement):
  10 + u'''
  11 + 式
  12 + '''
  13 +
  14 +
  15 +
  16 +def __makeop():
  17 +
  18 +
  19 + def make_operation(op):
  20 +
  21 + def operation(self, other):
  22 +
  23 + if not isinstance(other, Expression):
  24 + other = Literal(other)
  25 +
  26 + return Binary(self, Operator(op), other)
  27 +
  28 + return operation
  29 +
  30 +
  31 +
  32 + def make_roperation(op):
  33 +
  34 + def operation(self, other):
  35 +
  36 + if not isinstance(other, Expression):
  37 + other = Literal(other)
  38 +
  39 + return Binary(other, Operator(op), self)
  40 +
  41 + return operation
  42 +
  43 +
  44 + def make_single(op):
  45 +
  46 + def operation(self):
  47 +
  48 + return Unary(Operator(op), self)
  49 +
  50 +
  51 + compare = [
  52 + ('lt', '<'),
  53 + ('le', '<='),
  54 + ('eq', '=='),
  55 + ('ne', '!='),
  56 + ('gt', '>'),
  57 + ('ge', '>=')
  58 + ]
  59 +
  60 +
  61 + arismethic = [
  62 + ('add', '+'),
  63 + ('sub', '-'),
  64 + ('mul', '*'),
  65 + ('div', '/'),
  66 + ('floordiv', '//'),
  67 + ('mod', '%'),
  68 + ('pow', '**'),
  69 + ('lshift', '<<'),
  70 + ('rshift', '>>'),
  71 + ('and', '&'),
  72 + ('xor', '^'),
  73 + ('or', '|'),
  74 + ]
  75 +
  76 + single = [
  77 + ('neg', '-'),
  78 + ('pos', '+'),
  79 + ('invert', '~'),
  80 + ]
  81 +
  82 + for m, op in compare+arismethic:
  83 +
  84 + n = '__{0}__'.format(m)
  85 +
  86 + setattr(Expression, n, make_operation(op))
  87 +
  88 +
  89 + for m, op in compare+arismethic:
  90 +
  91 + n = '__r{0}__'.format(m)
  92 +
  93 + setattr(Expression, n, make_roperation(op))
  94 +
  95 +
  96 +__makeop()
  97 +
  98 +
  99 +
  100 +class Paren(Expression):
  101 + u'''
  102 + 括弧
  103 + '''
  104 +
  105 + def __init__(self, exp):
  106 +
  107 + self.expression = exp
  108 +
  109 +
  110 +
  111 +
  112 +class Operator(base.Element):
  113 + u'''
  114 + オペレータ
  115 + '''
  116 +
  117 + def __init__(self, symbol):
  118 + u'''
  119 + 演算子
  120 + '''
  121 +
  122 + self.symbol = symbol
  123 +
  124 +
  125 + def _make_string(self, env):
  126 +
  127 + return self.symbol
  128 +
  129 +
  130 +
  131 +
  132 +class Binary(Expression):
  133 + u'''
  134 + 二項演算
  135 +
  136 + :param lop: 左辺
  137 + :type lop: :py:class:`base.Expression`
  138 + :param op: 演算子
  139 + :type op: :py:class:`Operator`
  140 + :param rop: 右辺
  141 + :type rop: :py:class:`base.Expression`
  142 +
  143 + '''
  144 +
  145 +
  146 + def __init__(self, lval, op, rval):
  147 +
  148 + self.lval = lval
  149 + self.op = op
  150 + self.rval = rval
  151 +
  152 +
  153 +
  154 + def _make_string(self, env):
  155 + u'''
  156 + 文字列を作る
  157 + '''
  158 +
  159 + return u'{0} {1} {2}'.format(self.lval._make_string(env),
  160 + self.op._make_string(env),
  161 + self.rval._make_string(env))
  162 +
  163 +
  164 +class Unary(Expression):
  165 + u'''
  166 + 単項演算
  167 +
  168 + :param op: 演算子
  169 + :type op: :py:class:`Operator`
  170 + :param val: 演算対象
  171 + :type val: :py:class:`Expression`
  172 + '''
  173 +
  174 +
  175 + def __init__(self, op, val):
  176 +
  177 + self.operator = op
  178 + self.value = val
  179 +
  180 +
  181 +
  182 + def _make_string(self, env):
  183 +
  184 + return u'{0} {1}'.format(self.operator._make_string(env),
  185 + self.value._make_string(env))
  186 +
  187 +
  188 +
  189 +
  190 +
  191 +class Literal(Expression):
  192 + u'''
  193 + 即値
  194 +
  195 + :param value: 値
  196 + '''
  197 +
  198 + def __init__(self, value):
  199 +
  200 + self.value = value
  201 +
  202 +
  203 + def _make_string(self, env):
  204 +
  205 + return repr(self.value)
  206 +
  207 +
  208 +
  209 +class Symbol(Expression):
  210 + u'''
  211 + 変数とか
  212 +
  213 + :param name: シンボル名
  214 + '''
  215 +
  216 + def __init__(self, name):
  217 +
  218 + self.name = name
  219 +
  220 +
  221 + def _make_string(self, env):
  222 +
  223 + return self.name
  224 +
  225 +
  226 +
  227 +
77 metapy/statements.py
... ... @@ -0,0 +1,77 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import base
  4 +
  5 +
  6 +
  7 +class Statement(base.Element):
  8 + u'''
  9 + 文
  10 + '''
  11 +
  12 + def next(self, st):
  13 +
  14 + return StatementList([self, st])
  15 +
  16 +
  17 +
  18 +class StatementList(Statement):
  19 +
  20 +
  21 + def __init__(self, stlist):
  22 +
  23 + self.statements = stlist
  24 +
  25 +
  26 + def next(self, st):
  27 +
  28 + return StatementList(self.statements+[st])
  29 +
  30 +
  31 + def _make_string(self, env):
  32 +
  33 + return '\n'.join([x._make_string(env) for x in self.statements])
  34 +
  35 +
  36 +
  37 +
  38 +class Print(Statement):
  39 + u'''
  40 + print 文
  41 +
  42 + :param exps: 式
  43 + :type exps: [:py:class:`base.Expression`]
  44 +
  45 + :param output: 出力先
  46 + :param output: :py:class:`base.Expression`
  47 + '''
  48 +
  49 + def __init__(self, *args, **argd):
  50 +
  51 + self.exps = args
  52 + self.output = argd.get('file')
  53 +
  54 +
  55 +
  56 + def _make_string(self, env):
  57 +
  58 + tgt = ','.join(x._make_string(env) for x in self.exps)
  59 +
  60 + if self.output is not None:
  61 + return 'print >> {0}, {1}'.format(self.output._make_string(env),
  62 + tgt)
  63 + else:
  64 + return 'print {0}'.format(tgt)
  65 +
  66 +
  67 +
  68 +class Pass(Statement):
  69 + u'''
  70 + なにもしない
  71 + '''
  72 +
  73 +
  74 + def _make_string(self, env):
  75 +
  76 + return 'pass'
  77 +
5 metapy/symbols.py
... ... @@ -0,0 +1,5 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +
  4 +class Atom(object):
  5 + pass
13 setup.py
... ... @@ -0,0 +1,13 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import setuptools
  4 +
  5 +version = '0.0.1'
  6 +
  7 +setuptools.setup(
  8 + name='metapy',
  9 + packages=['metapy'],
  10 + install_requires=[
  11 + ],
  12 + version=version)
  13 +
41 test/test_expressions.py
... ... @@ -0,0 +1,41 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import sys
  4 +
  5 +from metapy.expressions import Symbol, Literal
  6 +from metapy.blocks import For
  7 +from metapy.statements import Print, Pass
  8 +
  9 +
  10 +
  11 +def test_expressions():
  12 +
  13 + op = Literal(10) * Symbol('aaa')
  14 +
  15 + print op._make_string({})
  16 +
  17 + assert op._make_string({}) == '10 * aaa'
  18 +
  19 + it = Symbol('it')
  20 + it2 = Symbol('it2')
  21 +
  22 + p = Print(it * it2)
  23 +
  24 + f = For(it, Literal(range(10)), p)
  25 +
  26 + f2 = For(it2, Literal(range(5)), f)
  27 +
  28 + print f2._make_string({})
  29 +
  30 + f2.execute()
  31 +
  32 +
  33 +
  34 +def test_expression2():
  35 +
  36 + aa = 10
  37 +
  38 + assert (Literal(10) * Symbol('aa')).evaluate() == 100
  39 +
  40 +
  41 +
13 test/test_statements.py
... ... @@ -0,0 +1,13 @@
  1 +#-*- coding:utf-8 -*-
  2 +
  3 +import sys
  4 +
  5 +from metapy.expressions import Symbol, Literal
  6 +from metapy.blocks import For
  7 +from metapy.statements import Print, Pass
  8 +
  9 +
  10 +
  11 +def test_print():
  12 +
  13 + Print(Literal('aaa')).next(Print(Literal('bbb'))).execute()

0 comments on commit 995bd7b

Please sign in to comment.
Something went wrong with that request. Please try again.