Skip to content

Commit

Permalink
Improve string formatting v5 (home-assistant#33697)
Browse files Browse the repository at this point in the history
* Improve string formatting v5

* Address review comments
  • Loading branch information
springstan authored Apr 5, 2020
1 parent 39336d3 commit fca90a8
Show file tree
Hide file tree
Showing 46 changed files with 224 additions and 255 deletions.
30 changes: 15 additions & 15 deletions docs/source/_ext/edit_on_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import os
import warnings

__licence__ = 'BSD (3 clause)'
__licence__ = "BSD (3 clause)"


def get_github_url(app, view, path):
github_fmt = 'https://github.com/{}/{}/{}/{}{}'
return (
github_fmt.format(app.config.edit_on_github_project, view,
app.config.edit_on_github_branch,
app.config.edit_on_github_src_path, path))
f"https://github.com/{app.config.edit_on_github_project}/"
f"{view}/{app.config.edit_on_github_branch}/"
f"{app.config.edit_on_github_src_path}{path}"
)


def html_page_context(app, pagename, templatename, context, doctree):
if templatename != 'page.html':
if templatename != "page.html":
return

if not app.config.edit_on_github_project:
Expand All @@ -29,16 +29,16 @@ def html_page_context(app, pagename, templatename, context, doctree):
if not doctree:
warnings.warn("doctree is None")
return
path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
show_url = get_github_url(app, 'blob', path)
edit_url = get_github_url(app, 'edit', path)
path = os.path.relpath(doctree.get("source"), app.builder.srcdir)
show_url = get_github_url(app, "blob", path)
edit_url = get_github_url(app, "edit", path)

context['show_on_github_url'] = show_url
context['edit_on_github_url'] = edit_url
context["show_on_github_url"] = show_url
context["edit_on_github_url"] = edit_url


def setup(app):
app.add_config_value('edit_on_github_project', '', True)
app.add_config_value('edit_on_github_branch', 'master', True)
app.add_config_value('edit_on_github_src_path', '', True) # 'eg' "docs/"
app.connect('html-page-context', html_page_context)
app.add_config_value("edit_on_github_project", "", True)
app.add_config_value("edit_on_github_branch", "master", True)
app.add_config_value("edit_on_github_src_path", "", True) # 'eg' "docs/"
app.connect("html-page-context", html_page_context)
163 changes: 86 additions & 77 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@

from homeassistant.const import __short_version__, __version__

PROJECT_NAME = 'Home Assistant'
PROJECT_PACKAGE_NAME = 'homeassistant'
PROJECT_AUTHOR = 'The Home Assistant Authors'
PROJECT_COPYRIGHT = f' 2013-2020, {PROJECT_AUTHOR}'
PROJECT_LONG_DESCRIPTION = ('Home Assistant is an open-source '
'home automation platform running on Python 3. '
'Track and control all devices at home and '
'automate control. '
'Installation in less than a minute.')
PROJECT_GITHUB_USERNAME = 'home-assistant'
PROJECT_GITHUB_REPOSITORY = 'home-assistant'

GITHUB_PATH = '{}/{}'.format(
PROJECT_GITHUB_USERNAME, PROJECT_GITHUB_REPOSITORY)
GITHUB_URL = f'https://github.com/{GITHUB_PATH}'


sys.path.insert(0, os.path.abspath('_ext'))
sys.path.insert(0, os.path.abspath('../homeassistant'))
PROJECT_NAME = "Home Assistant"
PROJECT_PACKAGE_NAME = "homeassistant"
PROJECT_AUTHOR = "The Home Assistant Authors"
PROJECT_COPYRIGHT = f" 2013-2020, {PROJECT_AUTHOR}"
PROJECT_LONG_DESCRIPTION = (
"Home Assistant is an open-source "
"home automation platform running on Python 3. "
"Track and control all devices at home and "
"automate control. "
"Installation in less than a minute."
)
PROJECT_GITHUB_USERNAME = "home-assistant"
PROJECT_GITHUB_REPOSITORY = "home-assistant"

GITHUB_PATH = f"{PROJECT_GITHUB_USERNAME}/{PROJECT_GITHUB_REPOSITORY}"
GITHUB_URL = f"https://github.com/{GITHUB_PATH}"


sys.path.insert(0, os.path.abspath("_ext"))
sys.path.insert(0, os.path.abspath("../homeassistant"))

# -- General configuration ------------------------------------------------

Expand All @@ -52,27 +53,27 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.linkcode',
'sphinx_autodoc_annotation',
'edit_on_github'
"sphinx.ext.autodoc",
"sphinx.ext.linkcode",
"sphinx_autodoc_annotation",
"edit_on_github",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
#
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = PROJECT_NAME
Expand All @@ -88,25 +89,25 @@
# The full version, including alpha/beta/rc tags.
release = __version__

code_branch = 'dev' if 'dev' in __version__ else 'master'
code_branch = "dev" if "dev" in __version__ else "master"

# Edit on Github config
edit_on_github_project = GITHUB_PATH
edit_on_github_branch = code_branch
edit_on_github_src_path = 'docs/source/'
edit_on_github_src_path = "docs/source/"


