python 相当于 make 中的 $(which)

python equivelant to $(which) in make

将 Makefile 移植到 dodo.py 我想在路径上获取 "nikola" 而不是直接调用它

在 Makefile 中我会做类似的事情

NIKOLA = $(which nikola)

但是我似乎找不到 doit/dodo/python 等价物我当前的文件看起来像这样

import subprocess

Nikola = subprocess.Popen("nikola", stdout=subprocess.PIPE, shell=True)

def task_build():
    return {
        'actions': ['{0} build'.format(Nikola)],
    }

但是运行 task_build returns 这个

########################################
Execution aborted.
Task 'build': invalid 'actions' type. got:<subprocess.Popen object at 0x10111f810> <class 'subprocess.Popen'>
(env)

试试这个:

>>> import subprocess
>>> subprocess.check_output(['which','nikola'])
'/Users/elyase/miniconda/bin/nikola\n'

你的情况:

def task_build():
    return {
        'actions': ['{0} build'.format(Nikola)],
    }

>>> Nikola = subprocess.check_output(['which','nikola']).rstrip()
>>> task_build()
{'actions': ['/Users/elyase/miniconda/bin/nikola build']}