Blacken code

This commit is contained in:
Vinayak Mehta
2021-06-15 03:29:35 +05:30
parent f7c14bf1d4
commit 2c59e7b0f7
11 changed files with 676 additions and 254 deletions
+9 -13
View File
@@ -55,7 +55,9 @@ class TextEdge(object):
x = round(self.x, 2)
y0 = round(self.y0, 2)
y1 = round(self.y1, 2)
return f"<TextEdge x={x} y0={y0} y1={y1} align={self.align} valid={self.is_valid}>"
return (
f"<TextEdge x={x} y0={y0} y1={y1} align={self.align} valid={self.is_valid}>"
)
def update_coords(self, x, y0, edge_tol=50):
"""Updates the text edge's x and bottom y coordinates and sets
@@ -102,8 +104,7 @@ class TextEdges(object):
return None
def add(self, textline, align):
"""Adds a new text edge to the current dict.
"""
"""Adds a new text edge to the current dict."""
x = self.get_x_coord(textline, align)
y0 = textline.y0
y1 = textline.y1
@@ -111,8 +112,7 @@ class TextEdges(object):
self._textedges[align].append(te)
def update(self, textline):
"""Updates an existing text edge in the current dict.
"""
"""Updates an existing text edge in the current dict."""
for align in ["left", "right", "middle"]:
x_coord = self.get_x_coord(textline, align)
idx = self.find(x_coord, align)
@@ -304,8 +304,7 @@ class Cell(object):
@property
def bound(self):
"""The number of sides on which the cell is bounded.
"""
"""The number of sides on which the cell is bounded."""
return self.top + self.bottom + self.left + self.right
@@ -361,8 +360,7 @@ class Table(object):
@property
def data(self):
"""Returns two-dimensional list of strings in table.
"""
"""Returns two-dimensional list of strings in table."""
d = []
for row in self.cells:
d.append([cell.text.strip() for cell in row])
@@ -383,8 +381,7 @@ class Table(object):
return report
def set_all_edges(self):
"""Sets all table edges to True.
"""
"""Sets all table edges to True."""
for row in self.cells:
for cell in row:
cell.left = cell.right = cell.top = cell.bottom = True
@@ -526,8 +523,7 @@ class Table(object):
return self
def set_border(self):
"""Sets table border edges to True.
"""
"""Sets table border edges to True."""
for r in range(len(self.rows)):
self.cells[r][0].left = True
self.cells[r][len(self.cols) - 1].right = True
+1 -2
View File
@@ -81,8 +81,7 @@ class __Ghostscript(object):
def Ghostscript(*args, **kwargs):
"""Factory function for setting up a Ghostscript instance
"""
"""Factory function for setting up a Ghostscript instance"""
global __instance__
# Ghostscript only supports a single instance
if __instance__ is None:
+1 -3
View File
@@ -167,9 +167,7 @@ class PDFHandler(object):
with TemporaryDirectory() as tempdir:
for p in self.pages:
self._save_page(self.filepath, p, tempdir)
pages = [
os.path.join(tempdir, f"page-{p}.pdf") for p in self.pages
]
pages = [os.path.join(tempdir, f"page-{p}.pdf") for p in self.pages]
parser = Lattice(**kwargs) if flavor == "lattice" else Stream(**kwargs)
for p in pages:
t = parser.extract_tables(
+1 -2
View File
@@ -6,8 +6,7 @@ from ..utils import get_page_layout, get_text_objects
class BaseParser(object):
"""Defines a base parser.
"""
"""Defines a base parser."""
def _generate_layout(self, filename, layout_kwargs):
self.filename = filename
+5 -5
View File
@@ -65,7 +65,7 @@ class Stream(BaseParser):
edge_tol=50,
row_tol=2,
column_tol=0,
**kwargs
**kwargs,
):
self.table_regions = table_regions
self.table_areas = table_areas
@@ -362,10 +362,10 @@ class Stream(BaseParser):
if len(elements):
ncols = max(set(elements), key=elements.count)
else:
warnings.warn(
f"No tables found in table area {table_idx + 1}"
)
cols = [(t.x0, t.x1) for r in rows_grouped if len(r) == ncols for t in r]
warnings.warn(f"No tables found in table area {table_idx + 1}")
cols = [
(t.x0, t.x1) for r in rows_grouped if len(r) == ncols for t in r
]
cols = self._merge_columns(sorted(cols), column_tol=self.column_tol)
inner_text = []
for i in range(1, len(cols)):
+3 -7
View File
@@ -34,13 +34,9 @@ class PlotMethods(object):
raise ImportError("matplotlib is required for plotting.")
if table.flavor == "lattice" and kind in ["textedge"]:
raise NotImplementedError(
f"Lattice flavor does not support kind='{kind}'"
)
raise NotImplementedError(f"Lattice flavor does not support kind='{kind}'")
elif table.flavor == "stream" and kind in ["joint", "line"]:
raise NotImplementedError(
f"Stream flavor does not support kind='{kind}'"
)
raise NotImplementedError(f"Stream flavor does not support kind='{kind}'")
plot_method = getattr(self, kind)
fig = plot_method(table)
@@ -48,7 +44,7 @@ class PlotMethods(object):
if filename is not None:
fig.savefig(filename)
return None
return fig
def text(self, table):
+3 -1
View File
@@ -870,7 +870,9 @@ def get_page_layout(
parser = PDFParser(f)
document = PDFDocument(parser)
if not document.is_extractable:
raise PDFTextExtractionNotAllowed(f"Text extraction is not allowed: {filename}")
raise PDFTextExtractionNotAllowed(
f"Text extraction is not allowed: {filename}"
)
laparams = LAParams(
char_margin=char_margin,
line_margin=line_margin,