diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 0000000..95cb3ee --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1 @@ +ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a7b00 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst diff --git a/Ska/Shell/__init__.py b/Ska/Shell/__init__.py index a1e4126..5e844a2 100644 --- a/Ska/Shell/__init__.py +++ b/Ska/Shell/__init__.py @@ -1,7 +1,9 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst +import ska_helpers + from .shell import * -__version__ = '3.3.4' +__version__ = ska_helpers.get_version(__package__) def test(*args, **kwargs): diff --git a/Ska/Shell/shell.py b/Ska/Shell/shell.py index d6cfb41..ed1c39c 100644 --- a/Ska/Shell/shell.py +++ b/Ska/Shell/shell.py @@ -5,10 +5,9 @@ import os import sys import signal +import platform import subprocess -import six - class ShellError(Exception): pass @@ -93,10 +92,12 @@ def _setup_bash_shell(logfile): os.environ['PS1'] = prompt1 os.environ['PS2'] = prompt2 - spawn = pexpect.spawn if six.PY2 else pexpect.spawnu + if platform.system() == 'Darwin': + os.environ['BASH_SILENCE_DEPRECATION_WARNING'] = '1' + spawn = pexpect.spawnu shell = spawn('/bin/bash --noprofile --norc --noediting', timeout=1e8) shell.logfile_read = logfile - shell.expect(r'.+') + shell.expect(re_prompt) return shell, re_prompt @@ -111,7 +112,7 @@ def _setup_tcsh_shell(logfile): # line that needs to be skipped. pexpect.spawn.sendline_expect = _sendline_expect_func(re_prompt, n_skip=2) - spawn = pexpect.spawn if six.PY2 else pexpect.spawnu + spawn = pexpect.spawnu shell = spawn('/bin/tcsh -f', timeout=1e8) shell.sendline('set prompt="{}"'.format(prompt)) diff --git a/Ska/Shell/tests/test_shell.py b/Ska/Shell/tests/test_shell.py index 758b31e..ffb6eff 100644 --- a/Ska/Shell/tests/test_shell.py +++ b/Ska/Shell/tests/test_shell.py @@ -26,13 +26,13 @@ def test_os_error(self): spawn = Spawn(stdout=None) with pytest.raises(OSError): spawn.run('bad command') - assert spawn.exitstatus == None + assert spawn.exitstatus is None def test_timeout_error(self): spawn = Spawn(shell=True, timeout=1, stdout=None) with pytest.raises(RunTimeoutError): spawn.run('sleep 5') - assert spawn.exitstatus == None + assert spawn.exitstatus is None def test_grab_stderr(self, tmpdir): tmp = tmpdir.join("test.out") @@ -90,10 +90,15 @@ def test_logfile(self): cmd = 'echo line1; echo line2' bash(cmd, logfile=logfile) outlines = logfile.getvalue().splitlines() - assert outlines[0].endswith(cmd) - assert outlines[1] == 'line1' - assert outlines[2] == 'line2' - assert outlines[3].startswith('Bash') + + # Note that starting bash may generate cruft at the beginning (e.g. the + # annoying message on catalina that zsh is now the default shell). So + # the tests reference expected output from the end of the log not the + # beginning. + assert outlines[-4].endswith(cmd) + assert outlines[-3] == 'line1' + assert outlines[-2] == 'line2' + assert outlines[-1].startswith('Bash') @pytest.mark.skipif('not HAS_HEAD_CIAO', reason='Test requires /soft/ciao/bin/ciao.sh') def test_ciao(self): @@ -147,7 +152,3 @@ def test_ciao(self): test_script = ['printenv {}'.format(name) for name in sorted(envs)] outlines = tcsh('\n'.join(test_script), env=envs) assert outlines == [envs[name] for name in sorted(envs)] - - -if __name__ == "__main__": - unittest.main() diff --git a/setup.py b/setup.py index 9337a22..cbbf82e 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from setuptools import setup -from Ska.Shell import __version__ try: from testr.setup_helper import cmdclass except ImportError: @@ -11,7 +10,8 @@ author='Tom Aldcroft', description='Various shell utilities', author_email='taldcroft@cfa.harvard.edu', - version=__version__, + use_scm_version=True, + setup_requires=['setuptools_scm', 'setuptools_scm_git_archive'], zip_safe=False, packages=['Ska', 'Ska.Shell', 'Ska.Shell.tests'], tests_require=['pytest'],