Including PATH in the env we pass to the subprocess.run causes my git to use /usr/local/git/etc/gitconfig which refers to files that don't exist in my homedir (~/.gitcinclude, `~/.gitignore, etc.).
|
component_env = { |
|
"SYSTEMROOT": os.environ.get("SYSTEMROOT", ""), # win32 |
|
"VIRTUAL_ENV": str(self.venv_path), |
|
"PATH": f"{str(bin_path)}:{os.environ.get('PATH')}", |
|
} |
|
subprocess.run(cmd, env=component_env) |
I verified this by running the following after activating virtualenv created by agentos for the agent:
python
>>> import subprocess
>>> subprocess.run(['/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin/python', '-m', 'pip', 'install', '-r', '/Users/andyk/Development/agentos/example_agents/papag/requirements.txt'], env={'SYSTEMROOT': '', 'VIRTUAL_ENV': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226', 'PATH': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/andyk/.gem/ruby/2.7.0/bin:/opt/homebrew/Caskroom/miniforge/base/envs/agentos_dev2/bin:/opt/homebrew/Caskroom/miniforge/base/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin'})
which fails with:
...
Cloning https://github.com/ikostrikov/pytorch-a2c-ppo-acktr-gail to /private/tmp/pip-req-build-0tvyih8o
Running command git clone --filter=blob:none --quiet https://github.com/ikostrikov/pytorch-a2c-ppo-acktr-gail /private/tmp/pip-req-build-0tvyih8o
fatal: failed to expand user dir in: '~/.gitignore'
the ~/.gitignore' in the error is referring to a line in /usr/local/git/etc/gitconfig.
And then I run it again, but remove /usr/local/bin from the PATH in the command:
python
>>> import subprocess
>>> subprocess.run(['/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin/python', '-m', 'pip', 'install', '-r', '/Users/andyk/Development/agentos/example_agents/papag/requirements.txt'], env={'SYSTEMROOT': '', 'VIRTUAL_ENV': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226', 'PATH': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/andyk/.gem/ruby/2.7.0/bin:/opt/homebrew/Caskroom/miniforge/base/envs/agentos_dev2/bin:/opt/homebrew/Caskroom/miniforge/base/condabin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin'})
...and the pip install runs fine.
Running the pip command directly in my bash shell works fine. That is, the following works fine (note that PATH is the same):
> echo $PATH
/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/andyk/.gem/ruby/2.7.0/bin:/opt/homebrew/Caskroom/miniforge/base/envs/agentos_dev2/bin:/opt/homebrew/Caskroom/miniforge/base/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin
> agentos run agent --entry-point learn --arg-set-file a2c_pong_args.yaml
I believe the problem is that we are currently passing shell=False to subprocess.run(), and so git is behaving differently for that subprocess than it does for me inside my shell (i.e., git seems to be using that conf file /usr/local/git/etc/gitconfig but not for my shell.
I verified this by running the same python command inside the virtualenv as before, except i set shell=True and it succeeds:
python
>>> import subprocess
>>> subprocess.run(['/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin/python', '-m', 'pip', 'install', '-r', '/Users/andyk/Development/agentos/example_agents/papag/requirements.txt'], env={'SYSTEMROOT': '', 'VIRTUAL_ENV': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226', 'PATH': '/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/Users/andyk/.agentos/cache/requirements_cache/python3.9/6ca95402f3200676689cbf632041895fb1b022e6c898c9bfc4439e4fcb0bb226/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/andyk/.gem/ruby/2.7.0/bin:/opt/homebrew/Caskroom/miniforge/base/envs/agentos_dev2/bin:/opt/homebrew/Caskroom/miniforge/base/condabin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Postgres.app/Contents/Versions/latest/bin'}, shell=True)
Including PATH in the env we pass to the
subprocess.runcauses mygitto use/usr/local/git/etc/gitconfigwhich refers to files that don't exist in my homedir (~/.gitcinclude, `~/.gitignore, etc.).agentos/pcs/virtual_env.py
Lines 214 to 219 in 4030b81
I verified this by running the following after activating virtualenv created by agentos for the agent:
which fails with:
the
~/.gitignore'in the error is referring to a line in/usr/local/git/etc/gitconfig.And then I run it again, but remove
/usr/local/binfrom the PATH in the command:...and the pip install runs fine.
Running the pip command directly in my bash shell works fine. That is, the following works fine (note that PATH is the same):
I believe the problem is that we are currently passing shell=False to
subprocess.run(), and so git is behaving differently for that subprocess than it does for me inside my shell (i.e., git seems to be using that conf file/usr/local/git/etc/gitconfigbut not for my shell.I verified this by running the same python command inside the virtualenv as before, except i set
shell=Trueand it succeeds: