Using reposurgeon and trying to extend its functionality, I am faced with:
reposurgeon: invalid syntax in extension function
which translates to a SyntaxError extension raised from the execfile() call in RepoSurgeon.do_exec(). What gives? The code I am trying to exec is as simple as:
print "Hello world"
I have also used the Python CLI and execfile and there are no complaints whatsoever?
Used version: reposurgeon 3.10
This one took me a while to figure out, which is why I am posting it here.
The key is indeed in the single line of code we're trying to "source". While this is perfectly valid Python 2.x code,
reposurgeonuses theprintfunction from Python 3.x by doing:Which causes
printto require the use of parentheses, as it makesprinta function instead of a statement.Obviously we're running our extension code in the context of
reposurgeon, which means that we're dependent on the rules it defines.See this document.
Hence the following will work just fine: