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

Added supported for CLI margins option. #111

Merged
merged 2 commits into from
Sep 17, 2024
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
9 changes: 8 additions & 1 deletion camelot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,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 @@ -300,7 +307,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, [ "--margins", "1.5", "0.5", "0.8", "--format", "csv", "--output", outfile, "stream", infile]
)
assert result.exit_code == 0
assert result.output == "Found 1 tables\n"

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


@skip_on_windows
def test_cli_parallel(testdir):
Expand Down