-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use unix line-endings in bash activate script
Signed-off-by: Siddhant Kumar <skumar619@bloomberg.net>
- Loading branch information
Siddhant Kumar
committed
Aug 16, 2020
1 parent
10f232b
commit 4246291
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use unix style line endings in bash activation script - by :user:`saytosid`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from virtualenv.info import IS_WIN | ||
from virtualenv.util.path import Path | ||
from virtualenv.util.six import ensure_text | ||
|
||
from ..via_template import ViaTemplateActivator | ||
|
||
|
||
class BashActivator(ViaTemplateActivator): | ||
def generate(self, creator): | ||
generated = super(BashActivator, self).generate(creator) | ||
if IS_WIN: | ||
_convert_to_unix_line_endings(generated) | ||
return generated | ||
|
||
def templates(self): | ||
yield Path("activate.sh") | ||
|
||
def as_name(self, template): | ||
return template.stem | ||
|
||
|
||
def _convert_to_unix_line_endings(generated): | ||
WINDOWS_LINE_ENDING = b"\r\n" | ||
UNIX_LINE_ENDING = b"\n" | ||
|
||
for file_path in generated: | ||
with open(ensure_text(str(file_path)), "rb") as open_file: | ||
content = open_file.read() | ||
|
||
content = content.replace(WINDOWS_LINE_ENDING, UNIX_LINE_ENDING) | ||
|
||
with open(ensure_text(str(file_path)), "wb") as open_file: | ||
open_file.write(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters