public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Desimone, Ashley E" <ashley.e.desimone@intel.com>
To: "Desimone, Nathaniel L" <nathaniel.l.desimone@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Pandya, Puja" <puja.pandya@intel.com>
Subject: Re: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Python 2.x deprecation warning in pip breaks EdkRepoInstaller
Date: Thu, 31 Oct 2019 22:44:37 +0000	[thread overview]
Message-ID: <4CF3A9EB60ABDA47BE7821A4DA3A0A3353C93A6A@ORSMSX116.amr.corp.intel.com> (raw)
In-Reply-To: <20191030234815.4506-1-nathaniel.l.desimone@intel.com>

Reviewed-by: Ashley DeSimone <ashley.e.desimone@intel.com>

-----Original Message-----
From: Desimone, Nathaniel L 
Sent: Wednesday, October 30, 2019 4:48 PM
To: devel@edk2.groups.io
Cc: Desimone, Ashley E <ashley.e.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>
Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Python 2.x deprecation warning in pip breaks EdkRepoInstaller

Newer versions of pip add the following output in addition to the JSON output when running on Python 2.7:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

This breaks machine parsing of the JSON output from pip.
Adding logic to strip the deprecation warning to fix this issue.

Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
---
 .../EdkRepoInstaller/PythonOperations.cs      | 37 +++++++++++++++++--
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/edkrepo_installer/EdkRepoInstaller/PythonOperations.cs b/edkrepo_installer/EdkRepoInstaller/PythonOperations.cs
index f96502c..73d5bec 100644
--- a/edkrepo_installer/EdkRepoInstaller/PythonOperations.cs
+++ b/edkrepo_installer/EdkRepoInstaller/PythonOperations.cs
@@ -600,17 +600,48 @@ namespace TianoCore.EdkRepoInstaller
             return PythonPackages;         } +        private static string SanitizePipOutput(string PipOutput)+        {+            StringBuilder Sanitized = new StringBuilder();+            IEnumerable<string> PipLines = PipOutput.SplitLines();+            foreach(string line in PipLines)+            {+                if(line.StartsWith("DEPRECATION:"))+                {+                    continue;+                }+                if (string.IsNullOrWhiteSpace(line))+                {+                    continue;+                }+                Sanitized.Append(line.Trim());+                Sanitized.Append("\r\n");+            }+            return Sanitized.ToString().Trim();+        }+         public static List<PythonPackage> GetInstalledPythonPackages(string PythonPath)         {             List<PythonPackage> PythonPackages = new List<PythonPackage>();             SilentProcess.StdoutDataCapture dataCapture = new SilentProcess.StdoutDataCapture();             SilentProcess process = SilentProcess.StartConsoleProcessSilently(PythonPath, "-m pip list --format=\"json\" --no-index", dataCapture.DataReceivedHandler);             process.WaitForExit();+            bool TryLegacy = true;             if (process.ExitCode == 0)             {-                PythonPackages = ParseJsonPipList(dataCapture.GetData());+                try+                {+                    PythonPackages = ParseJsonPipList(SanitizePipOutput(dataCapture.GetData()));+                    TryLegacy = false;+                }+                catch(Exception e)+                {+                    InstallLogger.Log("Error occurred while trying to parse pip JSON:");+                    InstallLogger.Log(e.ToString());+                    InstallLogger.Log("Falling back to legacy mode");+                }             }-            else+            if(TryLegacy)             {                 //                 // Older versions of pip don't support the --format flag, parse the legacy format@@ -620,7 +651,7 @@ namespace TianoCore.EdkRepoInstaller
                 process.WaitForExit();                 if (process.ExitCode == 0)                 {-                    PythonPackages = ParseLegacyPipList(dataCapture.GetData());+                    PythonPackages = ParseLegacyPipList(SanitizePipOutput(dataCapture.GetData()));                 }             }             return PythonPackages;-- 
2.23.0.windows.1


      reply	other threads:[~2019-10-31 22:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 23:48 [edk2-staging/EdkRepo] [PATCH] EdkRepo: Python 2.x deprecation warning in pip breaks EdkRepoInstaller Nate DeSimone
2019-10-31 22:44 ` Desimone, Ashley E [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CF3A9EB60ABDA47BE7821A4DA3A0A3353C93A6A@ORSMSX116.amr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox