GetComponents assumes that $USER is defined

Issue #2612 resolved
Roland Haas created an issue

Currently GetComponents assumes that the $USER environment variable is set. This is not true inside of docker containers and requires some workarounds in the Dockerfile to handle correctly.

Pull request instead uses Perl’s getpwuid to get the user name from the OS which does not rely on USER. I tested getpwuid to work fine in a Ubuntu container.

Comments (7)

  1. Roland Haas reporter

    ugh, I did not know that. Checking… Simfactory has “workarounds”:

    def GetUsername():
        if "USER" not in os.environ:
            fd = simenv.popen("whoami")
            username =
            username = os.environ["USER"]
        return username

    What’s wrong with os.getlogin() which is the first answer that Google finds for “Python get user name”: and apparently part of Python since forever?
    I’ll make a pull request for simfactory as well.

  2. Log in to comment