Skip to content

Commit 08b042d

Browse files
Will-Tylerjeromekelleher
authored andcommitted
Revert "Use pipe when output file descriptor is not available"
This reverts commit 8ba5ac0.
1 parent f406a95 commit 08b042d

File tree

2 files changed

+2
-37
lines changed

2 files changed

+2
-37
lines changed

vcztools/_vcztoolsmodule.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,10 @@ static PyObject *
480480
VcfEncoder_encode_all(VcfEncoder *self, PyObject *args)
481481
{
482482
bool allowed_threads = false;
483-
int output_fd;
484-
int is_pipe;
485-
FILE* file = NULL;
486483

487484
if (VcfEncoder_check_state(self) != 0) {
488485
goto out;
489486
}
490-
if (!PyArg_ParseTuple(args, "ip", &output_fd, &is_pipe)) {
491-
goto out;
492-
}
493-
494-
file = fdopen(output_fd, "w");
495-
496-
if (file == NULL) {
497-
goto out;
498-
}
499487

500488
Py_BEGIN_ALLOW_THREADS
501489
allowed_threads = true;
@@ -524,22 +512,14 @@ VcfEncoder_encode_all(VcfEncoder *self, PyObject *args)
524512
goto out;
525513
}
526514
} else {
527-
fputs(buf, file);
528-
fputc('\n', file);
515+
puts(buf);
529516
PyMem_RawFree(buf);
530517
break;
531518
} // if (line_length < 0)
532519
} // while (true)
533520
}
534521

535522
out:
536-
if (file != NULL) {
537-
fflush(file);
538-
539-
if (is_pipe) {
540-
fclose(file);
541-
}
542-
}
543523
if (allowed_threads) {
544524
Py_END_ALLOW_THREADS
545525
}

vcztools/vcf_writer.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import concurrent.futures
22
import functools
33
import io
4-
import os
54
import re
65
import sys
76
from datetime import datetime
@@ -416,21 +415,7 @@ def c_chunk_to_vcf(
416415
if preceding_future:
417416
concurrent.futures.wait((preceding_future,))
418417

419-
output = output or sys.stdout
420-
pipe = None
421-
try:
422-
output_fd = output.fileno()
423-
except OSError:
424-
pipe = os.pipe()
425-
output_fd = pipe[1]
426-
427-
output.flush()
428-
encoder.encode_all(output_fd, bool(pipe))
429-
430-
if pipe:
431-
with io.FileIO(pipe[0], closefd=True) as pipe_reader:
432-
output.write(pipe_reader.read().decode("ascii"))
433-
output.flush()
418+
encoder.encode_all()
434419

435420

436421
def _generate_header(ds, original_header, sample_ids, *, no_version: bool = False):

0 commit comments

Comments
 (0)