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

问题描述 投票:0回答:1

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

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

AM_PATH_PYTHON([3.8])

我正尝试开始使用3.x,因为明年(2020年)将不推荐使用2.x。

我的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 $@

配置--prefix $ HOME之后,进行安装,进行安装(仅在此步骤中编译了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

错误消息是与python3不兼容的典型python2不在这里。我希望让制作过程在这里停止,但是它一直持续到最后,并处理其他构建任务。 $ {PYTHON} -m py_compile FOO.py || 1号出口似乎在这里不起作用。这是一个手写规则,用于覆盖自动生成的隐式规则。

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

python autoconf automake
1个回答
0
投票

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

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

看起来好像手写规则似乎行得通。修复更多语法错误后,有时make流程会跳过一些错误,有时会停止。我仍然在这里缺少一些东西。

© www.soinside.com 2019 - 2024. All rights reserved.