Kallithea issues archive

Issue #367: windows server 2019 installation: ImportError: No module named pwd

Reported by: Serhiy Pikho
State: resolved
Created on: 2020-03-30 13:50
Updated on: 2020-05-02 19:37

Description

I’ve been following this installation Guide https://kallithea.readthedocs.io/en/latest/installation_win.html

But I seem to have hit a roadblock - Running the command kallithea-cli config-create my.ini creates the following errors

(Env) C:\Kallithea\Bin>kallithea-cli
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Kallithea\Env\Scripts\kallithea-cli.exe\__main__.py", line 4, in <module>
  File "c:\kallithea\env\lib\site-packages\kallithea\bin\kallithea_cli.py", line 18, in <module>
    import kallithea.bin.kallithea_cli_db
  File "c:\kallithea\env\lib\site-packages\kallithea\bin\kallithea_cli_db.py", line 18, in <module>
    from kallithea.lib.db_manage import DbManage
  File "c:\kallithea\env\lib\site-packages\kallithea\lib\db_manage.py", line 41, in <module>
    from kallithea.model.base import init_model
  File "c:\kallithea\env\lib\site-packages\kallithea\model\base.py", line 31, in <module>
    from kallithea.lib.utils2 import obfuscate_url_pw
  File "c:\kallithea\env\lib\site-packages\kallithea\lib\utils2.py", line 35, in <module>
    import pwd
ImportError: No module named pwd

Looking up the pwd module shows that its a unix specific module and not supported on windows. https://docs.python.org/2/library/pwd.html

This infomration has left me a bit confused…

Attachments

Comments

Comment by Serhiy Pikho, on 2020-03-30 14:17

Looking at the offending file; Looks like there is no try except in the import of pwd

from __future__ import print_function

import binascii
import datetime
import os
import pwd
import re
import time
import urllib

but there is a try except for its usage

def get_clone_url(clone_uri_tmpl, prefix_url, repo_name, repo_id, username=None):
    parsed_url = urlobject.URLObject(prefix_url)
    prefix = safe_unicode(urllib.unquote(parsed_url.path.rstrip('/')))
    try:
        system_user = pwd.getpwuid(os.getuid()).pw_name
    except Exception: # TODO: support all systems - especially Windows
        system_user = 'kallithea' # hardcoded default value ...

Comment by Mads Kiilerich, on 2020-03-30 14:19

That’s a bug. We don’t have many users on Windows … but there is no reason we couldn’t make it work.

Especially, the Python 3 version to be released soon hasn’t been tested on windows … but you can perhaps help doing that - see https://kallithea-scm.org/repos/kallithea/changeset/01aca0a4f876#C-01aca0a4f876-91a8e75452a1 .

For this particular problem, you can just delete the `import pwd` line.

Comment by Serhiy Pikho, on 2020-03-30 14:27

http://www.mergely.com/yeDhnuv5/

The following changes seem to have worked:

from __future__ import print_function

import binascii
import datetime
import os
import re
import time
import urllib

try:
    import pwd
except ImportError:
    print("running windows installation cannot use pwd keyring manager")

Comment by Serhiy Pikho, on 2020-03-30 14:40

Thanks for the offer Mads Kiilerich. Unfortunatley I can’t test anything: The Org I work for is looking to quickly switch from Bitbucket before the sunsetting and are looking for reliablity and usablity first.

The only reason why I’m running it on windows is that I’m doing a comparision between kallithea and HgLabs. If the recocomeded operating system is linux then I can easily switch over.