venvipy icon indicating copy to clipboard operation
venvipy copied to clipboard

My pyvenv.cfg doesn't seem to match what venvipy expects

Open Gadgetoid opened this issue 1 year ago • 1 comments

Created with virtualenvwrapper mkvirtualenv:

home = /usr
implementation = CPython
version_info = 3.9.2.final.0
virtualenv = 20.4.0+ds
include-system-site-packages = true
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3

Created with python3 -m venv

home = /usr/bin
include-system-site-packages = false
version = 3.9.2

Created with python3 -m virtualenv

home = /usr
implementation = CPython
version_info = 3.9.2.final.0
virtualenv = 20.4.0+ds
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3

Created in VenviPy:

home = /usr/bin
include-system-site-packages = false
version = 3.9.2

It looks like VenviPy's get_data.get_config expects:

  • version
  • site_packages
  • installed

And fetches them out of pyenv.cfg based on their explicit, expected position.

These changes get me up and running, by scanning through the config file for the relevant setting:

diff --git a/venvipy/get_data.py b/venvipy/get_data.py
index 0ccb322..5fb6dc0 100644
--- a/venvipy/get_data.py
+++ b/venvipy/get_data.py
@@ -280,8 +280,19 @@ def get_config(cfg_file, cfg):
     Values for `cfg` can be: `version`, `py_path`,
     `site_packages`, `installed`, `comment`.
     """
-    with open(cfg_file, "r", encoding="utf-8") as f:
-        lines = f.readlines()
+    lines = open(cfg_file, "r", encoding="utf-8").readlines()
+
+    if cfg == "site_packages":
+        return "global" if get_config(cfg_file, "include-system-site-packages") == "true" else "isolated"
+
+    if cfg == "py_path":
+        return get_config(cfg_file, "base-executable")
+
+    for line in lines:
+        if line.startswith(cfg):
+            return line.strip().split(" = ")[1]
+
+    return None
 
     if lines[2][13] == ".":
         version = lines[2][10:13].strip()  # python 3.x

Could also probably just use configparser.ConfigParser() with an additional section name.

This is a pretty low-level change that might break things I don't expect. Would you like a PR for it?

Gadgetoid avatar Oct 25 '23 15:10 Gadgetoid