hmrc / service-manager

A python tool to manage developing and testing with lots of microservices
Apache License 2.0
58 stars 37 forks source link

A Problem With Aliases #122

Open erasmos-hmrc opened 2 years ago

erasmos-hmrc commented 2 years ago

I installed the recommended version of Python (3.8).

On my system (MacOS), the binary was python3. However, I aliased it (via .zshrc) to python.

However, whenever I ran an sm command, I would get something like the following:

Traceback (most recent call last):
  File "/Users/seanrasmussen/.local/bin/sm", line 182, in <module>
    _process_command()
  File "/Users/seanrasmussen/.local/bin/sm", line 76, in _process_command
    for status_line in dostatus(context, args.shownotrunning):
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/smstatus.py", line 65, in dostatus
    for service in context.services():
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/smcontext.py", line 241, in <genexpr>
    return (self.get_service(service_name) for service_name in self.application.services)
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/smcontext.py", line 253, in get_service
    return SmPythonService(self, service_name)
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/service/smpythonservice.py", line 192, in __init__
    self.pattern = SmPythonService.get_pattern(self)
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/service/smpythonservice.py", line 249, in get_pattern
    if _is_python_3():
  File "/Users/seanrasmussen/.local/pipx/venvs/servicemanager/lib/python3.8/site-packages/servicemanager/service/smpythonservice.py", line 26, in _is_python_3
    proc = subprocess.Popen(["python", "--version"],
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'python'

After various attempts, I found that changing this line to use the shell worked:

   proc = subprocess.Popen(["python", "--version"],
                          shell=True,

Note that I'm not using pyenv as recommended.

erasmos-hmrc commented 2 years ago

Actually, I had to update the shell to be 'True' in all three places to make it work.