Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions sample_sheet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class SampleSheet(object):
_section_header_re = re.compile(r'\[(.*)\]')
_whitespace_re = re.compile(r'\s+')

def __init__(self, path: Optional[Union[Path, str]] = None) -> None:
def __init__(self, path: Optional[Union[Path, str, TextIO]] = None) -> None:
self.path = path

self._samples: List[Sample] = []
Expand All @@ -415,7 +415,12 @@ def __init__(self, path: Optional[Union[Path, str]] = None) -> None:
self.Header: Section = Section()
self.Settings: Section = Section()

if self.path:

if self.path is not None:
if isinstance(self.path, (str, Path)):
with open(self.path, 'r') as f:
self._parse(f)
else:
self._parse(self.path)

def add_section(self, section_name: str) -> None:
Expand Down Expand Up @@ -476,12 +481,11 @@ def samples(self) -> List:
"""Return the samples present in this :class:`SampleSheet`."""
return self._samples

def _parse(self, path: Union[Path, str]) -> None:
def _parse(self, handle: TextIO) -> None:
section_name: str = ''
sample_header: Optional[List[str]] = None

with open(path, encoding=self._encoding) as handle:
lines = list(csv.reader(handle, skipinitialspace=True))
lines = list(csv.reader(handle, skipinitialspace=True))

for i, line in enumerate(lines):
# Skip to next line if this line is empty to support formats of
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
minversion = 3.0.0
skip_missing_interpreters = true
envlist =
py36,py37
py36,py37,py38
lint
type
docs
Expand Down