Skip to content

Commit

Permalink
Major lint overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Jul 9, 2024
1 parent 425fe27 commit 95882c9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions antur/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AnturApp(App):

SUB_TITLE = f"v{__version__}"

show_markdown = reactive(False)
show_markdown = reactive(default=False)

def __init__(self: "AnturApp", url: str | None = None, *, max_concurrent_requests: int) -> None:
"""Initialize the Antur application."""
Expand All @@ -46,7 +46,7 @@ def __init__(self: "AnturApp", url: str | None = None, *, max_concurrent_request

def compose(self: "AnturApp") -> ComposeResult:
"""Compose the layout of the app."""
yield Header(False)
yield Header(show_clock=False)
yield SearchBar(self.url)
with Vertical(id="contents"):
with Vertical(id="main"):
Expand Down
1 change: 1 addition & 0 deletions antur/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""General utilities used through the application, such as sitemap parsing."""
21 changes: 13 additions & 8 deletions antur/utils/sitemap_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass

import aiohttp
from lxml.etree import Element, fromstring, tostring
from lxml.etree import Element, XMLSyntaxError, fromstring, tostring

from antur import __version__

Expand All @@ -29,7 +29,7 @@ class Error:


HEADERS = {
"User-Agent": f"Mozilla/5.0 (compatible; AnturSitemap/{__version__}; +http://github.com/jb3/antur)"
"User-Agent": f"Mozilla/5.0 (compatible; AnturSitemap/{__version__}; +http://github.com/jb3/antur)",
}

IGNORE_TAGS = ["lastmod", "changefreq", "priority", "loc"]
Expand All @@ -51,9 +51,13 @@ def __init__(self: "SitemapParser", url: str, max_concurrent_requests: int) -> N

async def get_data(self: "SitemapParser", url: str) -> bytes:
"""Fetch the data from the URL."""
async with aiohttp.ClientSession() as session, session.get(
url, headers=HEADERS
) as response:
async with (
aiohttp.ClientSession() as session,
session.get(
url,
headers=HEADERS,
) as response,
):
return await response.read()

def _filter_out_children(self: "SitemapParser", element: Element) -> Element:
Expand Down Expand Up @@ -86,7 +90,7 @@ async def parse(self: "SitemapParser", url: str | None = None) -> dict[str, Entr

try:
parsed = fromstring(data) # noqa: S320
except Exception as e:
except XMLSyntaxError as e:
self.xml_errors += 1
return Error(url, str(e))

Expand All @@ -100,8 +104,9 @@ async def parse(self: "SitemapParser", url: str | None = None) -> dict[str, Entr

results = await asyncio.gather(*child_tasks.values())

for loc, result in zip(child_tasks.keys(), results):
level[loc] = result
level_data = dict(zip(child_tasks.keys(), results, strict=False))

level.update(level_data)

if parsed.tag.endswith("urlset"):
for child in parsed:
Expand Down
1 change: 1 addition & 0 deletions antur/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Widgets used to display information through the application."""
2 changes: 1 addition & 1 deletion antur/widgets/search_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def is_url(value: str) -> bool:
return False

return all([result.scheme, result.netloc])
except Exception:
except ValueError:
return False


Expand Down
10 changes: 7 additions & 3 deletions antur/widgets/sitemap_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def dict_to_tree(dictionary: dict, tree: Tree | TreeNode) -> None:
"""Move a dictionary into the provided tree structure in-place."""
for key, value in dictionary.items():
if isinstance(value, (Entry, Error)):
if isinstance(value, Entry | Error):
tree.add_leaf(key, data=value)
else:
sub_tree = tree.add(key)
Expand All @@ -39,13 +39,17 @@ class CustomTree(Tree):
"""Custom tree widget to aid with formatting."""

def render_label(
self: "CustomTree", node: TreeNode, base_style: Style, additional_style: Style
self: "CustomTree",
node: TreeNode,
base_style: Style,
additional_style: Style,
) -> Text:
"""Render the label with a custom style."""
if hasattr(node, "data"): # noqa: SIM102
if isinstance(node.data, Error):
additional_style = Style.chain(
additional_style, Style.from_color(Color.parse("red"))
additional_style,
Style.from_color(Color.parse("red")),
)

return super().render_label(node, base_style, additional_style)
Expand Down

0 comments on commit 95882c9

Please sign in to comment.