Skip to content

Commit

Permalink
Alias Bug Fix2
Browse files Browse the repository at this point in the history
Fixed a bug where if you made an alias it would update after you ran another command. Fix was to deepcopy the alias.get statement so the following commands.append wouldn't update the dict entry. Very strange bug to track down

Also fixed unused import in setup.py
  • Loading branch information
volitank committed Nov 10, 2021
1 parent f8bfb7b commit 88956bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyshell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
__author__ = 'volitank'
__license__ = 'GPLv3'
__copyright__ = '2021 volitank'
__version__ = '1.0.0a4'
__version__ = '1.0.0a5'

from .pyshell import pyshell, DEFAULT, DEVNULL, PIPE, STDOUT
9 changes: 6 additions & 3 deletions pyshell/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import builtins
import sys
from pathlib import Path
from copy import deepcopy
from inspect import getouterframes, currentframe
from subprocess import Popen, CalledProcessError, TimeoutExpired, SubprocessError, CompletedProcess, _USE_POSIX_SPAWN

Expand Down Expand Up @@ -294,10 +295,11 @@ def __call__(self, *args,
commands = [name]
# Check kwargs to see if an alias was set
# If it was set our commands to that

if self.alias is not None:
if self.alias.get(name):
commands = self.alias.get(name)
commands = deepcopy(self.alias.get(name))

# Now that possible aliases are set, we can append our arguments
for arg in args:
commands.append(arg)
Expand All @@ -306,6 +308,7 @@ def __call__(self, *args,
# This block says to error if we're not using the shell and we can't find the command.
# But if we're using the shell then send it anyway. I'm not sure why I did this.
# Maybe we should just send it no matter what?

if kwargs.get('shell') is None and self.kwargs.get('shell') is None:
if shutil.which(name) is not None or self.alias.get(name) is not None:
self.run( commands,
Expand All @@ -321,7 +324,7 @@ def __call__(self, *args,
logfile=logfile, timeout=timeout, **kwargs)

return self.process

def run(self, *popenargs,
input=None, capture_output=False, check=False,
logfile=None, timeout=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
from setuptools import setup
from pathlib import Path
import pyshell
# Define the directory that setup.py is in
Expand Down

0 comments on commit 88956bd

Please sign in to comment.