如何将python集成到automake中并在python语法错误时退出构建过程

如何将python集成到automake中并在python语法错误时退出构建过程,python,autoconf,automake,Python,Autoconf,Automake,我已经完成了寻找解决方案的家庭工作。我得到了一个带有一些简单python脚本的autoconf项目 在my configure.ac中(仅显示相关片段): 我正试图开始使用3.x,因为2.x将在明年(2020年)被弃用 My Makefile.am: python_PYTHON = uptocloud.py loadvariant.py # I am not sure the following line is execute or the above one execute # more li

我已经完成了寻找解决方案的家庭工作。我得到了一个带有一些简单python脚本的autoconf项目

在my configure.ac中(仅显示相关片段):

我正试图开始使用3.x,因为2.x将在明年(2020年)被弃用

My Makefile.am:

python_PYTHON = uptocloud.py loadvariant.py
# I am not sure the following line is execute or the above one execute
# more likely the above one got executed
loadvariant : loadvariant.py
   ${PYTHON} -m py_compile $^ || exit 1
   @echo -e "#!/bin/sh\n${PYTHON} ${pythondir}/${@}.pyo \$$" > $@
   sed -i '2s,$$,*,' $@
   chmod +x $@
在configure--prefix$HOME,make,make install之后(仅在此步骤中python被编译),我收到以下错误消息:

 /usr/bin/install -c -m 644 uptocloud.py loadvariant.py load1variant.py '/home/myhome/lib/python3.8/site-packages'
<string>:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Byte-compiling python modules...
uptocloud.pyloadvariant.py  File "/home/myhome/lib/python3.8/site-packages/loadvariant.py", line 57
    print "Connected to {} on {}!\n".format(pgdbname, hostname)
          ^
SyntaxError: invalid syntax

 Byte-compiling python modules (optimized versions) ...
 uptocloud.pyloadvariant.py
/usr/bin/install-c-m 644 uptocloud.py loadvariant.py load1variant.py'/home/myhome/lib/python3.8/site packages'
:2:弃用警告:imp模块已弃用,取而代之的是importlib;有关替代用途,请参阅模块文档
字节编译python模块。。。
uptocloud.pyloadvariant.py文件“/home/myhome/lib/python3.8/site packages/loadvariant.py”,第57行
打印“连接到{}上的{}!\n”。格式(pgdbname,主机名)
^
SyntaxError:无效语法
字节编译python模块(优化版本)。。。
uptocloud.pyloadvariant.py
错误消息是典型的python2与python3不兼容,这不是重点。我本来希望让make过程停止在这里,但它一直持续到最后,并在其他构建任务中工作。${PYTHON}-m py|u compile FOO.py||exit 1在这里似乎不起作用。这是一条手写规则,用于覆盖自动生成的隐式规则


我的问题是如何让make停在这里,并要求我修复python脚本中的语法错误

这是一个很好的答案,但有50%的正确率。在我修复了上面提到的打印语法错误之后。这次我再次尝试了make安装,构建过程确实停止了。不知道为什么会这样。下面是错误消息的简短版本(删除冗余消息)

make[2]:输入目录“/home/myhome/coding/projname/scripts”
/usr/local/bin/python3-m py|u compile loadvariant.py||退出1
回溯(最近一次呼叫最后一次):
文件“/usr/local/lib/python3.8/py_compile.py”,第144行,在compile中
代码=加载程序。源代码到源代码(源字节、数据文件或文件,
文件“”,第846行,源代码为
文件“”,第219行,在“调用”中,删除了“帧”
文件“loadvariant.py”,第186行
打印sqlstr
^
SyntaxError:调用“print”时缺少括号。您是指print(sqlstr)吗?
在处理上述异常期间,发生了另一个异常:
#这里删除了更多的错误行
NameError:未定义名称“quiet”
Makefile:860:目标“loadvariant”的配方失败
生成[2]:***[loadvariant]错误1
看起来手写规则似乎有效。在修复了更多语法错误后,有时make进程会跳过一些错误,有时会停止。我仍然缺少一些东西

 /usr/bin/install -c -m 644 uptocloud.py loadvariant.py load1variant.py '/home/myhome/lib/python3.8/site-packages'
<string>:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Byte-compiling python modules...
uptocloud.pyloadvariant.py  File "/home/myhome/lib/python3.8/site-packages/loadvariant.py", line 57
    print "Connected to {} on {}!\n".format(pgdbname, hostname)
          ^
SyntaxError: invalid syntax

 Byte-compiling python modules (optimized versions) ...
 uptocloud.pyloadvariant.py
make[2]: Entering directory '/home/myhome/coding/projname/scripts'
/usr/local/bin/python3 -m py_compile loadvariant.py || exit 1
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/py_compile.py", line 144, in compile
    code = loader.source_to_code(source_bytes, dfile or file,
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "loadvariant.py", line 186
    print sqlstr
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(sqlstr)?

During handling of the above exception, another exception occurred:
# more lines of error removed here

NameError: name 'quiet' is not defined
Makefile:860: recipe for target 'loadvariant' failed
make[2]: *** [loadvariant] Error 1