Skip to content

Commit

Permalink
Merge pull request #2386 from pypa/python2-dotenv-subprocess-conflict
Browse files Browse the repository at this point in the history
Ensure environs are strings on Python 2 + Windows
  • Loading branch information
techalchemy authored Jun 22, 2018
2 parents beb6aef + 154f13a commit 82bf57a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/2386.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patched ``python-dotenv`` to ensure that environment variables always get encoded to the filesystem encoding.
1 change: 1 addition & 0 deletions news/2386.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patched ``python-dotenv`` to ensure that environment variables always get encoded to the filesystem encoding.
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 82bf57a

Please sign in to comment.