From 85bc81be0baa77face537968265de9df151b78f5fde9b22d12034cea6c0fc7d3 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Thu, 27 Mar 2025 04:04:10 +0000 Subject: [PATCH] - Normalize metadata directory name. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-delegator.py?expand=0&rev=11 --- .gitattributes | 23 ++++++ .gitignore | 1 + delegator.py-0.1.1.tar.gz | 3 + merged_pr_62.patch | 157 ++++++++++++++++++++++++++++++++++++ python-delegator.py.changes | 25 ++++++ python-delegator.py.spec | 69 ++++++++++++++++ test_chain.py | 6 ++ 7 files changed, 284 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 delegator.py-0.1.1.tar.gz create mode 100644 merged_pr_62.patch create mode 100644 python-delegator.py.changes create mode 100644 python-delegator.py.spec create mode 100644 test_chain.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/delegator.py-0.1.1.tar.gz b/delegator.py-0.1.1.tar.gz new file mode 100644 index 0000000..6f73aa0 --- /dev/null +++ b/delegator.py-0.1.1.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6cc9cedab9ae59b169ee0422e17231adedadb144e63c0b5a60e6ff8adf8521b +size 6260 diff --git a/merged_pr_62.patch b/merged_pr_62.patch new file mode 100644 index 0000000..2714404 --- /dev/null +++ b/merged_pr_62.patch @@ -0,0 +1,157 @@ +From 9bb7790d6ad54a238f57cce8ad93a811ef302268 Mon Sep 17 00:00:00 2001 +From: Dan Ryan +Date: Mon, 22 Oct 2018 09:42:40 -0400 +Subject: [PATCH 1/3] Explicitly close file handles on block + +- Fixes #61 + +Signed-off-by: Dan Ryan +--- + delegator.py | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/delegator.py b/delegator.py +index d15aeb9..9eb430d 100644 +--- a/delegator.py ++++ b/delegator.py +@@ -233,6 +233,8 @@ def kill(self): + def block(self): + """Blocks until process is complete.""" + if self._uses_subprocess: ++ # Close open file handles to prevent leaking them ++ self.subprocess.stdout.close() + # consume stdout and stderr + try: + stdout, stderr = self.subprocess.communicate() +@@ -241,6 +243,8 @@ def block(self): + except ValueError: + pass # Don't read from finished subprocesses. + else: ++ self.subprocess.sendeof() ++ self.subprocess.proc.stdout.close() + self.subprocess.wait() + + def pipe(self, command, timeout=None, cwd=None): + +From eddd9d14e50f7945faf99cac92ef33ab18b1342b Mon Sep 17 00:00:00 2001 +From: Dan Ryan +Date: Mon, 22 Oct 2018 10:04:15 -0400 +Subject: [PATCH 2/3] Don't pass `subprocess.PIPE` to blocking Popen calls + +Signed-off-by: Dan Ryan +--- + delegator.py | 23 ++++++++++++++--------- + 1 file changed, 14 insertions(+), 9 deletions(-) + +diff --git a/delegator.py b/delegator.py +index 9eb430d..3ffb2e3 100644 +--- a/delegator.py ++++ b/delegator.py +@@ -178,6 +178,7 @@ def run(self, block=True, binary=False, cwd=None, env=None): + # Use subprocess. + if self.blocking: + popen_kwargs = self._default_popen_kwargs.copy() ++ del popen_kwargs["stdin"] + popen_kwargs["universal_newlines"] = not binary + if cwd: + popen_kwargs["cwd"] = cwd +@@ -233,19 +234,23 @@ def kill(self): + def block(self): + """Blocks until process is complete.""" + if self._uses_subprocess: +- # Close open file handles to prevent leaking them +- self.subprocess.stdout.close() + # consume stdout and stderr +- try: +- stdout, stderr = self.subprocess.communicate() +- self.__out = stdout +- self.__err = stderr +- except ValueError: +- pass # Don't read from finished subprocesses. ++ if self.blocking: ++ try: ++ stdout, stderr = self.subprocess.communicate() ++ self.__out = stdout ++ self.__err = stderr ++ except ValueError: ++ pass # Don't read from finished subprocesses. ++ else: ++ self.subprocess.stdin.close() ++ self.std_out.close() ++ self.std_err.close() ++ self.subprocess.wait() + else: + self.subprocess.sendeof() +- self.subprocess.proc.stdout.close() + self.subprocess.wait() ++ self.subprocess.proc.stdout.close() + + def pipe(self, command, timeout=None, cwd=None): + """Runs the current command and passes its output to the next + +From d07d065ef3ae5f7b637214a9fe193a4c642126cb Mon Sep 17 00:00:00 2001 +From: Dan Ryan +Date: Tue, 23 Oct 2018 18:53:27 -0400 +Subject: [PATCH 3/3] Don't pass `EOF` to the caller + +Signed-off-by: Dan Ryan +--- + delegator.py | 17 ++++++++++++----- + 1 file changed, 12 insertions(+), 5 deletions(-) + +diff --git a/delegator.py b/delegator.py +index 3ffb2e3..56d1245 100644 +--- a/delegator.py ++++ b/delegator.py +@@ -7,6 +7,8 @@ + import errno + + from pexpect.popen_spawn import PopenSpawn ++import pexpect ++pexpect.EOF.__module__ = "pexpect.exceptions" + + # Include `unicode` in STR_TYPES for Python 2.X + try: +@@ -110,7 +112,7 @@ def _pexpect_out(self): + if self.subprocess.before: + result += self.subprocess.before + +- if self.subprocess.after: ++ if self.subprocess.after and self.subprocess.after is not pexpect.EOF: + result += self.subprocess.after + + result += self.subprocess.read() +@@ -206,7 +208,10 @@ def expect(self, pattern, timeout=-1): + if self.blocking: + raise RuntimeError("expect can only be used on non-blocking commands.") + +- self.subprocess.expect(pattern=pattern, timeout=timeout) ++ try: ++ self.subprocess.expect(pattern=pattern, timeout=timeout) ++ except pexpect.EOF: ++ pass + + def send(self, s, end=os.linesep, signal=False): + """Sends the given string or signal to std_in.""" +@@ -249,8 +254,11 @@ def block(self): + self.subprocess.wait() + else: + self.subprocess.sendeof() +- self.subprocess.wait() +- self.subprocess.proc.stdout.close() ++ try: ++ self.subprocess.wait() ++ finally: ++ if self.subprocess.proc.stdout: ++ self.subprocess.proc.stdout.close() + + def pipe(self, command, timeout=None, cwd=None): + """Runs the current command and passes its output to the next +@@ -272,7 +280,6 @@ def pipe(self, command, timeout=None, cwd=None): + c.run(block=False, cwd=cwd) + if data: + c.send(data) +- c.subprocess.sendeof() + c.block() + return c + diff --git a/python-delegator.py.changes b/python-delegator.py.changes new file mode 100644 index 0000000..cf2e0a4 --- /dev/null +++ b/python-delegator.py.changes @@ -0,0 +1,25 @@ +------------------------------------------------------------------- +Thu Mar 27 04:03:17 UTC 2025 - Steve Kowalik + +- Normalize metadata directory name. + +------------------------------------------------------------------- +Thu Feb 29 03:13:06 UTC 2024 - Steve Kowalik + +- Switch to autosetup and pyproject macros. +- No more greedy globs in %files. + +------------------------------------------------------------------- +Sun Oct 23 09:43:15 UTC 2022 - John Vandenberg + +- Replace custom exclude-eof-from-result.patch with merged_pr_62.patch + +------------------------------------------------------------------- +Fri Mar 15 18:51:31 UTC 2019 - Jan Engelhardt + +- Replace useless descriptions. + +------------------------------------------------------------------- +Thu Mar 7 08:26:37 AM UTC 2019 - John Vandenberg + +- Initial spec for v0.1.1, using exclude-eof-from-result.patch diff --git a/python-delegator.py.spec b/python-delegator.py.spec new file mode 100644 index 0000000..e9c0a46 --- /dev/null +++ b/python-delegator.py.spec @@ -0,0 +1,69 @@ +# +# spec file for package python-delegator.py +# +# Copyright (c) 2025 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: python-delegator.py +Version: 0.1.1 +Release: 0 +Summary: Python library for dealing with subprocesses +License: MIT +URL: https://github.com/kennethreitz/delegator.py +Source: https://files.pythonhosted.org/packages/source/d/delegator.py/delegator.py-%{version}.tar.gz +Source1: https://raw.githubusercontent.com/kennethreitz/delegator.py/master/tests/test_chain.py +Patch0: merged_pr_62.patch +BuildRequires: %{python_module pexpect >= 4.1.0} +BuildRequires: %{python_module pip} +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module setuptools} +BuildRequires: %{python_module wheel} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +Requires: python-pexpect >= 4.1.0 +BuildArch: noarch +Conflicts: python-delegator + +%python_subpackages + +%description +Delegator.py is a library for dealing with subprocesses, inspired +by both "envoy" and "pexpect" (in fact, it depends on it). + +%prep +%autosetup -p1 -n delegator.py-%{version} +cp %{SOURCE1} . + +%build +%pyproject_wheel + +%install +%pyproject_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +# Tests from master are not compatible. Likely fixed in next release. +# https://github.com/kennethreitz/delegator.py/pull/71 +#%%check +#export PYTHONPATH=${PWD} +#%%python_exec -m pytest test_chain.py + +%files %{python_files} +%doc README.rst +%license LICENSE +%{python_sitelib}/delegator.py +%pycache_only %{python_sitelib}/__pycache__/delegator.*.pyc +%{python_sitelib}/delegator_py-%{version}.dist-info + +%changelog diff --git a/test_chain.py b/test_chain.py new file mode 100644 index 0000000..2ea6e14 --- /dev/null +++ b/test_chain.py @@ -0,0 +1,6 @@ +import pytest +import delegator + +def test_chain(): + c = delegator.chain("seq 4 | awk '{ print $0 \" test\"; }'") + assert c.out == '1 test\n2 test\n3 test\n4 test\n'