Commits

Carl Meyer  committed c48e97e

Look for <executable-name>.virtual.conf adjacent to the binary and one level up.

Also changed relevant config file section name from [pythonv] to [virtual].

The default sys.prefix in either case is set to the directory where the
configuration file is found. The sys.prefix value can be overridden by setting
"prefix" in the [virtual] section of the config file.

  • Participants
  • Parent commits 34760e6
  • Branches pythonv2

Comments (0)

Files changed (1)

     sys.installed_prefix = sys.prefix
     sys.installed_exec_prefix = sys.exec_prefix
 
-    executable_prefix = os.path.dirname(os.path.dirname(sys.executable))
-    pythonv_conf = os.path.join(executable_prefix, "pythonv.conf")
-    if os.path.isfile(pythonv_conf):
+    executable_dir, executable_name = os.path.split(sys.executable)
+    if sys.platform == "win32":
+        executable_name = os.path.splitext(executable_name)[0]
+    conf_basename = executable_name + ".virtual.conf"
+    candidate_confs = [
+        conffile for conffile in [
+            os.path.join(executable_dir, conf_basename),
+            os.path.join(os.path.dirname(executable_dir), conf_basename)
+            ]
+        if os.path.isfile(conffile)
+        ]
+
+    if candidate_confs:
+        virtual_conf = candidate_confs[0]
         from configparser import ConfigParser
         cfg = ConfigParser()
-        cfg.read(pythonv_conf)
+        cfg.read(virtual_conf)
         system_site = cfg.get(
-            "pythonv", "include-system-site", fallback="false").lower()
+            "virtual", "include-system-site", fallback="false").lower()
+        sys_prefix = cfg.get(
+            "virtual", "prefix", fallback=os.path.dirname(virtual_conf))
 
-        sys.prefix = sys.exec_prefix = executable_prefix
+        sys.prefix = sys.exec_prefix = sys_prefix
 
         if system_site and system_site != "false":
             PREFIXES.insert(0, sys.prefix)
         else:
-            PREFIXES = [sys.prefix, sys.exec_prefix]
+            PREFIXES = [sys.prefix]
 
 
 def execsitecustomize():