def _convert_to_rex(self, commands): if isinstance(commands, list): from rez.utils.backcompat import convert_old_commands msg = "package %r is using old-style commands." % self.uri if config.disable_rez_1_compatibility or config.error_old_commands: raise SchemaError(None, msg) elif config.warn("old_commands"): print_warning(msg) commands = convert_old_commands(commands) if isinstance(commands, basestring): return SourceCode(source=commands) elif callable(commands): return SourceCode(func=commands) else: return commands
def _convert_to_rex(self, commands): if isinstance(commands, list): from rez.utils.backcompat import convert_old_commands msg = "package %r is using old-style commands." % self.uri if config.disable_rez_1_compatibility or config.error_old_commands: raise SchemaError(None, msg) elif config.warn("old_commands"): print_warning(msg) commands = convert_old_commands(commands) if isinstance(commands, basestring): return SourceCode(commands) elif callable(commands): return SourceCode.from_function(commands) else: return commands
def test_old_style_commands(self): """Convert old style commands to rex""" expected = "" rez_commands = convert_old_commands([], annotate=False) self.assertEqual(rez_commands, expected) expected = "setenv('A', 'B')" rez_commands = convert_old_commands(["export A=B"], annotate=False) self.assertEqual(rez_commands, expected) expected = "setenv('A', 'B:$C')" rez_commands = convert_old_commands(["export A=B:$C"], annotate=False) self.assertEqual(rez_commands, expected) expected = "setenv('A', 'hey \"there\"')" rez_commands = convert_old_commands(['export A="hey \\"there\\""'], annotate=False) self.assertEqual(rez_commands, expected) expected = "appendenv('A', 'B')" rez_commands = convert_old_commands(["export A=$A:B"], annotate=False) self.assertEqual(rez_commands, expected) expected = "prependenv('A', 'B')" rez_commands = convert_old_commands(["export A=B:$A"], annotate=False) self.assertEqual(rez_commands, expected) expected = "appendenv('A', 'B:$C')" rez_commands = convert_old_commands(["export A=$A:B:$C"], annotate=False) self.assertEqual(rez_commands, expected) expected = "prependenv('A', '$C:B')" rez_commands = convert_old_commands(["export A=$C:B:$A"], annotate=False) self.assertEqual(rez_commands, expected)