From: Jason Ish Date: Tue, 3 May 2022 19:11:03 +0000 (-0600) Subject: entry point: update sys.path for non-distutils install X-Git-Tag: 1.3.0rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4920cf317c75160a62b6ce667da8132bf2a3db76;p=thirdparty%2Fsuricata-update.git entry point: update sys.path for non-distutils install When bundled with Suricata, Suricata-Update will not be installed with distutils/setuptools and will be installed in a custom location. Update the search path for these changes. This will still work correctly if installed from pip, or running from a custom directory not bundled with Suricata. Issue: #5313 --- diff --git a/bin/suricata-update b/bin/suricata-update index f2e8557..94ea2ba 100755 --- a/bin/suricata-update +++ b/bin/suricata-update @@ -20,12 +20,15 @@ import sys import os exec_dir = os.path.dirname(__file__) -version_info = sys.version_info -pyver = "%d.%d" % (version_info.major, version_info.minor) -site_path = "%s/../lib/python%s/site-packages" % (exec_dir, pyver) -if os.path.exists("%s/suricata/update" % (site_path)): - sys.path.insert(0, site_path) +# Check if we were installed along with Suricata, and setup the path if so. +libpath = os.path.realpath( + os.path.join(exec_dir, os.pardir, "lib/suricata/python")) +if os.path.exists(os.path.join(libpath, "suricata", "update")): + sys.path.insert(0, libpath) + +# If running out of the source directory, make sure we pick up the +# library from the current directory. sys.path.insert( 0, os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))))