From 265f68b93f19762fe51bfa6b9a0eccef17c56d77 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Tue, 17 Dec 2019 12:57:36 -0500 Subject: [PATCH 1/5] Added changes to use setuptools_scm --- Ska/Shell/__init__.py | 4 +++- setup.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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/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'], From 3bb1c4769dbbeaefd32542ac263d22542c9ef4ec Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Fri, 20 Dec 2019 11:42:17 -0500 Subject: [PATCH 2/5] added files for scm git archive --- .git_archival.txt | 1 + .gitattributes | 1 + 2 files changed, 2 insertions(+) create mode 100644 .git_archival.txt create mode 100644 .gitattributes 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 From ad1f31d3f3db59a99f0da50e5277610a19911f6d Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Sun, 5 Jan 2020 07:06:43 -0500 Subject: [PATCH 3/5] Changes required to pass tests on MacOSX catalina --- Ska/Shell/shell.py | 2 +- Ska/Shell/tests/test_shell.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Ska/Shell/shell.py b/Ska/Shell/shell.py index d6cfb41..d0785d0 100644 --- a/Ska/Shell/shell.py +++ b/Ska/Shell/shell.py @@ -96,7 +96,7 @@ def _setup_bash_shell(logfile): spawn = pexpect.spawn if six.PY2 else 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 diff --git a/Ska/Shell/tests/test_shell.py b/Ska/Shell/tests/test_shell.py index 758b31e..172602d 100644 --- a/Ska/Shell/tests/test_shell.py +++ b/Ska/Shell/tests/test_shell.py @@ -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): From f6176a026b5a315b413ca7ed7e19faeb7f89c40f Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Sun, 5 Jan 2020 07:07:14 -0500 Subject: [PATCH 4/5] Python-3 only and flake8 fixes --- Ska/Shell/shell.py | 6 ++---- Ska/Shell/tests/test_shell.py | 8 ++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Ska/Shell/shell.py b/Ska/Shell/shell.py index d0785d0..f92c5d6 100644 --- a/Ska/Shell/shell.py +++ b/Ska/Shell/shell.py @@ -7,8 +7,6 @@ import signal import subprocess -import six - class ShellError(Exception): pass @@ -93,7 +91,7 @@ def _setup_bash_shell(logfile): os.environ['PS1'] = prompt1 os.environ['PS2'] = prompt2 - spawn = pexpect.spawn if six.PY2 else pexpect.spawnu + spawn = pexpect.spawnu shell = spawn('/bin/bash --noprofile --norc --noediting', timeout=1e8) shell.logfile_read = logfile shell.expect(re_prompt) @@ -111,7 +109,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 172602d..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") @@ -152,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() From 78532fda0cb410fddcb257ea8df9ce0492563ade Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Mon, 6 Jan 2020 07:05:34 -0500 Subject: [PATCH 5/5] Also silence Darwin bash deprecation warning --- Ska/Shell/shell.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Ska/Shell/shell.py b/Ska/Shell/shell.py index f92c5d6..ed1c39c 100644 --- a/Ska/Shell/shell.py +++ b/Ska/Shell/shell.py @@ -5,6 +5,7 @@ import os import sys import signal +import platform import subprocess @@ -91,6 +92,8 @@ def _setup_bash_shell(logfile): os.environ['PS1'] = prompt1 os.environ['PS2'] = prompt2 + 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