[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Allow user to override python command

Nate DeSimone posted 1 patch 4 years, 4 months ago
Failed in applying to current master (apply log)
edkrepo_installer/linux-scripts/install.py | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Allow user to override python command
Posted by Nate DeSimone 4 years, 4 months ago
The --py flag will allow the user to specify a specific version of
python removing the need for the python3 sym-link on some systems.

Cc: Ashley DeSimone <ashley.e.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 edkrepo_installer/linux-scripts/install.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer/linux-scripts/install.py
index a05ce6a..e7d3f91 100755
--- a/edkrepo_installer/linux-scripts/install.py
+++ b/edkrepo_installer/linux-scripts/install.py
@@ -27,6 +27,7 @@ tool_sign_on = 'Installer for edkrepo version {}\nCopyright(c) Intel Corporation
 cfg_dir = '.edkrepo'
 cfg_src_dir = os.path.abspath('config')
 whl_src_dir = os.path.abspath('wheels')
+def_python = 'python3'

 def default_run(cmd):
     return subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)
@@ -45,6 +46,7 @@ def init_logger(verbose):
 def get_args():
     parser = ArgumentParser()
     parser.add_argument('-l', '--local', action='store_true', default=False, help='Install edkrepo to the user directory instead of system wide')
+    parser.add_argument('-p', '--py', action='store', default=None, help='Specify the python command to use when installing')
     parser.add_argument('-u', '--user', action='store', default=None, help='Specify user account to install edkrepo support on')
     parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Enables verbose output')
     return parser.parse_args()
@@ -75,7 +77,7 @@ def get_required_wheels():
                                                  'version':wheel.attrib['Version'],
                                                  'install':True}
             break
-    pip_cmd = ['python3', '-m', 'pip', 'list', '--legacy']
+    pip_cmd = [def_python, '-m', 'pip', 'list', '--legacy']
     try:
         res = default_run(pip_cmd)
     except:
@@ -117,8 +119,14 @@ def _check_version(current, expected):
     return 0

 def do_install():
+    global def_python
+    org_python = None
+
     # Parse command line
     args = get_args()
+    if args.py is not None:
+        org_python = def_python
+        def_python = args.py

     # Enable logging output
     log = init_logger(args.verbose)
@@ -132,6 +140,9 @@ def do_install():
     except:
         log.error('ERROR: Missing installer configuration file.')
         return 1
+    if org_python is not None:
+        cfg['req_tools'][def_python] = cfg['req_tools'][org_python]
+        cfg['req_tools'].pop(org_python)
     try:
         sha_data = configparser.ConfigParser(allow_no_value=True)
         sha_data.read(os.path.join(cfg_src_dir, 'sha_data.cfg'))
@@ -299,13 +310,13 @@ def do_install():
             uninstall_whl = wheels_to_install[whl_name]['uninstall']
             if uninstall_whl:
                 try:
-                    res = default_run(['python3', '-m', 'pip', 'uninstall', '--yes', whl_name])
+                    res = default_run([def_python, '-m', 'pip', 'uninstall', '--yes', whl_name])
                 except:
                     log.info('- Failed to uninstall {}'.format(whl_name))
                     return 1
                 log.info('+ Uninstalled {}'.format(whl_name))
             if install_whl:
-                install_cmd = ['python3', '-m', 'pip', 'install']
+                install_cmd = [def_python, '-m', 'pip', 'install']
                 if args.local:
                     install_cmd.append('--user')
                 install_cmd.append(os.path.join(whl_src_dir, whl))
--
2.20.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#52079): https://edk2.groups.io/g/devel/message/52079
Mute This Topic: https://groups.io/mt/67968732/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Allow user to override python command
Posted by Desimone, Ashley E 4 years, 4 months ago
Reviewed-by: Ashley DeSimone <ashley.e.desimone@intel.com>

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Nate DeSimone
Sent: Tuesday, December 10, 2019 1:55 AM
To: devel@edk2.groups.io
Cc: Desimone, Ashley E <ashley.e.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Allow user to override python command

The --py flag will allow the user to specify a specific version of python removing the need for the python3 sym-link on some systems.

Cc: Ashley DeSimone <ashley.e.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 edkrepo_installer/linux-scripts/install.py | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer/linux-scripts/install.py
index a05ce6a..e7d3f91 100755
--- a/edkrepo_installer/linux-scripts/install.py
+++ b/edkrepo_installer/linux-scripts/install.py
@@ -27,6 +27,7 @@ tool_sign_on = 'Installer for edkrepo version {}\nCopyright(c) Intel Corporation  cfg_dir = '.edkrepo'
 cfg_src_dir = os.path.abspath('config')  whl_src_dir = os.path.abspath('wheels')
+def_python = 'python3'

 def default_run(cmd):
     return subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True) @@ -45,6 +46,7 @@ def init_logger(verbose):
 def get_args():
     parser = ArgumentParser()
     parser.add_argument('-l', '--local', action='store_true', default=False, help='Install edkrepo to the user directory instead of system wide')
+    parser.add_argument('-p', '--py', action='store', default=None, 
+ help='Specify the python command to use when installing')
     parser.add_argument('-u', '--user', action='store', default=None, help='Specify user account to install edkrepo support on')
     parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Enables verbose output')
     return parser.parse_args()
@@ -75,7 +77,7 @@ def get_required_wheels():
                                                  'version':wheel.attrib['Version'],
                                                  'install':True}
             break
-    pip_cmd = ['python3', '-m', 'pip', 'list', '--legacy']
+    pip_cmd = [def_python, '-m', 'pip', 'list', '--legacy']
     try:
         res = default_run(pip_cmd)
     except:
@@ -117,8 +119,14 @@ def _check_version(current, expected):
     return 0

 def do_install():
+    global def_python
+    org_python = None
+
     # Parse command line
     args = get_args()
+    if args.py is not None:
+        org_python = def_python
+        def_python = args.py

     # Enable logging output
     log = init_logger(args.verbose)
@@ -132,6 +140,9 @@ def do_install():
     except:
         log.error('ERROR: Missing installer configuration file.')
         return 1
+    if org_python is not None:
+        cfg['req_tools'][def_python] = cfg['req_tools'][org_python]
+        cfg['req_tools'].pop(org_python)
     try:
         sha_data = configparser.ConfigParser(allow_no_value=True)
         sha_data.read(os.path.join(cfg_src_dir, 'sha_data.cfg')) @@ -299,13 +310,13 @@ def do_install():
             uninstall_whl = wheels_to_install[whl_name]['uninstall']
             if uninstall_whl:
                 try:
-                    res = default_run(['python3', '-m', 'pip', 'uninstall', '--yes', whl_name])
+                    res = default_run([def_python, '-m', 'pip', 
+ 'uninstall', '--yes', whl_name])
                 except:
                     log.info('- Failed to uninstall {}'.format(whl_name))
                     return 1
                 log.info('+ Uninstalled {}'.format(whl_name))
             if install_whl:
-                install_cmd = ['python3', '-m', 'pip', 'install']
+                install_cmd = [def_python, '-m', 'pip', 'install']
                 if args.local:
                     install_cmd.append('--user')
                 install_cmd.append(os.path.join(whl_src_dir, whl))
--
2.20.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#52134): https://edk2.groups.io/g/devel/message/52134
Mute This Topic: https://groups.io/mt/67968732/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-