From daadf177bbd61511e36392bed4cebe0eeb650096 Mon Sep 17 00:00:00 2001 From: Nezar Abdennur Date: Fri, 25 Sep 2020 10:28:39 -0400 Subject: [PATCH 1/2] Fix get_header to work with different peek implementations --- cooler/cli/cload.py | 21 ++++++++++++++++----- tests/data/toy_hash.pairs.gz | Bin 0 -> 625 bytes tests/test_create_ingest.py | 5 +++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 tests/data/toy_hash.pairs.gz diff --git a/cooler/cli/cload.py b/cooler/cli/cload.py index 605dae31..4fb245cd 100644 --- a/cooler/cli/cload.py +++ b/cooler/cli/cload.py @@ -49,17 +49,28 @@ def get_header(instream, comment_char='#'): raise ValueError('Please, provide a comment char!') comment_byte = comment_char.encode() # get peekable buffer for the instream - inbuffer = instream.buffer - current_peek = inbuffer.peek() + read_f, peek_f = None, None + if hasattr(instream, 'buffer'): + peek_f = instream.buffer.peek + readline_f = instream.buffer.readline + elif hasattr(instream, 'peek'): + peek_f = instream.peek + readline_f = instream.readline + else: + raise ValueError('Cannot find the peek() function of the provided stream!') + + current_peek = peek_f(1) while current_peek.startswith(comment_byte): # consuming a line from buffer guarantees # that the remainder of the buffer starts # with the beginning of the line. - line = inbuffer.readline() + line = readline_f() + if isinstance(line, bytes): + line = line.decode() # append line to header, since it does start with header - header.append(line.decode().strip()) + header.append(line.strip()) # peek into the remainder of the instream - current_peek = inbuffer.peek() + current_peek = peek_f(1) # apparently, next line does not start with the comment # return header and the instream, advanced to the beginning of the data return header, instream diff --git a/tests/data/toy_hash.pairs.gz b/tests/data/toy_hash.pairs.gz new file mode 100644 index 0000000000000000000000000000000000000000..e4675cf737dfd10a75a1f1674eb64f5df6352433 GIT binary patch literal 625 zcmV-%0*?J3iwFpm8OB}!19WeBUua=-XfAMJX>xM_ZI(gK)-Vi2*X0^45vaD)B)!Ie z0|ZE{x&Hz|{gT+tYNU?7#rK>U`{UR5pP%LU@%xV)NISkBUyk#eeERt3>hsw}dUWmi z>>_t`%k$Yq&*)yyXBU;|*5|W}YINK4*+nh7{rT*oCA#EE7wF`#ckJw zUe#^aL|)Bp*Zfe6+pdYbUT(W4>{{J+m4sa#7b=OH!V7*0oH{U65;=2Xs3dge$WTe_ z%$cE*;F&S*?W-{0?H`q0jC=bgtupTIleWgVw~4UMxVM3_n{jXRSWd>hjdKykz3qac zW8B*&DK^Hv?V(b}xVJ4HMq#=Y&|(#N>B?Ok|oZL~t{V4hnatrC5n z+dWz-`b3u2O#Ch~OKT>67w?YNO#CiVOKavGLTn4A9&J*4u@Rz8Xe;X^+GMt|i{gf& z>^h4q+LYbR7K}E5Jz1gAwl(jPd$^W0?vh))@?5qZUrE}w;%i%W`m5ns{nhP_aPipFBWlnBSK`$O7iE!;5yC}TBxa3p zQ5K0>BV3e4;?@ZlWs%7BdAbqy=+EPgut$HMZ-hPi^ME7l(Vr(AVUPYi;s|^6=NU)X zqdyNh!XEv3%8~YX@Xb?>xJQ4Ua^yYw^OPg-(VwRriI4s~<%oRr=P5_#qd!kMLXZC! L`#Pu Date: Fri, 25 Sep 2020 10:28:52 -0400 Subject: [PATCH 2/2] Stop testing 2.7 in ci --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 27ab68b8..f1cfff76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: # We don't actually use the Travis Python, but this keeps it organized. - - "2.7" - "3.6" - "3.7" - "3.8"