Skip to content

Commit

Permalink
Formatting and cleaning up diffs w/ master
Browse files Browse the repository at this point in the history
Signed-off-by: javrin <jawabiscuit@users.noreply.github.com>
  • Loading branch information
Jawabiscuit committed Sep 15, 2023
1 parent 0186176 commit d894bb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
19 changes: 6 additions & 13 deletions src/rezplugins/shell/_utils/powershell_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,29 @@ def shebang(self):
pass

def setenv(self, key, value):
is_path = self._is_pathed_key(key)
new_value = self.escape_string(value, is_path=is_path)

self._addline(
'Set-Item -Path "Env:{0}" -Value "{1}"'.format(key, new_value)
)
value = self.escape_string(value, is_path=self._is_pathed_key(key))
self._addline('Set-Item -Path "Env:{0}" -Value "{1}"'.format(key, value))

def prependenv(self, key, value):
is_path = self._is_pathed_key(key)
new_value = self.escape_string(value, is_path=is_path)
value = self.escape_string(value, is_path=self._is_pathed_key(key))

# Be careful about ambiguous case in pwsh on Linux where pathsep is :
# so that the ${ENV:VAR} form has to be used to not collide.
self._addline(
'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value)'
.format(key, new_value, self.pathsep)
.format(key, value, self.pathsep)
)

def appendenv(self, key, value):
is_path = self._is_pathed_key(key)
# Doesn't just escape, but can also perform path normalization
modified_value = self.escape_string(value, is_path=is_path)
value = self.escape_string(value, is_path=self._is_pathed_key(key))

# Be careful about ambiguous case in pwsh on Linux where pathsep is :
# so that the ${ENV:VAR} form has to be used to not collide.
# The nested Get-ChildItem call is set to SilentlyContinue to prevent
# an exception of the Environment Variable is not set already
self._addline(
'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value + "{1}{2}")'
.format(key, os.path.pathsep, modified_value))
.format(key, os.path.pathsep, value))

def unsetenv(self, key):
self._addline(
Expand Down
12 changes: 5 additions & 7 deletions src/rezplugins/shell/gitbash.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class GitBash(Bash):
"""Git Bash shell plugin."""
pathsep = ':'

_drive_regex = re.compile(r'([A-Za-z]):\\')
_drive_regex = re.compile(r"([A-Za-z]):\\")

@classmethod
def name(cls):
return 'gitbash'
return "gitbash"

@classmethod
def executable_name(cls):
Expand All @@ -51,7 +51,6 @@ def find_executable(cls, name, check_syspaths=False):
else:
return settings.executable_fullpath

# Find the gitbash bash executable using the windows registry.
exepath = Bash.find_executable(name, check_syspaths=check_syspaths)

if exepath and "system32" in exepath.lower():
Expand All @@ -62,9 +61,8 @@ def find_executable(cls, name, check_syspaths=False):
"plugins.shell.gitbash.executable_fullpath.",
exepath
)
raise ValueError("Gitbash executable is not correct: %s" % exepath)

exepath = exepath.replace('\\', '\\\\')
exepath = exepath.replace("\\", "\\\\")

return exepath

Expand Down Expand Up @@ -92,7 +90,7 @@ def get_syspaths(cls):
out_, _ = p.communicate()
if p.returncode == 0:
lines = out_.split('\n')
line = [x for x in lines if '__PATHS_' in x.split()][0]
line = [x for x in lines if "__PATHS_" in x.split()][0]
# note that we're on windows, but pathsep in bash is ':'
paths = line.strip().split()[-1].split(':')
else:
Expand Down Expand Up @@ -187,7 +185,7 @@ def lowrepl(match):
return normalized_path

def shebang(self):
self._addline('#! /usr/bin/env bash')
self._addline("#!/usr/bin/env bash")


def register_plugin():
Expand Down
1 change: 0 additions & 1 deletion src/rezplugins/shell/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def escape_string(
if is_shell_path:
txt = self.as_shell_path(txt)
elif is_path:
# potentially calls plugin shell's normalize
txt = self.normalize_paths(txt)

txt = txt.replace('\\', '\\\\')
Expand Down

0 comments on commit d894bb3

Please sign in to comment.