py-htgettoken: use os.environ, avoid AttributeError (#41717)

* py-htgettoken: use os.environ, avoid AttributeError

This avoids the following error:
```
Warning: could not load runtime environment due to AttributeError: 'EnvironmentModifications' object has no attribute 'get'
```

* py-htgettoken: allow for undefined variables

* py-htgettoken: use dict get()

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

---------

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
This commit is contained in:
Wouter Deconinck 2023-12-17 12:17:23 -06:00 committed by GitHub
parent 17d47accf9
commit b111064e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,8 +33,8 @@ class PyHtgettoken(PythonPackage):
depends_on("py-urllib3", type=("build", "run"))
def setup_run_environment(self, env):
dir = env.get("XDG_RUNTIME_DIR") or "/tmp"
uid = env.get("UID") or os.geteuid()
dir = os.environ.get("XDG_RUNTIME_DIR", "/tmp")
uid = os.environ.get("UID", str(os.geteuid()))
file = join_path(dir, "bt_u" + uid)
env.set("BEARER_TOKEN", file)
env.set("BEARER_TOKEN_FILE", file)