From 8f1313c65f4924edc1d92879e949224a439795ac Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 20 Jun 2018 00:27:15 +0800 Subject: [PATCH] Ensure environs are strings on Python2 + Windows Patch based on theskumar/python-dotenv#101 by @greyli. --- pipenv/vendor/dotenv/main.py | 8 ++++++++ .../vendor/dotenv-windows-unicode.patch | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch diff --git a/pipenv/vendor/dotenv/main.py b/pipenv/vendor/dotenv/main.py index 3d1bd72f34..4e1b4b4698 100644 --- a/pipenv/vendor/dotenv/main.py +++ b/pipenv/vendor/dotenv/main.py @@ -94,6 +94,14 @@ def set_as_environment_variables(self, override=False): for k, v in self.dict().items(): if k in os.environ and not override: continue + # With Python2 on Windows, force environment variables to str to + # avoid "TypeError: environment can only contain strings" in + # Python's subprocess module. + if sys.version_info.major < 3 and sys.platform == 'win32': + if not isinstance(k, str): + k = k.encode(sys.getdefaultencoding()) + if not isinstance(v, str): + v = v.encode(sys.getdefaultencoding()) os.environ[k] = v return True diff --git a/tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch b/tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch new file mode 100644 index 0000000000..4fcfdebfb2 --- /dev/null +++ b/tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch @@ -0,0 +1,19 @@ +diff --git a/pipenv/vendor/dotenv/main.py b/pipenv/vendor/dotenv/main.py +index 3d1bd72f..4e1b4b46 100644 +--- a/pipenv/vendor/dotenv/main.py ++++ b/pipenv/vendor/dotenv/main.py +@@ -94,6 +94,14 @@ class DotEnv(): + for k, v in self.dict().items(): + if k in os.environ and not override: + continue ++ # With Python2 on Windows, force environment variables to str to ++ # avoid "TypeError: environment can only contain strings" in ++ # Python's subprocess module. ++ if sys.version_info.major < 3 and sys.platform == 'win32': ++ if not isinstance(k, str): ++ k = k.encode(sys.getdefaultencoding()) ++ if not isinstance(v, str): ++ v = v.encode(sys.getdefaultencoding()) + os.environ[k] = v + + return True