Builds fails if stdin is redirected to empty input
Created by: Jenselme
Hi,
While packaging csvkit for fedora and OpenSuse, we (I and @tigerfoot) found out that tests that relying on stdin fail with this message:
[ 31s] ======================================================================
[ 31s] ERROR: test_no_inference (tests.test_utilities.test_csvsql.TestCSVSQL)
[ 31s] ----------------------------------------------------------------------
[ 31s] Traceback (most recent call last):
[ 31s] File "/home/abuild/rpmbuild/BUILD/csvkit-0.9.1/tests/test_utilities/test_csvsql.py", line 37, in test_no_inference
[ 31s] utility.main()
[ 31s] File "/home/abuild/rpmbuild/BUILD/csvkit-0.9.1/csvkit/utilities/csvsql.py", line 105, in main
[ 31s] **self.reader_kwargs
[ 31s] File "/home/abuild/rpmbuild/BUILD/csvkit-0.9.1/csvkit/table.py", line 223, in from_csv
[ 31s] headers = next(rows)
[ 31s] File "/home/abuild/rpmbuild/BUILD/csvkit-0.9.1/csvkit/py3.py", line 21, in __next__
[ 31s] return next(self.reader)
[ 31s] StopIteration
From what we figured out, the problem is that you add sys.stdin
to the list of input files if the script is not run on a tty. But on the packages build system, stdin is redirected to something empty. This causes the build to fail.
Below is the patch that allow us to solve this issue. Is it really needed to add sys.stdin
to input files?
diff -rup a/csvkit/utilities/csvsql.py b/csvkit/utilities/csvsql.py
--- a/csvkit/utilities/csvsql.py 2015-11-19 19:37:48.000000000 +0100
+++ b/csvkit/utilities/csvsql.py 2015-11-30 18:19:56.369200131 +0100
@@ -54,14 +54,6 @@ class CSVSQL(CSVKitUtility):
else:
table_names = []
- # If one or more filenames are specified, we need to add stdin ourselves (if available)
- if sys.stdin not in self.input_files:
- try:
- if not sys.stdin.isatty():
- self.input_files.insert(0, sys.stdin)
- except:
- pass
-
# Create an SQLite database in memory if no connection string is specified
if query and not connection_string:
connection_string = "sqlite:///:memory:"
Only in b/csvkit/utilities: csvsql.py.orig
diff -rup a/tests/test_utilities/test_csvsql.py b/tests/test_utilities/test_csvsql.py
--- a/tests/test_utilities/test_csvsql.py 2015-11-19 19:37:48.000000000 +0100
+++ b/tests/test_utilities/test_csvsql.py 2015-11-30 18:18:43.737197120 +0100
@@ -90,7 +90,8 @@ class TestCSVSQL(unittest.TestCase):
sql = output_file.getvalue()
- self.assertTrue('CREATE TABLE stdin' in sql)
+ # This one doesn't work on build systems koji,obs etc
+ # self.assertTrue('CREATE TABLE stdin' in sql)
self.assertTrue('CREATE TABLE dummy' in sql)
def test_query(self):
Originaly reported on OpenSuse packaging. See: http://opensuse.14.x6.nabble.com/python3-test-a-strange-failure-only-during-build-td5052784.html.