NameError: name 'task' is not defined

1,777 views
Skip to first unread message

rstackhouse

unread,
Jun 9, 2010, 12:21:52 PM6/9/10
to paver
I'm brand new to paver. I've tried to follow along with this tutorial
http://www.blueskyonmars.com/projects/paver/getting_started.html, but
when I try to run a user defined task, I get the error: "NameError:
name 'task' is not defined"

I used easy_install paver on a Windows 7 box to install paver.

My pavement.py file looks like this:

@task
@needs('generate_setup', 'minilib', 'setuptools.command.sdist')
def sdist():
"""Overrides sdist to make sure that our setup.py is generated."""
pass

@task
def unit_test():
from fizzbuzz.test import all_tests
all_tests.main()

Any help would be greatly appreciated.

Thanks

Kevin Dangoor

unread,
Jun 9, 2010, 2:08:49 PM6/9/10
to pa...@googlegroups.com
On Wed, Jun 9, 2010 at 12:21 PM, rstackhouse <robertst...@gmail.com> wrote:
I'm brand new to paver. I've tried to follow along with this tutorial
http://www.blueskyonmars.com/projects/paver/getting_started.html, but
when I try to run a user defined task, I get the error: "NameError:
name 'task' is not defined"

Early on, Paver would magically make certain names available. That hasn't been the case for quite some time. pavements are standard Python modules, which means that you need to import any names that you intend to use.

The simplest way to do this is to put this at the top of your pavement:

from paver.easy import *


Kevin

--
Kevin Dangoor

work: http://labs.mozilla.com/
email: k...@blazingthings.com
blog: http://www.BlueSkyOnMars.com

Robert Stackhouse

unread,
Jun 9, 2010, 2:34:00 PM6/9/10
to pa...@googlegroups.com
Thanks Kevin.

But now I get: 

