Skip to content

Commit

Permalink
Pacify linters
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Jul 26, 2021
1 parent d467db2 commit fd66689
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/furo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pathlib import Path
from typing import Any, Dict, Optional

import pygments
import sphinx.application
from bs4 import BeautifulSoup
from pygments.formatters import HtmlFormatter
Expand Down Expand Up @@ -70,7 +69,7 @@ def get_pygments_style_colors(
) -> Dict[str, str]:
"""Get background/foreground colors for given pygments style."""
background = style.background_color
text_colors = style.style_for_token(pygments.token.Text)
text_colors = style.style_for_token(Text)
foreground = text_colors["color"]

if not background:
Expand Down Expand Up @@ -188,20 +187,21 @@ def _builder_inited(app: sphinx.application.Sphinx) -> None:
update_known_styles_state(app)


def update_known_styles_state(app):
def update_known_styles_state(app: sphinx.application.Sphinx) -> None:
"""Update a global store of known styles of this application."""
global _KNOWN_STYLES_IN_USE

_KNOWN_STYLES_IN_USE = {
"light": get_light_style(app),
"dark": get_dark_style(app),
"light": _get_light_style(app),
"dark": _get_dark_style(app),
}


def get_light_style(app):
def _get_light_style(app: sphinx.application.Sphinx) -> Style:
return app.builder.highlighter.formatter_args["style"]


def get_dark_style(app):
def _get_dark_style(app: sphinx.application.Sphinx) -> Style:
# number_of_hours_spent_figuring_this_out = 7
#
# Hello human in the future! This next block of code needs a bit of a story, and
Expand Down Expand Up @@ -269,7 +269,11 @@ def get_dark_style(app):
return PygmentsBridge("html", dark_style).formatter_args["style"]


def get_pygments_stylesheet():
def get_pygments_stylesheet() -> str:
"""Generate the theme-specific pygments.css.
There is no way to tell Sphinx how the theme handles dark mode; at this time.
"""
light_formatter = HtmlFormatter(style=_KNOWN_STYLES_IN_USE["light"])
dark_formatter = HtmlFormatter(style=_KNOWN_STYLES_IN_USE["dark"])

Expand All @@ -292,7 +296,10 @@ def get_pygments_stylesheet():

# Yup, we overwrite the default pygments.css file, because it can't possibly respect
# the needs of this theme.
def _overwrite_pygments_css(app, exception):
def _overwrite_pygments_css(
app: sphinx.application.Sphinx,
exception: Optional[Exception],
) -> None:
with open(os.path.join(app.builder.outdir, "_static", "pygments.css"), "w") as f:
f.write(get_pygments_stylesheet())

Expand Down

0 comments on commit fd66689

Please sign in to comment.