[Grok-dev] Grokproject error for first time Windows users

Steve Schmechel steveschmechel at yahoo.com
Thu Feb 18 11:32:30 EST 2010


There is a rather hidden problem with Grokproject that occurs when
running it for the first time under the Windows OS without the win32api
module being available.  It can also occur when win32api is available in
the system Python site-packages, but the user is working in a virtual
environment created using "virtualenv --no-site-packages".

This is related to the fix applied for the bug:
https://bugs.launchpad.net/grok/+bug/315223
Which addressed problems with Window paths with spaces.

The problem only occurs when initially creating the file "default.cfg"
in the default location of:
"C:\Documents and Settings\<USERNAME>\.buildout"

If the file does not exist and an explicit eggs_dir path is not
provided, an attempt is made to create the file.

  buildout_default = exist_buildout_default_file()
  if explicit_eggs_dir:
      # Put explicit_eggs_dir in the vars; used by the post command.
      vars['explicit_eggs_dir'] = explicit_eggs_dir
      vars['eggs_dir'] = (
          '# Warning: when you share this buildout.cfg with friends\n'
          '# please remove the eggs-directory line as it is hardcoded.\n'
          'eggs-directory = %s') % explicit_eggs_dir
  elif buildout_default:
      vars['eggs-dir'] = ''
  else:
      create_buildout_default_file()


However, the creation method does a conditional import of win32api which
fails.

  def create_buildout_default_file():
      default_dir = os.path.join(HOME, '.buildout')
      if not os.path.isdir(default_dir):
          os.mkdir(default_dir)
      eggs_dir = os.path.join(default_dir, 'eggs')
      if not os.path.isdir(eggs_dir):
          os.mkdir(eggs_dir)
      if sys.platform == 'win32':
          # Fix for paths with spaces on Windows.
          # See https://bugs.launchpad.net/grok/+bug/315223
          import win32api
          eggs_dir = win32api.GetShortPathName(eggs_dir)
      default_cfg = os.path.join(HOME, '.buildout', 'default.cfg')
      if not os.path.isfile(default_cfg):
          config_file = open(default_cfg, 'w')
          contents = """[buildout]
  eggs-directory = %s
  """ % (eggs_dir)
          config_file.write(contents)
          config_file.close()


After running grokproject and providing the user and passwd inputs, the
user receives:


  Enter user (Name of an initial administrator user): grok
  Enter passwd (Password for the initial administrator user):
  Downloading info about versions...
  Traceback (most recent call last):
    File "C:\vgrok\Scripts\grokproject-script.py", line 8, in <module>
      load_entry_point('grokproject==1.0.2', 'console_scripts', 'grokproject')()
    File "C:\vgrok\lib\site-packages\grokproject-1.0.2-py2.6.egg\grokproject\main.py", line 80, in main + extra_args)
    File "C:\vgrok\lib\site-packages\pastescript-1.7.3-py2.6.egg\paste\script\command.py", line 218, in run result = self.command()
    File "C:\vgrok\lib\site-packages\pastescript-1.7.3-py2.6.egg\paste\script\create_distro.py", line 125, in command vars = template.check_vars(vars, self)
    File "C:\vgrok\lib\site-packages\grokproject-1.0.2-py2.6.egg\grokproject\templates.py", line 117, in check_vars create_buildout_default_file()
    File "C:\vgrok\lib\site-packages\grokproject-1.0.2-py2.6.egg\grokproject\utils.py", line 45, in create_buildout_defau
  lt_file
      import win32api
  ImportError: No module named win32api


Would it be possible for Grokproject to check for the availability of
the module and either output a sensible warning to the user, or possibly
easy_install pywin32 to satisfy its own requirement?

The people that are likely to run into this will be first time users of
grokproject and buildout, so it will probably be a source of continuing
confusion and questions until the virtualenv developers start to handle
this upstream.

Should I file a bug report on this?


Thanks,
Steve



      


More information about the Grok-dev mailing list