[Git][NTPsec/ntpsec][master] 2 commits: Fixes FixConfig bug with non-default Python.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Nov 13 13:43:47 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
b664549b by Fred Wright at 2017-11-12T14:05:25-08:00
Fixes FixConfig bug with non-default Python.

This actually makes three changes, though only one has a functional
effect:

1) For the sys.path check, it obtains the sys.path from the target
Python, rather than using it from the possibly different running
Python.

2) It removes the unnecessary directory existence check.

3) It uses (i.e., leaves unchanged) the result of the prefixed
get_python_lib() when possible, rather than explicitly constructing
what should be the same thing in the relevant cases.

TESTED:
Tested "configure" on OSX 10.5, 10.9, 10.12, Ubuntu 14.04, CentOS 7,
Fedora 25, FreeBSD 10.3, OpenBSD 5.6, and NetBSD 6.1.5.  Verified that
the resulting PYTHONDIR was not altered by this change.
Also tried non-default Python3.4 on Ubuntu, but it seems that it
doesn't set up sys.path to include the "local" dir even when it
exists, so this fix doesn't actually help in that case.

- - - - -
608c977b by Fred Wright at 2017-11-12T14:05:25-08:00
Fixes FixConfig to ignore existing PYTHONPATH.

Since the purpose of FixConfig is to avoid paths which only work when
specified by PYTHONPATH, any existing PYTHONPATH definition needs to
be avoided when checking a path.  This is done by removing PYTHONPATH
from the environment used to run the external Python that obtains the
sys.path setup.

TESTED:
Ran "configure" on Ubuntu 14.04, CentOS 7, and Fedora 25.  Verified
that the resulting PYTHONDIR is unchanged in the normal no-PYTHONPATH
case.  Verified that defining PYTHONPATH to match OLD_PYTHONDIR no
longer alters the result where it perviously did (CentOS and Fedora).

- - - - -


1 changed file:

- wafhelpers/fix_python_config.py


Changes:

=====================================
wafhelpers/fix_python_config.py
=====================================
--- a/wafhelpers/fix_python_config.py
+++ b/wafhelpers/fix_python_config.py
@@ -1,6 +1,6 @@
 """Work around waf bugs related to Python config setup."""
 
-import os, sys
+import ast, os, sys
 
 from waflib import Utils  # pylint: disable=import-error
 from waflib.Logs import pprint  # pylint: disable=import-error
@@ -9,14 +9,23 @@ from waflib.Logs import pprint  # pylint: disable=import-error
 # the waf bugs are fixed.
 
 # The waf code for setting up PYTHONDIR and PYTHONARCHDIR is broken, because
-# get_python_lib() only returns the proper library locations when the 'prefix'
-# argument is absent or None, but waf insists on feeding it the PREFIX value.
-# To make matters worse, the design of waf's ConfigSet object makes it
+# get_python_lib() only returns guaranteed usable library locations when the
+# 'prefix' argument is absent or None, but waf insists on feeding it the PREFIX
+# value.  To make matters worse, the design of waf's ConfigSet object makes it
 # impossible to get it to return a value of None for any item, so merely
 # temporarily patching PREFIX doesn't work.  Thus, the most straightforward
 # workaround is to duplicate the relevant code with the properly omitted
 # 'prefix'.
 #
+# The downside of the prefixless get_python_lib() is that the result may not
+# be FHS-compliant, and may result in conflicts when a base install includes
+# this code and another version is installed later.  There doesn't seem to be
+# a universal solution to this, but it tries to do the best it can by using
+# waf's original prefixed result when it appears in the target Python's
+# sys.path (with any preexisting PYTHONPATH definition inhibited).
+# Unfortunately, it will only appear there if it already exists, even though
+# the install itself will create it if needed.
+#
 # In principle, there might be some value in allowing a prefix to be optionally
 # supplied (separately from PREFIX), but given that both values are already
 # overridable, there's little need for an additional option.
@@ -53,33 +62,33 @@ class FixConfig(object):
         """Capture values after option processing."""
         self.opts = self.conf.env.derive().detach()
 
-    def massage(self, path):
-        "Massage Python library path to get around upstream bug."
-        # This will produce an FHS-compliant installation if the
-        # proper local path pre-exists.
-        localized = path.replace(sys.prefix, self.conf.env.PREFIX)
-        if os.path.exists(localized) and localized in sys.path:
-            return localized
-        else:
-            return path
-
     def fix_python_libs(self):
         """Fix up library install paths."""
         # Remember original setting for "compatibility cleanup".
         self.conf.env.OLD_PYTHONDIR = self.conf.env.PYTHONDIR
         if Utils.is_win32:
             return  # No fixups supported on Windows
-        if not ('PYTHONDIR' in self.opts or 'PYTHONDIR' in self.conf.environ):
+        # Note that get_python_variables() doesn't work for sys.path
+        path_env = dict(os.environ)
+        path_env.pop('PYTHONPATH', None)  # Ignore any current PYTHONPATH
+        path_str = self.conf.cmd_and_log(self.conf.env.PYTHON
+                                         + ['-c',
+                                            'import sys; print(sys.path)'],
+                                         env=path_env)
+        sys_path = ast.literal_eval(path_str)
+        if (not ('PYTHONDIR' in self.opts or 'PYTHONDIR' in self.conf.environ)
+            and self.conf.env.PYTHONDIR not in sys_path):
             (pydir,) = self.conf.get_python_variables(
                 ["get_python_lib(plat_specific=0)"]
                 )
-            self.conf.env.PYTHONDIR = self.massage(pydir)
-        if not ('PYTHONARCHDIR' in self.opts
-                or 'PYTHONARCHDIR' in self.conf.environ):
+            self.conf.env.PYTHONDIR = pydir
+        if (not ('PYTHONARCHDIR' in self.opts
+                 or 'PYTHONARCHDIR' in self.conf.environ)
+            and self.conf.env.PYTHONARCHDIR not in sys_path):
             (pyarchdir,) = self.conf.get_python_variables(
                 ["get_python_lib(plat_specific=1)"]
                 )
-            self.conf.env.PYTHONARCHDIR = self.massage(pyarchdir or pydir)
+            self.conf.env.PYTHONARCHDIR = pyarchdir or pydir
 
     def load(self, *args, **kwargs):
         """Do the load and capture the options."""



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/06b1eaedb731ffa1ec64a1522b3e2eba9253423f...608c977b794ef9d32f19cf31a76874796994432b

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/06b1eaedb731ffa1ec64a1522b3e2eba9253423f...608c977b794ef9d32f19cf31a76874796994432b
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171113/e73a2717/attachment.html>


More information about the vc mailing list