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 1341b28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pipenv/vendor/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ 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 Python 2 on Windows, ensuree environment variables are
# system strings to avoid "TypeError: environment can only contain
# strings" in Python's subprocess module.
if sys.version_info.major < 3 and sys.platform == 'win32':
from pipenv.utils import fs_str
k = fs_str(k)
v = fs_str(v)
os.environ[k] = v

return True
Expand Down
18 changes: 18 additions & 0 deletions tasks/vendoring/patches/vendor/dotenv-windows-unicode.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/pipenv/vendor/dotenv/main.py b/pipenv/vendor/dotenv/main.py
index 3d1bd72f..75f49c4a 100644
--- a/pipenv/vendor/dotenv/main.py
+++ b/pipenv/vendor/dotenv/main.py
@@ -94,6 +94,13 @@ class DotEnv():
for k, v in self.dict().items():
if k in os.environ and not override:
continue
+ # With Python 2 on Windows, ensuree environment variables are
+ # system strings to avoid "TypeError: environment can only contain
+ # strings" in Python's subprocess module.
+ if sys.version_info.major < 3 and sys.platform == 'win32':
+ from pipenv.utils import fs_str
+ k = fs_str(k)
+ v = fs_str(v)
os.environ[k] = v

return True

0 comments on commit 1341b28

Please sign in to comment.