diff --git a/run/__init__.py b/run/__init__.py index fc3830c..2e6116c 100644 --- a/run/__init__.py +++ b/run/__init__.py @@ -50,6 +50,8 @@ __version__ = "0.0.8" +str_type = str if sys.version_info.major >= 3 else basestring + class std_output(str): @@ -118,7 +120,7 @@ class run(runmeta('base_run', (std_output, ), {})): @classmethod def create_process(cls, command, stdin, cwd, env, shell): return subprocess.Popen( - shlex.split(command), + shlex.split(command) if isinstance(command, str_type) else command, universal_newlines=True, shell=shell, cwd=cwd, @@ -173,7 +175,10 @@ def stderr(self): return std_output(self.process.communicate()[1]) def __repr__(self): - return " | ".join([e.command for e in self.chain]) + return " | ".join([ + e.command if isinstance(e.command, str_type) else ' '.join(e.command) + for e in self.chain + ]) if __name__ == "__main__": diff --git a/setup.py b/setup.py index e172d22..6ca2457 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ def run(self): setup(name='subprocess.run', version=run.__version__, data_files = [ - (get_python_lib(), [pth_file]), + (get_python_lib(prefix=''), [pth_file]), ], packages=find_packages(), author='Sebastian PawluĊ›', diff --git a/tests.py b/tests.py index 7c5bbb4..da6dc54 100644 --- a/tests.py +++ b/tests.py @@ -14,6 +14,7 @@ # dafault _commands class _commands: ls = 'ls -la' + ls_list = ['ls', '-la'] rm = 'rm -r' more = 'more' @@ -21,19 +22,26 @@ class _commands: if sys.platform.startswith('win'): class _commands: ls = 'dir' + ls_list = ['dir'] rm = 'rmdir' more = 'more' def test_run(): - output = run(_commands.ls) + to_run = [ + _commands.ls, + _commands.ls_list, + ] - assert output.lines - assert output + for cmd in to_run: + output = run(cmd) - assert isinstance(output.lines, list) - assert isinstance(output.qlines, list) - assert isinstance(output.qlines[0], list) + assert output.lines + assert output + + assert isinstance(output.lines, list) + assert isinstance(output.qlines, list) + assert isinstance(output.qlines[0], list) def test_stdout(): @@ -108,4 +116,4 @@ def test_stdin(): """python -c 'from run import run; print(run("wc -l", stdin=run.stdin).stdout)'""" ) - command.stdout.strip("\n") == run('ls -la', 'wc -l') \ No newline at end of file + command.stdout.strip("\n") == run('ls -la', 'wc -l')