From 7fe01ccaf35bba48f60dfb9e8fb40db923992b52 Mon Sep 17 00:00:00 2001 From: dthelegend Date: Wed, 10 Apr 2024 17:40:08 +0100 Subject: [PATCH 1/4] Remove use of environment python --- howdy-gtk/bin/howdy-gtk.in | 2 +- howdy-gtk/src/init.py | 2 +- howdy/src/bin/howdy.in | 2 +- howdy/src/cli.py | 2 +- howdy/src/compare.py | 2 +- howdy/src/pam/main.cc | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/howdy-gtk/bin/howdy-gtk.in b/howdy-gtk/bin/howdy-gtk.in index 1ea89f70..d3df5403 100644 --- a/howdy-gtk/bin/howdy-gtk.in +++ b/howdy-gtk/bin/howdy-gtk.in @@ -1,3 +1,3 @@ #!/bin/sh -env python3 "@script_path@" "$@" \ No newline at end of file +/usr/bin/python3 "@script_path@" "$@" \ No newline at end of file diff --git a/howdy-gtk/src/init.py b/howdy-gtk/src/init.py index 01a7bb33..ce3fd04e 100755 --- a/howdy-gtk/src/init.py +++ b/howdy-gtk/src/init.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # Opens auth ui if requested, otherwise starts normal ui import sys diff --git a/howdy/src/bin/howdy.in b/howdy/src/bin/howdy.in index 1ea89f70..d3df5403 100644 --- a/howdy/src/bin/howdy.in +++ b/howdy/src/bin/howdy.in @@ -1,3 +1,3 @@ #!/bin/sh -env python3 "@script_path@" "$@" \ No newline at end of file +/usr/bin/python3 "@script_path@" "$@" \ No newline at end of file diff --git a/howdy/src/cli.py b/howdy/src/cli.py index f923cb59..0e896b5b 100755 --- a/howdy/src/cli.py +++ b/howdy/src/cli.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # CLI directly called by running the howdy command # Import required modules diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 0b2213f6..e2f835fe 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # Compare incoming video with known faces # Running in a local python instance to get around PATH issues diff --git a/howdy/src/pam/main.cc b/howdy/src/pam/main.cc index d1b8e347..5bef3828 100644 --- a/howdy/src/pam/main.cc +++ b/howdy/src/pam/main.cc @@ -47,7 +47,7 @@ const auto DEFAULT_TIMEOUT = std::chrono::duration(100); const auto MAX_RETRIES = 5; -const auto PYTHON_EXECUTABLE = "python3"; +const auto PYTHON_EXECUTABLE = "/usr/bin/python3"; #define S(msg) gettext(msg) From 18aaee9fbb34b4598b4706e9c0c10120960b3d6f Mon Sep 17 00:00:00 2001 From: Daudi Wampamba Date: Thu, 2 May 2024 13:47:10 +0100 Subject: [PATCH 2/4] Apply suggestions from code review Thanks @musikid Co-authored-by: Sayafdine Said --- howdy-gtk/bin/howdy-gtk.in | 2 +- howdy-gtk/src/init.py | 1 - howdy/src/bin/howdy.in | 2 +- howdy/src/cli.py | 1 - howdy/src/compare.py | 1 - howdy/src/pam/main.cc | 2 +- 6 files changed, 3 insertions(+), 6 deletions(-) diff --git a/howdy-gtk/bin/howdy-gtk.in b/howdy-gtk/bin/howdy-gtk.in index d3df5403..64485f08 100644 --- a/howdy-gtk/bin/howdy-gtk.in +++ b/howdy-gtk/bin/howdy-gtk.in @@ -1,3 +1,3 @@ #!/bin/sh -/usr/bin/python3 "@script_path@" "$@" \ No newline at end of file +@python_path@ "@script_path@" "$@" \ No newline at end of file diff --git a/howdy-gtk/src/init.py b/howdy-gtk/src/init.py index ce3fd04e..b351050e 100755 --- a/howdy-gtk/src/init.py +++ b/howdy-gtk/src/init.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # Opens auth ui if requested, otherwise starts normal ui import sys diff --git a/howdy/src/bin/howdy.in b/howdy/src/bin/howdy.in index d3df5403..64485f08 100644 --- a/howdy/src/bin/howdy.in +++ b/howdy/src/bin/howdy.in @@ -1,3 +1,3 @@ #!/bin/sh -/usr/bin/python3 "@script_path@" "$@" \ No newline at end of file +@python_path@ "@script_path@" "$@" \ No newline at end of file diff --git a/howdy/src/cli.py b/howdy/src/cli.py index 0e896b5b..ebb6bc22 100755 --- a/howdy/src/cli.py +++ b/howdy/src/cli.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # CLI directly called by running the howdy command # Import required modules diff --git a/howdy/src/compare.py b/howdy/src/compare.py index e2f835fe..7a4f4a61 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 # Compare incoming video with known faces # Running in a local python instance to get around PATH issues diff --git a/howdy/src/pam/main.cc b/howdy/src/pam/main.cc index 5bef3828..91496cc0 100644 --- a/howdy/src/pam/main.cc +++ b/howdy/src/pam/main.cc @@ -47,7 +47,7 @@ const auto DEFAULT_TIMEOUT = std::chrono::duration(100); const auto MAX_RETRIES = 5; -const auto PYTHON_EXECUTABLE = "/usr/bin/python3"; +const auto PYTHON_EXECUTABLE = "@python_path@"; #define S(msg) gettext(msg) From 7246ff795a92d1dd2dbfd2557eb468b75187b2d6 Mon Sep 17 00:00:00 2001 From: dthelegend Date: Mon, 20 May 2024 19:59:37 +0100 Subject: [PATCH 3/4] python_path is now set from python meson finds --- howdy-gtk/meson.build | 2 +- howdy/src/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/howdy-gtk/meson.build b/howdy-gtk/meson.build index c8207999..08c9acac 100644 --- a/howdy-gtk/meson.build +++ b/howdy-gtk/meson.build @@ -65,7 +65,7 @@ interface_files = files( install_data(interface_files, install_dir: datadir) cli_path = join_paths(pysourcesinstalldir, 'init.py') -conf_data = configuration_data({ 'script_path': cli_path }) +conf_data = configuration_data({ 'script_path': cli_path, 'python_path': py.full_path() }) bin_name = 'howdy-gtk' bin = configure_file( diff --git a/howdy/src/meson.build b/howdy/src/meson.build index 2cff83af..b44a178c 100644 --- a/howdy/src/meson.build +++ b/howdy/src/meson.build @@ -153,7 +153,7 @@ install_man('../howdy.1') # endif cli_path = join_paths(pysourcesinstalldir, 'cli.py') -conf_data = configuration_data({ 'script_path': cli_path }) +conf_data = configuration_data({ 'script_path': cli_path, 'python_path': py.full_path() }) bin_name = 'howdy' bin = configure_file( From be6357bff42bfd1aff23074965f1be39d14a7ff9 Mon Sep 17 00:00:00 2001 From: dthelegend Date: Mon, 20 May 2024 20:10:26 +0100 Subject: [PATCH 4/4] add python_path to meson options --- howdy/src/meson.build | 5 +++-- howdy/src/pam/main.cc | 5 ++--- howdy/src/pam/paths.hh.in | 3 ++- meson.build | 2 ++ meson.options | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/howdy/src/meson.build b/howdy/src/meson.build index b44a178c..36dc05e3 100644 --- a/howdy/src/meson.build +++ b/howdy/src/meson.build @@ -2,13 +2,14 @@ if meson.is_subproject() project('howdy', 'cpp', license: 'MIT', version: 'beta', meson_version: '>= 0.64.0') endif -py = import('python').find_installation() -py.dependency() datadir = get_option('prefix') / get_option('datadir') / 'howdy' py_conf = configuration_data(paths_dict) py_conf.set('data_dir', datadir) +py = import('python').find_installation(paths_dict.get('python_path')) +py.dependency() + py_paths = configure_file( input: 'paths.py.in', output: 'paths.py', diff --git a/howdy/src/pam/main.cc b/howdy/src/pam/main.cc index 91496cc0..7cd1643c 100644 --- a/howdy/src/pam/main.cc +++ b/howdy/src/pam/main.cc @@ -47,7 +47,6 @@ const auto DEFAULT_TIMEOUT = std::chrono::duration(100); const auto MAX_RETRIES = 5; -const auto PYTHON_EXECUTABLE = "@python_path@"; #define S(msg) gettext(msg) @@ -268,12 +267,12 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv, } } - const char *const args[] = {PYTHON_EXECUTABLE, // NOLINT + const char *const args[] = {PYTHON_EXECUTABLE_PATH, // NOLINT COMPARE_PROCESS_PATH, username, nullptr}; pid_t child_pid; // Start the python subprocess - if (posix_spawnp(&child_pid, PYTHON_EXECUTABLE, nullptr, nullptr, + if (posix_spawnp(&child_pid, PYTHON_EXECUTABLE_PATH, nullptr, nullptr, const_cast(args), nullptr) != 0) { syslog(LOG_ERR, "Can't spawn the howdy process: %s (%d)", strerror(errno), errno); diff --git a/howdy/src/pam/paths.hh.in b/howdy/src/pam/paths.hh.in index 771db2a3..d8cd7ebc 100644 --- a/howdy/src/pam/paths.hh.in +++ b/howdy/src/pam/paths.hh.in @@ -1,3 +1,4 @@ const auto COMPARE_PROCESS_PATH = "@compare_script_path@"; const auto CONFIG_FILE_PATH = "@config_file_path@"; -const auto USER_MODELS_DIR = "@user_models_dir@"; \ No newline at end of file +const auto USER_MODELS_DIR = "@user_models_dir@"; +const auto PYTHON_EXECUTABLE_PATH = "@python_path@"; \ No newline at end of file diff --git a/meson.build b/meson.build index 8c629965..65a5bc6c 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,7 @@ dlibdatadir = get_option('dlib_data_dir') != '' ? get_option('dlib_data_dir') : confdir = get_option('config_dir') != '' ? get_option('config_dir') : join_paths(get_option('prefix'), get_option('sysconfdir'), 'howdy') usermodelsdir = get_option('user_models_dir') != '' ? get_option('user_models_dir') : join_paths(confdir, 'models') logpath = get_option('log_path') +pythonpath = get_option('python_path') config_path = join_paths(confdir, 'config.ini') @@ -12,6 +13,7 @@ paths_dict = { 'dlib_data_dir': dlibdatadir, 'user_models_dir': usermodelsdir, 'log_path': logpath, + 'python_path': pythonpath } # We need to keep this order beause howdy-gtk defines the gtk script path which is used later in howdy diff --git a/meson.options b/meson.options index 1a35b819..4c9940b3 100644 --- a/meson.options +++ b/meson.options @@ -6,4 +6,5 @@ option('user_models_dir', type: 'string', value: '', description: 'Set the user option('log_path', type: 'string', value: '/var/log/howdy', description: 'Set the log file path') option('install_in_site_packages', type: 'boolean', value: false, description: 'Install howdy python files in site packages') option('py_sources_dir', type: 'string', value: '', description: 'Set the python sources directory') +option('python_path', type: 'string', value: '/usr/bin/python', description: 'Set the path to the python executable') option('install_pam_config', type: 'boolean', value: false, description: 'Install pam config file (for Debian/Ubuntu)') \ No newline at end of file