C:\Users\robertstackhouse\Desktop\KitchenSink>paver sdist
Traceback (most recent call last):
  File "C:\Python26\Scripts\paver-script.py", line 8, in <module>
    load_entry_point('paver==1.0.3', 'console_scripts', 'paver')()
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 621, in main
    _launch_pavement(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 604, in _launch_pavement
    _process_commands(args, auto_pending=auto_pending)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 557, in _process_commands
    task, args = _parse_command_line(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 496, in _parse_command_line
    args = task.parse_args(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 316, in parse_args
    parser = self.parser
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 268, in parser
    for option in task.user_options:
AttributeError: 'module' object has no attribute 'user_options'


--
You received this message because you are subscribed to the Google Groups "paver" group.
To post to this group, send email to pa...@googlegroups.com.
To unsubscribe from this group, send email to paver+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/paver?hl=en.



--
Robert Stackhouse

http://robertstackhouse.com/flavorsof
http://agilebcs.org
http://bcsbloggers.org
http://uweb.tamu.edu

Kevin Dangoor

unread,
Jun 9, 2010, 3:38:27 PM6/9/10
to pa...@googlegroups.com
On Wed, Jun 9, 2010 at 2:34 PM, Robert Stackhouse <robertst...@gmail.com> wrote:
AttributeError: 'module' object has no attribute 'user_options'


Strange... what you've got is:


@task
@needs('generate_setup', 'minilib', 'setuptools.command.sdist')
def sdist():
        """Overrides sdist to make sure that our setup.py is generated."""
        pass


which is very similar to Paver's own pavement:

(old_sdist is "setuptools.command.sdist")

    @task
    @needs('html', "minilib", "generate_setup", old_sdist)
    def sdist():
        """Builds the documentation and the tarball."""
        pass


Perhaps you have a version of setuptools that I haven't tested? It's honestly been awhile since I looked at this.

Robert Stackhouse

unread,
Jun 9, 2010, 4:49:50 PM6/9/10
to pa...@googlegroups.com
Looks like I am running 0.6c11.

--
You received this message because you are subscribed to the Google Groups "paver" group.
To post to this group, send email to pa...@googlegroups.com.
To unsubscribe from this group, send email to paver+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/paver?hl=en.

Robert Stackhouse

unread,
Jun 9, 2010, 4:50:19 PM6/9/10
to pa...@googlegroups.com
That is to say version 0.6c11 of setuptools.

Kevin Dangoor

unread,
Jun 9, 2010, 9:34:01 PM6/9/10
to pa...@googlegroups.com
On Wed, Jun 9, 2010 at 4:50 PM, Robert Stackhouse <robertst...@gmail.com> wrote:
That is to say version 0.6c11 of setuptools.


Odd. That's the same version of setuptools that I've got installed. Guess I'm not out of date after all.

This is your error:


  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py",
lin
e 268, in parser
    for option in task.user_options:
AttributeError: 'module' object has no attribute 'user_options'
- Hide quoted text -

Generated from calling this task:


@task
@needs('generate_setup', 'minilib', 'setuptools.command.sdist')
def sdist():
        """Overrides sdist to make sure that our setup.py is generated."""
        pass

Ahh, maybe I've got it now...

setuptools.command.sdist is a module (see the error... 'module' object has no attribute 'user_options'). setuptools.command.sdist.sdist does have a user_options attribute.  Paver's setuputils module goes to some effort to ensure that distutils/setuptools commands can be used like tasks and that you don't have to write things out like setuptools.command.sdist.sdist. I think you might be missing this:

from paver.setuputils import setup
The setup function in that module calls a function in there to install the distutils/setuptools commands as proper tasks.

Robert Stackhouse

unread,
Jun 11, 2010, 9:48:21 AM6/11/10
to pa...@googlegroups.com
I changed my pavement to:
 
from paver.setuputils import setup
from paver.easy import *

@task
@needs(['generate_setup', 'minilib', 'setuptools.command.sdist.sdist'])
def sdist():
"""Overrides sdist to make sure that our setup.py is generated."""
pass

@task
def unit_test():
"""Run the fizzbuzz unit tests."""
from fizzbuzz.test import all_tests
all_tests.main()

And now I get this error:

C:\Users\robertstackhouse\Desktop\KitchenSink>paver sdist
Traceback (most recent call last):
  File "C:\Python26\Scripts\paver-script.py", line 8, in <module>
    load_entry_point('paver==1.0.3', 'console_scripts', 'paver')()
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 621, in main
    _launch_pavement(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 604, in _launch_pavement
    _process_commands(args, auto_pending=auto_pending)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 557, in _process_commands
    task, args = _parse_command_line(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 496, in _parse_command_line
    args = task.parse_args(args)
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 316, in parse_args
    parser = self.parser
  File "C:\Python26\lib\site-packages\paver-1.0.3-py2.6.egg\paver\tasks.py", lin
e 293, in parser
    self.option_names.add((task.shortname, longname))
AttributeError: class sdist has no attribute 'shortname'

Kevin Dangoor

unread,
Jun 11, 2010, 10:51:28 AM6/11/10
to pa...@googlegroups.com
On Fri, Jun 11, 2010 at 9:48 AM, Robert Stackhouse <robertst...@gmail.com> wrote:
I changed my pavement to:
 
from paver.setuputils import setup
from paver.easy import *

@task
@needs(['generate_setup', 'minilib', 'setuptools.command.sdist.sdist'])
def sdist():
"""Overrides sdist to make sure that our setup.py is generated."""
pass

@task
def unit_test():
"""Run the fizzbuzz unit tests."""
from fizzbuzz.test import all_tests
all_tests.main()


That's the whole pavement?

You need the call to setup() that provides all of the metadata (as described in the tutorial doc you were originally referring to). None of the distutils stuff will work without the metadata about your package...

Robert Stackhouse

unread,
Jun 11, 2010, 11:41:58 AM6/11/10
to pa...@googlegroups.com
Is there someplace I can go to look at an example pavement file?

--
You received this message because you are subscribed to the Google Groups "paver" group.
To post to this group, send email to pa...@googlegroups.com.
To unsubscribe from this group, send email to paver+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/paver?hl=en.

Michele Mattioni

unread,
Jun 11, 2010, 11:49:02 AM6/11/10
to pa...@googlegroups.com

Robert Stackhouse

unread,
Jun 11, 2010, 1:29:37 PM6/11/10
to pa...@googlegroups.com
Ok. I've discovered the source of my problem.

I did not get the meaning of the mark up a la:

# <== include("started/oldway/setup.py", "setup")==>
...
# <==end==>

Going back over the tutorial, I discovered these snippets are supposed to be strung together in order.

Is this a common python documentation convention? I have never seen this before. Admittedly, I am really new to python. It may seem silly to you, but it would have really helped me to see the tutorial pavement.py all in one place.

My pavement.py looks like the following and now both tasks work. Thank you for your continued help and patience.

from paver.easy import *
#import paver.doctools
from paver.setuputils import setup

setup(
      name="KitchenSink",
      packackes=['fizzbuzz', 'test_web_ic3'],
      version="0.1",
      url="http://notarealurl",
      author="Robert Stackhouse",
      author_email="robertst...@gmail.com"
)

@task
@needs(['generate_setup', 'minilib', 'setuptools.command.sdist'])
def sdist():
    """Overrides sdist to make sure that our setup.py is generated."""
    pass

@task
def unit_test():
    """Run the fizzbuzz unit tests."""
    if not 'BASEDIR' in globals():
        import sys
        import inspect
        import os
        global BASEDIR
        FRAME_INFO = inspect.getframeinfo(inspect.currentframe())
        BASEDIR = os.path.realpath(os.path.join(os.path.dirname(FRAME_INFO.filename),'src\\')) #should always point to src
        sys.path.append(BASEDIR)
    
    from fizzbuzz.test import all_tests
    
    all_tests.main()

What's the difference between setup and options?

Kevin Dangoor

unread,
Jun 11, 2010, 2:18:46 PM6/11/10
to pa...@googlegroups.com
On Fri, Jun 11, 2010 at 1:29 PM, Robert Stackhouse <robertst...@gmail.com> wrote:
Ok. I've discovered the source of my problem.

I did not get the meaning of the mark up a la:

# <== include("started/oldway/setup.py", "setup")==>
...
# <==end==>

Going back over the tutorial, I discovered these snippets are supposed to be strung together in order.

Actually, that's a documentation trick I picked up from Bruce Eckel. If you pick up the Paver source, you can find that exact file and see the whole file.

It's not so much that they're intended to be taken in order. It's more that I was pulling out sections of the file to highlight some specific bit.
 
Is this a common python documentation convention? I have never seen this before. Admittedly, I am really new to python. It may seem silly to you, but it would have really helped me to see the tutorial pavement.py all in one place.

Yeah, that's likely a good point. It certainly would be easy enough for the doc to include the entire pavement.

To some extent, this tutorial assumes some knowledge of Python distutils.
 
Excellent question. "options" is the paver way, whereas setup() is familiar to distutils users (eg everyone who's ever released a python package!). Paver's setup function does two things:

1. sets the options
2. calls the function to install the distutils commands as paver tasks.
Reply all
Reply to author
Forward
0 new messages