Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] #499 Added support for CLI margins option #500

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion camelot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ def stream(c, *args, **kwargs):
columns = list(kwargs["columns"])
kwargs["columns"] = None if not columns else columns

margins = conf.pop('margins')

if margins is None:
layout_kwargs = {}
else:
layout_kwargs = {"char_margin": margins[0], "line_margin": margins[1], "word_margin": margins[2]}

if plot_type is not None:
if not _HAS_MPL:
raise ImportError("matplotlib is required for plotting.")
Expand All @@ -294,7 +301,7 @@ def stream(c, *args, **kwargs):
raise click.UsageError("Please specify output file format using --format")

tables = read_pdf(
filepath, pages=pages, flavor="stream", suppress_stdout=quiet, **kwargs
filepath, pages=pages, flavor="stream", suppress_stdout=quiet, layout_kwargs=layout_kwargs, **kwargs
)
click.echo(f"Found {tables.n} tables")
if plot_type is not None:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def test_cli_stream(testdir):
format_error = "Please specify output file format using --format"
assert format_error in result.output

result = runner.invoke(
cli, ["--format", "csv", "--output", outfile, "stream", infile, "--margins", "1.5 0.5 0.8"]
)
assert result.exit_code == 0
assert result.output == "Found 1 tables\n"

result = runner.invoke(
cli, ["--format", "csv", "--output", outfile, "stream", infile, "--margins", "1.5 0.5"]
)
output_error = "Error: Invalid value for '-M' / '--margins': '--format' is not a valid float."
assert output_error in result.output


def test_cli_password(testdir):
with TemporaryDirectory() as tempdir:
Expand Down