Skip to content

Commit

Permalink
Adds a missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-smallshire committed Mar 5, 2024
1 parent c4b209c commit 348da29
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/venv_management/pyenv_config.py
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

0 comments on commit 348da29

Please sign in to comment.