def linkcode_resolve(domain, info):
"""Determine the URL corresponding to Python object."""
if domain != 'py':
if domain != "py":
return None
modname = info['module']
fullname = info['fullname']
modname = info["module"]
fullname = info["fullname"]
submod = sys.modules.get(modname)
if submod is None:
return None
obj = submod
for part in fullname.split('.'):
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except:
Expand All @@ -131,7 +132,8 @@ def linkcode_resolve(domain, info):

fn = fn[index:]

return f'{GITHUB_URL}/blob/{code_branch}/{fn}{linespec}'
return f"{GITHUB_URL}/blob/{code_branch}/{fn}{linespec}"


# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -174,7 +176,7 @@ def linkcode_resolve(domain, info):
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -191,22 +193,22 @@ def linkcode_resolve(domain, info):
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'logo': 'logo.png',
'logo_name': PROJECT_NAME,
'description': PROJECT_LONG_DESCRIPTION,
'github_user': PROJECT_GITHUB_USERNAME,
'github_repo': PROJECT_GITHUB_REPOSITORY,
'github_type': 'star',
'github_banner': True,
'travis_button': True,
'touch_icon': 'logo-apple.png',
"logo": "logo.png",
"logo_name": PROJECT_NAME,
"description": PROJECT_LONG_DESCRIPTION,
"github_user": PROJECT_GITHUB_USERNAME,
"github_repo": PROJECT_GITHUB_REPOSITORY,
"github_type": "star",
"github_banner": True,
"travis_button": True,
"touch_icon": "logo-apple.png",
# 'fixed_sidebar': True, # Re-enable when we have more content
}

Expand All @@ -232,12 +234,12 @@ def linkcode_resolve(domain, info):
# This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#
html_favicon = '_static/favicon.ico'
html_favicon = "_static/favicon.ico"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand All @@ -249,7 +251,7 @@ def linkcode_resolve(domain, info):
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
#
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
Expand All @@ -259,13 +261,13 @@ def linkcode_resolve(domain, info):
# Custom sidebar templates, maps document names to template names.
#
html_sidebars = {
'**': [
'about.html',
'links.html',
'searchbox.html',
'sourcelink.html',
'navigation.html',
'relations.html'
"**": [
"about.html",
"links.html",
"searchbox.html",
"sourcelink.html",
"navigation.html",
"relations.html",
]
}

Expand Down Expand Up @@ -326,34 +328,36 @@ def linkcode_resolve(domain, info):
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = 'Home-Assistantdoc'
htmlhelp_basename = "Home-Assistantdoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'home-assistant.tex', 'Home Assistant Documentation',
'Home Assistant Team', 'manual'),
(
master_doc,
"home-assistant.tex",
"Home Assistant Documentation",
"Home Assistant Team",
"manual",
)
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -394,8 +398,7 @@ def linkcode_resolve(domain, info):
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'home-assistant', 'Home Assistant Documentation',
[author], 1)
(master_doc, "home-assistant", "Home Assistant Documentation", [author], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -409,9 +412,15 @@ def linkcode_resolve(domain, info):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Home-Assistant', 'Home Assistant Documentation',
author, 'Home Assistant', 'Open-source home automation platform.',
'Miscellaneous'),
(
master_doc,
"Home-Assistant",
"Home Assistant Documentation",
author,
"Home Assistant",
"Open-source home automation platform.",
"Miscellaneous",
)
]

# Documents to append as an appendix to all manuals.
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def validate_python() -> None:
"""Validate that the right Python version is running."""
if sys.version_info[:3] < REQUIRED_PYTHON_VER:
print(
"Home Assistant requires at least Python {}.{}.{}".format(
*REQUIRED_PYTHON_VER
)
"Home Assistant requires at least Python "
f"{REQUIRED_PYTHON_VER[0]}.{REQUIRED_PYTHON_VER[1]}.{REQUIRED_PYTHON_VER[2]}"
)
sys.exit(1)

Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/aftership/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ async def async_update(self, **kwargs):
"name": name,
"tracking_number": track["tracking_number"],
"slug": track["slug"],
"link": "{}{}/{}".format(
BASE, track["slug"], track["tracking_number"]
),
"link": f"{BASE}{track['slug']}/{track['tracking_number']}",
"last_update": track["updated_at"],
"expected_delivery": track["expected_delivery"],
"status": track["tag"],
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/august/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ async def async_august_configuration_validation_callback(data):
hass.data[DOMAIN][entry_id][TWO_FA_REVALIDATE] = configurator.async_request_config(
f"{DEFAULT_NAME} ({username})",
async_august_configuration_validation_callback,
description="August must be re-verified. Please check your {} ({}) and enter the verification "
"code below".format(login_method, username),
description=(
"August must be re-verified. "
f"Please check your {login_method} ({username}) "
"and enter the verification code below"
),
submit_caption="Verify",
fields=[
{"id": VERIFICATION_CODE_KEY, "name": "Verification code", "type": "string"}
Expand Down Expand Up @@ -265,7 +268,7 @@ async def _async_refresh_device_detail_by_ids(self, device_ids_list):
self._api.async_get_doorbell_detail,
)
_LOGGER.debug(
"async_signal_device_id_update (from detail updates): %s", device_id,
"async_signal_device_id_update (from detail updates): %s", device_id
)
self.async_signal_device_id_update(device_id)

Expand Down
Loading

0 comments on commit fca90a8

Please sign in to comment.