Skip to content

Commit

Permalink
Add pyupgrade (in pre-commit and CI) (home-assistant#33688)
Browse files Browse the repository at this point in the history
* Add pyupgrade (in pre-commit and CI)

* Fix leftover results of pyupgrade

* Ensure we run for Python 3.7 on pyupgrade
  • Loading branch information
frenck authored Apr 5, 2020
1 parent 5bf7e0f commit f380115
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.1.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ stages:
. venv/bin/activate
pre-commit run yamllint --all-files
displayName: 'Run yamllint'
- script: |
. venv/bin/activate
pre-commit run pyupgrade --all-files
displayName: 'Run pyupgrade'
- job: 'Validate'
pool:
vmImage: 'ubuntu-latest'
Expand Down
7 changes: 3 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Home-Assistant documentation build configuration file, created by
# sphinx-quickstart on Sun Aug 28 13:13:10 2016.
Expand All @@ -26,7 +25,7 @@
PROJECT_NAME = 'Home Assistant'
PROJECT_PACKAGE_NAME = 'homeassistant'
PROJECT_AUTHOR = 'The Home Assistant Authors'
PROJECT_COPYRIGHT = ' 2013-2020, {}'.format(PROJECT_AUTHOR)
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 '
Expand All @@ -37,7 +36,7 @@

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


sys.path.insert(0, os.path.abspath('_ext'))
Expand Down Expand Up @@ -132,7 +131,7 @@ def linkcode_resolve(domain, info):

fn = fn[index:]

return '{}/blob/{}/{}{}'.format(GITHUB_URL, 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
1 change: 1 addition & 0 deletions requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ flake8-docstrings==1.5.0
flake8==3.7.9
isort==4.3.21
pydocstyle==5.0.2
pyupgrade==2.1.0
yamllint==1.21.0
2 changes: 1 addition & 1 deletion script/hassfest/codeowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def validate(integrations: Dict[str, Integration], config: Config):
codeowners_path = config.root / "CODEOWNERS"
config.cache["codeowners"] = content = generate_and_validate(integrations)

with open(str(codeowners_path), "r") as fp:
with open(str(codeowners_path)) as fp:
if fp.read().strip() != content:
config.add_error(
"codeowners",
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def validate(integrations: Dict[str, Integration], config: Config):
config_flow_path = config.root / "homeassistant/generated/config_flows.py"
config.cache["config_flow"] = content = generate_and_validate(integrations)

with open(str(config_flow_path), "r") as fp:
with open(str(config_flow_path)) as fp:
if fp.read().strip() != content:
config.add_error(
"config_flow",
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Error:

def __str__(self) -> str:
"""Represent error as string."""
return "[{}] {}".format(self.plugin.upper(), self.error)
return f"[{self.plugin.upper()}] {self.error}"


@attr.s
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def validate(integrations: Dict[str, Integration], config: Config):
ssdp_path = config.root / "homeassistant/generated/ssdp.py"
config.cache["ssdp"] = content = generate_and_validate(integrations)

with open(str(ssdp_path), "r") as fp:
with open(str(ssdp_path)) as fp:
if fp.read().strip() != content:
config.add_error(
"ssdp",
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/zeroconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def validate(integrations: Dict[str, Integration], config: Config):
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
config.cache["zeroconf"] = content = generate_and_validate(integrations)

with open(str(zeroconf_path), "r") as fp:
with open(str(zeroconf_path)) as fp:
current = fp.read().strip()
if current != content:
config.add_error(
Expand Down

0 comments on commit f380115

Please sign in to comment.