Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #228 from frictionlessdata/readme-review-and-minor…
Browse files Browse the repository at this point in the history
…-improvements

README review and minor improvements
  • Loading branch information
serahkiburu committed Jul 19, 2018
2 parents 273f4ff + c30f8ea commit caa43ad
Show file tree
Hide file tree
Showing 14 changed files with 710 additions and 669 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.pytest_cache/
.coverage
.coverage.*
.cache
Expand Down Expand Up @@ -74,3 +75,4 @@ tmp

# Extra
datapackage
.#*
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ list:
@grep '^\.PHONY' Makefile | cut -d' ' -f2- | tr ' ' '\n'

test:
pylama $(PACKAGE)
tox

version:
Expand Down
1,054 changes: 466 additions & 588 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def read(*paths):
'lxml>=3.0,<4.0',
]
TESTS_REQUIRE = [
'pylama',
'tox',
]
README = read('README.md')
Expand Down
4 changes: 1 addition & 3 deletions tabulator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
@click.option('--limit', type=click.INT)
@click.version_option(tabulator.__version__, message='%(version)s')
def cli(source, limit, **options):
"""https://github.com/frictionlessdata/tabulator-py#cli
"""
options = {key: value for key, value in options.items() if value is not None}
with tabulator.Stream(source, **options) as stream:
cast = str
Expand All @@ -30,7 +28,7 @@ def cli(source, limit, **options):
if stream.headers:
click.echo(click.style(', '.join(map(cast, stream.headers)), bold=True))
for count, row in enumerate(stream, start=1):
click.echo(', '.join(map(cast, row)))
click.echo(','.join(map(cast, row)))
if count == limit:
break

Expand Down
20 changes: 5 additions & 15 deletions tabulator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,34 @@
# Module API

class TabulatorException(Exception):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
'''Base class for all tabulator exceptions.'''
pass


class IOError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
pass


class HTTPError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
class HTTPError(IOError):
pass


class SourceError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
'''The source file could not be parsed correctly.'''
pass


class SchemeError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
'''The file scheme is not supported.'''
pass


class FormatError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
'''The file format is unsupported or invalid.'''
pass


class EncodingError(TabulatorException):
"""https://github.com/frictionlessdata/tabulator-py#exceptions
"""
pass


Expand Down
27 changes: 23 additions & 4 deletions tabulator/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@

@add_metaclass(ABCMeta)
class Loader(object):
'''Abstract class implemented by the data loaders
The loaders inherit and implement this class' methods to add support for a
new scheme (e.g. ssh).
Args:
bytes_sample_size (int): Sample size in bytes
**options (dict): Loader options
Returns:
Loader: Loader instance.
'''

# Public

options = []

def __init__(self, bytes_sample_size, **options):
"""https://github.com/frictionlessdata/tabulator-py#custom-loaders
"""
pass

@abstractmethod
def load(self, source, mode='t', encoding=None):
"""https://github.com/frictionlessdata/tabulator-py#custom-loaders
"""
'''Load source file.
Args:
source (str): Path to tabular source file.
mode (str, optional): Text stream mode, `t` (text) or `b` (binary).
Defaults to `t`.
encoding (str, optional): Source encoding. Auto-detect by default.
Returns:
Union[TextIO, BinaryIO]: I/O stream opened either as text or binary.
'''
pass
65 changes: 51 additions & 14 deletions tabulator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,88 @@

@add_metaclass(ABCMeta)
class Parser(object):
'''Abstract class implemented by the data parsers.
The parsers inherit and implement this class' methods to add support for a
new file type.
Args:
loader (tabulator.Loader): Loader instance to read the file.
force_parse (bool): When `True`, the parser yields an empty extended
row tuple `(row_number, None, [])` when there is an error parsing a
row. Otherwise, it stops the iteration by raising the exception
`tabulator.exceptions.SourceError`.
**options (dict): Loader options
Returns:
Parser: Parser instance.
'''

# Public

options = []

def __init__(self, loader, force_parse, **options):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
pass

@property
@abstractmethod
def closed(self):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
'''Flag telling if the parser is closed.'''
pass # pragma: no cover

@abstractmethod
def open(self, source, encoding=None):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
'''Open underlying file stream in the beginning of the file.
The parser gets a byte or text stream from the `tabulator.Loader`
instance and start emitting items.
Args:
source (str): Path to source table.
encoding (str, optional): Source encoding. Auto-detect by default.
Returns:
None
'''
pass # pragma: no cover

@abstractmethod
def close(self):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
'''Closes underlying file stream.'''
pass # pragma: no cover

@abstractmethod
def reset(self):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
'''Resets underlying stream and current items list.
After `reset()` is called, iterating over the items will start from the
beginning.
'''
pass # pragma: no cover

@property
@abstractmethod
def encoding(self):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
pass # pragma: no cover

@property
@abstractmethod
def extended_rows(self):
"""https://github.com/frictionlessdata/tabulator-py#custom-parsers
"""
'''Returns extended rows iterator.
The extended rows are tuples containing `(row_number, headers, row)`,
Yields:
Tuple[int, List[str], List[Any]]: Extended rows containing
`(row_number, headers, row)`, where `headers` is a list of the
header names (can be `None`), and `row` is a list of row
values.
Raises:
`tabulator.exceptions.SourceError`: If `force_parse` is `False` and
a row can't be parsed, this exception will be raised.
Otherwise, an empty extended row is returned (i.e.
`(row_number, None, [])`).
'''
pass # pragma: no cover
Loading

0 comments on commit caa43ad

Please sign in to comment.