Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure environs are strings on Python 2 + Windows #2386

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to just do this all the time? Why not just always use fs_str here?

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