Skip to content

Commit

Permalink
Add support for environment variables (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored Jul 20, 2020
1 parent 317826f commit e9b8519
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.2.1

- Custom enviroment variables can be passed to commands

## v0.2.0

- Support for cwd when executing commands
Expand Down
2 changes: 2 additions & 0 deletions docs/api_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ API Documentation
:type sudo: string
:param cwd: Working directory of the command being executed
:type cwd: string
:param env: Environment variables that would be available when the command is being executed
:type env: dict(str, str)
:param stream: When set to true, the output of your command will be streamed. (It does not work with piped commands)
:type stream: bool
:param timeout: The timeout for the process in seconds
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='soldier',
version='0.2.0',
version='0.2.1',
author='Yash Mehrotra',
author_email='[email protected]',
packages=['soldier'],
Expand Down
2 changes: 2 additions & 0 deletions soldier/soldier.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, command, **kwargs):
self._in_shell = kwargs.get('shell', False)
self._is_alive = False
self._cwd = kwargs.get('cwd', None)
self._env = kwargs.get('env', None)
self._stream = kwargs.get('stream', False)
self._std_in = kwargs.get('std_in', False)
self._output = kwargs.get('std_in', None) # Hack, think of better way
Expand Down Expand Up @@ -120,6 +121,7 @@ def _run(self):
self._process = Popen(comm,
shell=self._in_shell,
cwd=self._cwd,
env=self._env,
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_cwd(self):
output = soldier.run('ls | grep {}'.format(self.testdir), cwd=self.testdir).\
output.strip()

assert output == ''

def test_cwd(self):
output = soldier.run('printenv', env={'TEST_VAR': 'VALUE'}).\
output.strip()

assert output == 'TEST_VAR=VALUE'

def test_rmdir(self):
soldier.run('rmdir {}'.format(self.testdir))
assert not os.path.exists(os.getcwd() + '/' + self.testdir)

0 comments on commit e9b8519

Please sign in to comment.