コード例 #1
0
def _pop_values(values_dct, key):
    """Remove values from the dictionary and convert them as a list"""
    vals_str = values_dct.pop(key, '')
    if not vals_str:
        return
    fields = []
    # the line separator is \n for setup.cfg files
    for field in vals_str.split('\n'):
        tmp_vals = field.split('--')
        if len(tmp_vals) == 2 and not interpret(tmp_vals[1]):
            continue
        fields.append(tmp_vals[0])
    # Get bash options like `gcc -print-file-name=libgcc.a` XXX bash options?
    vals = split(' '.join(fields))
    if vals:
        return vals
コード例 #2
0
ファイル: config.py プロジェクト: pombredanne/distutils2
def _pop_values(values_dct, key):
    """Remove values from the dictionary and convert them as a list"""
    vals_str = values_dct.pop(key, "")
    if not vals_str:
        return
    fields = []
    # the line separator is \n for setup.cfg files
    for field in vals_str.split("\n"):
        tmp_vals = field.split("--")
        if len(tmp_vals) == 2 and not interpret(tmp_vals[1]):
            continue
        fields.append(tmp_vals[0])
    # Get bash options like `gcc -print-file-name=libgcc.a` XXX bash options?
    # kludge around shlex not supporting unicode
    vals = u" ".join(fields).encode("utf-8")
    vals = split(vals)
    if vals:
        return [val.decode("utf-8") for val in vals]
コード例 #3
0
ファイル: metadata.py プロジェクト: pombredanne/distutils2
 def _platform(self, value):
     if not self.platform_dependent or ";" not in value:
         return True, value
     value, marker = value.split(";")
     return interpret(marker, self.execution_context), value
コード例 #4
0
ファイル: test_markers.py プロジェクト: dstufft/distutils2
    def test_interpret(self):
        sys_platform = sys.platform
        version = sys.version.split()[0]
        os_name = os.name
        platform_version = platform.version()
        platform_machine = platform.machine()
        platform_python_implementation = python_implementation()

        self.assertTrue(interpret("sys.platform == '%s'" % sys_platform))
        self.assertTrue(interpret(
            "sys.platform == '%s' and python_full_version == '%s'" %
            (sys_platform, version)))
        self.assertTrue(interpret("'%s' == sys.platform" % sys_platform))
        self.assertTrue(interpret('os.name == "%s"' % os_name))
        self.assertTrue(interpret(
            'platform.version == "%s" and platform.machine == "%s"' %
            (platform_version, platform_machine)))
        self.assertTrue(interpret('platform.python_implementation == "%s"' %
            platform_python_implementation))

        # stuff that need to raise a syntax error
        ops = ('os.name == os.name', 'os.name == 2', "'2' == '2'",
               'okpjonon', '', 'os.name ==', 'python_version == 2.4')
        for op in ops:
            self.assertRaises(SyntaxError, interpret, op)

        # combined operations
        OP = 'os.name == "%s"' % os_name
        FALSEOP = 'os.name == "buuuu"'
        AND = ' and '
        OR = ' or '
        self.assertTrue(interpret(OP + AND + OP))
        self.assertTrue(interpret(OP + AND + OP + AND + OP))
        self.assertTrue(interpret(OP + OR + OP))
        self.assertTrue(interpret(OP + OR + FALSEOP))
        self.assertTrue(interpret(OP + OR + OP + OR + FALSEOP))
        self.assertTrue(interpret(OP + OR + FALSEOP + OR + FALSEOP))
        self.assertTrue(interpret(FALSEOP + OR + OP))
        self.assertFalse(interpret(FALSEOP + AND + FALSEOP))
        self.assertFalse(interpret(FALSEOP + OR + FALSEOP))

        # other operators
        self.assertTrue(interpret("os.name != 'buuuu'"))
        self.assertTrue(interpret("python_version > '1.0'"))
        self.assertTrue(interpret("python_version < '5.0'"))
        self.assertTrue(interpret("python_version <= '5.0'"))
        self.assertTrue(interpret("python_version >= '1.0'"))
        self.assertTrue(interpret("'%s' in os.name" % os_name))
        self.assertTrue(interpret("'buuuu' not in os.name"))
        self.assertTrue(interpret(
            "'buuuu' not in os.name and '%s' in os.name" % os_name))

        # execution context
        self.assertTrue(interpret('python_version == "0.1"',
                                  {'python_version': '0.1'}))
コード例 #5
0
    def test_interpret(self):
        sys_platform = sys.platform
        version = sys.version.split()[0]
        os_name = os.name
        platform_version = platform.version()
        platform_machine = platform.machine()
        platform_python_implementation = platform.python_implementation()

        self.assertTrue(interpret("sys.platform == '%s'" % sys_platform))
        self.assertTrue(
            interpret("sys.platform == '%s' and python_full_version == '%s'" %
                      (sys_platform, version)))
        self.assertTrue(interpret("'%s' == sys.platform" % sys_platform))
        self.assertTrue(interpret('os.name == "%s"' % os_name))
        self.assertTrue(
            interpret('platform.version == "%s" and platform.machine == "%s"' %
                      (platform_version, platform_machine)))
        self.assertTrue(
            interpret('platform.python_implementation == "%s"' %
                      platform_python_implementation))

        # stuff that need to raise a syntax error
        ops = ('os.name == os.name', 'os.name == 2', "'2' == '2'", 'okpjonon',
               '', 'os.name ==', 'python_version == 2.4')
        for op in ops:
            self.assertRaises(SyntaxError, interpret, op)

        # combined operations
        OP = 'os.name == "%s"' % os_name
        FALSEOP = 'os.name == "buuuu"'
        AND = ' and '
        OR = ' or '
        self.assertTrue(interpret(OP + AND + OP))
        self.assertTrue(interpret(OP + AND + OP + AND + OP))
        self.assertTrue(interpret(OP + OR + OP))
        self.assertTrue(interpret(OP + OR + FALSEOP))
        self.assertTrue(interpret(OP + OR + OP + OR + FALSEOP))
        self.assertTrue(interpret(OP + OR + FALSEOP + OR + FALSEOP))
        self.assertTrue(interpret(FALSEOP + OR + OP))
        self.assertFalse(interpret(FALSEOP + AND + FALSEOP))
        self.assertFalse(interpret(FALSEOP + OR + FALSEOP))

        # other operators
        self.assertTrue(interpret("os.name != 'buuuu'"))
        self.assertTrue(interpret("python_version > '1.0'"))
        self.assertTrue(interpret("python_version < '5.0'"))
        self.assertTrue(interpret("python_version <= '5.0'"))
        self.assertTrue(interpret("python_version >= '1.0'"))
        self.assertTrue(interpret("'%s' in os.name" % os_name))
        self.assertTrue(interpret("'buuuu' not in os.name"))
        self.assertTrue(
            interpret("'buuuu' not in os.name and '%s' in os.name" % os_name))

        # execution context
        self.assertTrue(
            interpret('python_version == "0.1"', {'python_version': '0.1'}))
コード例 #6
0
ファイル: metadata.py プロジェクト: Arturo0911/water-quality
 def _platform(self, value):
     if not self.platform_dependent or ';' not in value:
         return True, value
     value, marker = value.split(';')
     return interpret(marker, self.execution_context), value