From a9797ef2bd2e4618a61c88b5dc6c7062e2a334e7 Mon Sep 17 00:00:00 2001 From: GibbonJojo <47012283+GibbonJojo@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:37:57 +0100 Subject: [PATCH 1/2] Add option to specify python version for virtualenv --- lib/fpm/package/virtualenv.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/fpm/package/virtualenv.rb b/lib/fpm/package/virtualenv.rb index 158bd98c92..37288c3e0c 100644 --- a/lib/fpm/package/virtualenv.rb +++ b/lib/fpm/package/virtualenv.rb @@ -48,6 +48,11 @@ class FPM::Package::Virtualenv < FPM::Package :multivalued => true, :attribute_name => :virtualenv_find_links_urls, :default => nil + option "--python", "PYTHON_EXECUTABLE", "interpreter based on what to create environment "\ + "(path/identifier) - by default use the interpreter where virtualenv is installed - "\ + "first found wins", + :default => nil + private # Input a package. @@ -100,13 +105,20 @@ def input(package) ::FileUtils.mkdir_p(virtualenv_build_folder) + virtualenv_args = ["virtualenv", virtualenv_build_folder] + if self.attributes[:virtualenv_system_site_packages?] logger.info("Creating virtualenv with --system-site-packages") - safesystem("virtualenv", "--system-site-packages", virtualenv_build_folder) - else - safesystem("virtualenv", virtualenv_build_folder) + virtualenv_args << virtualenv_build_folder end + if self.attributes[:python?] + logger.info("Creating virtualenv with python executable #{self.attributes[:python]}") + virtualenv_args.concat(["--python", self.attributes[:python]]) + end + + safesystem(*virtualenv_args) + pip_exe = File.join(virtualenv_build_folder, "bin", "pip") python_exe = File.join(virtualenv_build_folder, "bin", "python") From 62f4e6592dfb1d49a99a87d9ff3bfbd96f514bac Mon Sep 17 00:00:00 2001 From: GibbonJojo <47012283+GibbonJojo@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:58:42 +0100 Subject: [PATCH 2/2] Fix stuff, because I can't Ruby --- lib/fpm/package/virtualenv.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fpm/package/virtualenv.rb b/lib/fpm/package/virtualenv.rb index 37288c3e0c..f7339926f1 100644 --- a/lib/fpm/package/virtualenv.rb +++ b/lib/fpm/package/virtualenv.rb @@ -112,9 +112,9 @@ def input(package) virtualenv_args << virtualenv_build_folder end - if self.attributes[:python?] - logger.info("Creating virtualenv with python executable #{self.attributes[:python]}") - virtualenv_args.concat(["--python", self.attributes[:python]]) + if self.attributes[:virtualenv_python] + logger.info("Creating virtualenv with python executable #{self.attributes[:virtualenv_python]}") + virtualenv_args.concat(["--python", self.attributes[:virtualenv_python]]) end safesystem(*virtualenv_args)