简体   繁体   中英

python equivelant to $(which) in make

porting a Makefile to dodo.py i want to source the "nikola" on the path rather than directly call it

in Makefile i would do something like

NIKOLA = $(which nikola)

however i cant seem to find the doit/dodo/python equivelant my current file looks like this

import subprocess

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

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

however running task_build returns this

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

Try this:

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

In your case:

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']}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM