Python "make" like tools (was Re: [ANN] DoIt 0.1.0 Released (build tool))

Eduardo Schettino schettino72 at gmail.com
Wed Apr 23 15:37:22 EDT 2008


On Wed, Apr 23, 2008 at 8:39 PM, Ville M. Vainio <vivainio at gmail.com> wrote:
>
>  Yeah, decorators get around this.
>
>
>  Perhaps you could do:
>
>  for f in pyFiles:
>   @task("checker")
>   @depend(f)
>   def check():
>     c("pychecker %s" % f)
>
>  Never underestimate the magic that is nested scopes and name-agnostic
> function object creation...
>

ok. it is possible to do everything with decorators... i agree.
but i dont want "name-agnostic function object creation". i want to be
able to execute every single task without executing all other tasks.
thats why when defining sub-tasks  it is required an extra parameter
"name". I know you could add another decorator for this also :)
I mean decorators could do the job i dont say they cant. *I* prefer to
work with dictionaries though. Even if they are a bit more verbose.


> >
> > 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.
> >
>
>  Yeah, this is what I consider much friendlier syntax (the aim is to not be
> much more verbose than make).
>
>

Maybe it is just a bad example. I tried to put all features on single
example. but in *real* life I could do like this.

import os
jsPath = "./"
jsFiles = ["file1.js", "file2.js"]
sourceFiles = [jsPath + f for f in jsFiles]
compressedFiles = [jsPath + "build/" + f + ".compressed" for f in jsFiles]

def task_shrink_js():
    # create output folder
    if not os.path.exists(path):
        os.mkdir(path)
    for jsFile,compFile in zip(sourceFiles,compressedFiles):
        action = 'java -jar custom_rhino.jar -c %s > %s'% (jsFile, compFile)
        yield {'action':action,
               'name':jsFile,
               'dependencies':(jsFile,),
               'targets':(compFile,)
               }

Can I challenge you to do this with any other build tool?

i guess anything more complicated than this you want to create a
python function separate from the task definition anyway.

My examples are from scratch. I dont use a "standard library".

I could also document the short-cuts :P. I was afraid that including
the short-cuts would make it more complicated for who is trying to
learn it.

if you dont define any dependencies or args to the function you dont
need to return a dictionary. just the action:

def task_simple_shell():
    return "echo spam"

def task_simple_python():
   def say_spam():
       print "spam"
       return True
   return say_spam

# or from our discussion

def task_create_build_folder():
   def create_folder():
      path = jsPath + "build"
      if not os.path.exists(path):
         os.mkdir(path)
      return True
   return create_folder


>
> > apart from one .py file installation (easy_install is not enough?)
> > thats what i am trying to do.
> >
>
>  easy_install is not really enough - it introduces a dependency that you
> can't get around by just shipping a short .py file with your project.
>
what about shipping a single egg file with the whole package? ( I am
not very much familiar with this subject)

>  'Paver' seems to have the right idea:
>
>  http://www.blueskyonmars.com/projects/paver/index.html
>

Thanks for the link. I took a quick look on its documentation.
It seems that "paver" doesnt keep track of file-dependencies at all.
So it is more like a setuptools extension commands than a
"full-feature" build system with "smart" re-build and dependency
support.

"doit" target is not on creating releases for python projects only. it
can do it also, but it can do much more.

You can read about my motivation to start another build tool project
on http://schettino72.wordpress.com/2008/04/14/doit-a-build-tool-tale/


>  But it's still *slightly* too big:
>

man, it is hard to make you happy :)

the doit egg file containg the whole packge is 27782 bytes on my
system. but you also need the command line script 154 bytes.

cheers,
  Eduardo



More information about the Python-list mailing list