-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4b209c
commit 348da29
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import configparser | ||
from pathlib import Path | ||
|
||
|
||
def pyvenv_config(env_dirpath: Path, key: str) -> str | None: | ||
"""Read a value from a pyvenv config file. | ||
Args: | ||
env_dirpath: Path to the directory containing the pyvenv.cfg file. | ||
key: The key from which to lookup the associated value. | ||
Returns: | ||
The value from the pyvenv.cfg file, or None if the key does not exist | ||
in the pyvenv.cfg file or if the pyenv.cfg config file does not exist. | ||
""" | ||
pyenv_cfg_path = env_dirpath / "pyvenv.cfg" | ||
value = None | ||
if pyenv_cfg_path.is_file(): | ||
config_text = pyenv_cfg_path.read_text() | ||
config = configparser.ConfigParser() | ||
config.read_string("[root]\n" + config_text) | ||
|
||
try: | ||
config_executable = config["root"][key] | ||
except KeyError: | ||
pass | ||
else: | ||
value = config_executable.strip() | ||
return value |