[Git][NTPsec/ntpsec][fixinstall] Revert build to the Old Ways re: python install.

Ian Bruene gitlab at mg.gitlab.com
Fri Jan 5 13:56:55 UTC 2018


Ian Bruene pushed to branch fixinstall at NTPsec / ntpsec


Commits:
50daea95 by Ian Bruene at 2018-01-05T07:56:27-06:00
Revert build to the Old Ways re: python install.

This reverts all of the changes associated with the fix_python_config.py
script. The build will no longer throw up in /usr/ when prefix==/usr/local/

- - - - -


12 changed files:

- INSTALL
- contrib/ntpheat
- contrib/ntpheatusb
- devel/testing.txt
- ntpclients/ntpdig.py
- ntpclients/ntploggps.py
- ntpclients/ntplogtemp.py
- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- pylib/wscript
- − wafhelpers/fix_python_config.py
- wscript


Changes:

=====================================
INSTALL
=====================================
--- a/INSTALL
+++ b/INSTALL
@@ -50,6 +50,14 @@ Python 2.x, x >= 6, or Python 3.x, x >= 3::
    Python 3.  Note that you will need both the ordinary Python
    installation and Python dev tools, if your OS makes such a
    distinction.
+   
+   Some OS distros won't find our installed python libraries.
+   Your shell may need something like this:
+     export PYTHONPATH=/usr/local/lib/python2.7/site-packages
+   CentOS 6 is using python 2.6
+     export PYTHONPATH=/usr/local/lib/python2.6/site-packages
+   (I put it in my .bashrc)
+
 
 argparse::
    Required for ntpviz when using Python version 2.6


=====================================
contrib/ntpheat
=====================================
--- a/contrib/ntpheat
+++ b/contrib/ntpheat
@@ -24,7 +24,8 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpheat: can't find Python NTP modules.\n%s\n" % e)
+    sys.stderr.write("ntpheat: can't find Python NTP modules. "
+                     "-- check PYTHONPATH.\n%s\n" % e)
     sys.exit(1)
 
 # Work with argvars


=====================================
contrib/ntpheatusb
=====================================
--- a/contrib/ntpheatusb
+++ b/contrib/ntpheatusb
@@ -37,7 +37,8 @@ import time
 try:
     import ntp.util
 except ImportError as e:
-    sys.stderr.write("ntpheatusb: can't find Python NTP modules.\n%s\n" % e)
+    sys.stderr.write("ntpheatusb: can't find Python NTP modules. "
+                     "-- check PYTHONPATH.\n%s\n" % e)
     sys.exit(1)
 
 


=====================================
devel/testing.txt
=====================================
--- a/devel/testing.txt
+++ b/devel/testing.txt
@@ -13,7 +13,7 @@ directory to build/main/ntpclients/ and run ./ntpq there. If you get a message
 that says
 
 ---------------------------------------------------------------------
-ntpq: can't find Python NTP library.
+ntpq: can't find Python NTP library -- check PYTHONPATH.
 ---------------------------------------------------------------------
 
 you *may* have a problem.  A lot of what was C code in legacy versions


=====================================
ntpclients/ntpdig.py
=====================================
--- a/ntpclients/ntpdig.py
+++ b/ntpclients/ntpdig.py
@@ -52,7 +52,7 @@ try:
     import ntp.util
 except ImportError as e:
     sys.stderr.write(
-        "ntpdig: can't find Python NTP library.\n")
+        "ntpdig: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntploggps.py
=====================================
--- a/ntpclients/ntploggps.py
+++ b/ntpclients/ntploggps.py
@@ -48,7 +48,7 @@ try:
     import ntp.util
 except ImportError as e:
     sys.stderr.write(
-        "ntploggps: can't find Python NTP library.\n")
+        "ntploggps: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntplogtemp.py
=====================================
--- a/ntpclients/ntplogtemp.py
+++ b/ntpclients/ntplogtemp.py
@@ -35,7 +35,7 @@ try:
     import ntp.util
 except ImportError as e:
     sys.stderr.write(
-        "ntplogtemp: can't find Python NTP library.\n")
+        "ntplogtemp: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpmon.py
=====================================
--- a/ntpclients/ntpmon.py
+++ b/ntpclients/ntpmon.py
@@ -40,7 +40,7 @@ try:
     import ntp.version
 except ImportError as e:
     sys.stderr.write(
-        "ntpmon: can't find Python NTP library.\n")
+        "ntpmon: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
ntpclients/ntpq.py
=====================================
--- a/ntpclients/ntpq.py
+++ b/ntpclients/ntpq.py
@@ -30,7 +30,7 @@ try:
     import ntp.version
 except ImportError as e:
     sys.stderr.write(
-        "ntpq: can't find Python NTP library.\n")
+        "ntpq: can't find Python NTP library -- check PYTHONPATH.\n")
     sys.stderr.write("%s\n" % e)
     sys.exit(1)
 


=====================================
pylib/wscript
=====================================
--- a/pylib/wscript
+++ b/pylib/wscript
@@ -1,5 +1,4 @@
 from waflib import Utils  # pylint: disable=import-error
-from wafhelpers.fix_python_config import FixConfig
 
 
 def options(opt):
@@ -7,9 +6,8 @@ def options(opt):
 
 
 def configure(conf):
-    fixed = FixConfig(conf)
-    fixed.load('python')
-    fixed.check_python_version((2, 6, 0))
+    conf.load('python')
+    conf.check_python_version((2, 6, 0))
     conf.check_python_headers(features='pyext')  # Extension-only, no embedded
 
 


