Python "make" like tools (was Re: [ANN] DoIt 0.1.0 Released (build tool))
Eduardo Schettino
schettino72 at gmail.com
Mon Apr 21 12:03:35 EDT 2008
>
> I took a look at dolt syntax, and saw this:
>
> QQQ
>
> def create_folder(path):
> """Create folder given by "path" if it doesnt exist"""
> if not os.path.exists(path):
> os.mkdir(path)
> return True
>
> def task_create_build_folder():
> buildFolder = jsPath + "build"
> return {'action':create_folder,
> 'args': (buildFolder,)
> }
>
> QQQ
>
> Wouldn't it be more convenient to provide syntax like this:
>
> @task("create_build_folder")
> @depend("dep1 some_other_dep")
> def buildf():
> buildFolder = jsPath + "build"
> create_folder(buildFolder)
>
> I find the doit syntax a bit cumbersome, especially as you can avoid
> 'args' by just returning a lamda in 'action'.
My idea was to: do *not* add any new syntax (to avoid being
cumbersome). It is just python, you dont have to import or subclass
anything. You just need to create a function that returns a dictionary
with some predefined keys.
I though about using decorators in the beginning... but returning a
dictionary looked easier to implement and more flexible. one important
feature is how easy to define a group of task with the same action.
Take a look at the example below on running pychecker in all python
files from a folder. I couldnt figure out an easy way of doing it with
decorators.
import glob;
pyFiles = glob.glob('*.py')
def task_checker():
for f in pyFiles:
yield {'action': "pychecker %s"% f,
'name':f,
'dependencies':(f,)}
Another advantage of using just a dictionary to define a task is that
it will be easy to read tasks from a text file (if it is very simple
and you dont need to write any python script). but not implemented
yet.
I though about using decorator for simple python-tasks but in a different way:
@task
def create_folder(path):
"""Create folder given by "path" if it doesnt exist"""
if not os.path.exists(path):
os.mkdir(path)
return True
so if your python function is a task and you will use it only once you
dont need to define a function for the 'action' and another function
to create the task. but not implement yet also.
>
> I've looked around a bit for python "make" replacement, but there does
> not seem to be a simple & straightforward solution around (read -
> straight-python syntax, one .py file installation, friendly license).
apart from one .py file installation (easy_install is not enough?)
thats what i am trying to do.
thanks for the feedback.
cheers,
Eduardo
More information about the Python-list
mailing list