Skip to content

Commit

Permalink
Ensure environs are strings on Python2 + Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jun 19, 2018
1 parent 9195d3a commit 8f1313c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pipenv/vendor/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f1313c

Please sign in to comment.