=====================================
wafhelpers/fix_python_config.py deleted
=====================================
--- a/wafhelpers/fix_python_config.py
+++ /dev/null
@@ -1,120 +0,0 @@
-"""Work around waf bugs related to Python config setup."""
-
-import ast, os, sys
-
-from waflib import Utils  # pylint: disable=import-error
-from waflib.Logs import pprint  # pylint: disable=import-error
-
-# NOTE:  Everything in this file relates to waf bugs.  It can go away once
-# the waf bugs are fixed.
-
-# The waf code for setting up PYTHONDIR and PYTHONARCHDIR is broken, because
-# 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.
-#
-# Naturally, the fix doesn't override user-supplied values, but the fixup runs
-# after the version check, using the captured original settings to determine
-# whether to override.
-
-# An additional function is temporarily needed to clean up any libraries
-# that had been installed to the incorrect PYTHONDIR by former
-# versions of the script.
-#
-# Although this code is a NOP when the old and new install locations are
-# identical, for maximum safety the extra deletions are done preinstall
-# and postuninstall.  This might matter if the old and new locations were
-# symlinked together (a possible workaround for the old bug).
-#
-# Merely removing the libraries doesn't remove the containing directory(s)
-# which may have been newly created by the old script.  Removing any such
-# directories is desirable, but doing so automatically would be too
-# dangerous.  The compromise is to issue a warning message when an empty
-# containing directory is left.  This is always done at the end, to avoid
-# burying the warning in the install messages.
-
-
-class FixConfig(object):
-    """Methods and state for working around waf's python-config bugs."""
-
-    def __init__(self, conf):
-        """Initialize state from conf object."""
-        self.conf = conf
-        self.opts = None
-
-    def get_options(self):
-        """Capture values after option processing."""
-        self.opts = self.conf.env.derive().detach()
-
-    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
-        # 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 = 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 = pyarchdir or pydir
-
-    def load(self, *args, **kwargs):
-        """Do the load and capture the options."""
-        self.conf.load(*args, **kwargs)
-        self.get_options()
-
-    def check_python_version(self, *args, **kwargs):
-        """Check version and fix up install paths."""
-        self.conf.check_python_version(*args, **kwargs)
-        self.fix_python_libs()
-
-    @staticmethod
-    def cleanup_python_libs(ctx, cmd='preinstall'):
-        """Remove any Python libs that were installed to the wrong location."""
-        if not ctx.env.PYTHONDIR:
-            return  # Here on pre-setup call
-        if ctx.env.PYTHONDIR == ctx.env.OLD_PYTHONDIR:
-            return  # Here when old bug had no effect
-        if not os.path.isdir(ctx.env.OLD_PYTHONDIR):
-            return  # Here when old dir doesn't exist or isn't a dir
-        if cmd in ('preinstall', 'uninstall'):
-            ctx.exec_command('rm -rf %s/ntp' % ctx.env.OLD_PYTHONDIR)
-        if cmd == 'preinstall':
-            return  # Skip message where it's not likely to be seen
-        # See if we may have left an inappropriate empty directory
-        if not os.listdir(ctx.env.OLD_PYTHONDIR):
-            pprint('YELLOW',
-                   'May need to manually remove %s' % ctx.env.OLD_PYTHONDIR)


=====================================
wscript
=====================================
--- a/wscript
+++ b/wscript
@@ -24,7 +24,6 @@ from wafhelpers.options import options_cmd
 from wafhelpers.probes \
     import probe_header_with_prerequisites, probe_function_with_prerequisites
 from wafhelpers.test import test_write_log, test_print_log
-from wafhelpers.fix_python_config import FixConfig
 
 
 pprint.__doc__ = None
@@ -1018,9 +1017,6 @@ def afterparty(ctx):
     # expected to work.
     if ctx.cmd == 'clean':
         ctx.exec_command("rm -f ntpd/version.h ")
-    if ctx.cmd in ('uninstall', 'install'):
-        # Make sure libs are removed from the old location
-        FixConfig.cleanup_python_libs(ctx, ctx.cmd)
     for x in ("ntpclients", "tests/pylib",):
         # List used to be longer...
         path_build = ctx.bldnode.make_node("pylib")
@@ -1062,10 +1058,6 @@ def build(ctx):
         # the build directory never happens.  This is how we foil that.
         ctx.add_pre_fun(lambda ctx: ctx.exec_command("rm -f pylib/*.py[co]"))
 
-    if ctx.cmd == "install":
-        # Make sure libs are removed from the old location
-        ctx.add_pre_fun(FixConfig.cleanup_python_libs)
-
     if ctx.env.ENABLE_DOC_USER:
         if ctx.variant != "main":
             ctx.recurse("docs")
@@ -1141,8 +1133,8 @@ def build(ctx):
 
     if ctx.cmd == "build":
         if "PYTHONPATH" in os.environ:
-            print("--- PYTHONPATH is set, "
-                  "this may mask or cause library-related problems ---")
+            print("--- PYTHONPATH is not set, "
+                  "loading the Python ntp library may be troublesome ---")
 
 #
 # Boot script setup



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/50daea95f4ee40e32f0e8ec27e677fd35f712be7

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/50daea95f4ee40e32f0e8ec27e677fd35f712be7
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/20180105/13aeefc8/attachment.html>


More information about the vc mailing list