Skip to content

Commit

Permalink
Run the whole codebase against pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Jul 14, 2020
1 parent ae0bb70 commit ca76bc0
Show file tree
Hide file tree
Showing 116 changed files with 63 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.5
python-version: 3.7
- name: Set Cache Key
run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)"
- uses: actions/cache@v1
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ repos:
- id: check-merge-conflict # Check for files that contain merge conflict strings.
- id: check-ast # Simply check whether files parse as valid python.

- repo: https://github.com/asottile/pyupgrade
rev: v2.7.0
hooks:
- id: pyupgrade
name: Rewrite Code to be Py3.5+
args: [--py3-plus]

- repo: https://github.com/asottile/reorder_python_imports
rev: v1.9.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=saltpylint.pep8,
saltpylint.pep263,
saltpylint.strings,
saltpylint.fileperms,
saltpylint.smartup,
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import datetime
import json
import os
Expand Down
1 change: 0 additions & 1 deletion saltfactories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
NG PyTest Salt Plugin
"""
Expand Down
15 changes: 7 additions & 8 deletions saltfactories/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

"""Git implementation of _version.py."""

from __future__ import absolute_import, print_function, unicode_literals
import errno
import os
import re
Expand Down Expand Up @@ -84,7 +83,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
except EnvironmentError:
except OSError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
Expand All @@ -94,7 +93,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print("unable to find command, tried {}".format(commands))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -141,7 +140,7 @@ def git_get_keywords(versionfile_abs):
# _version.py.
keywords = {}
try:
f = open(versionfile_abs, "r")
f = open(versionfile_abs)
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
Expand All @@ -156,7 +155,7 @@ def git_get_keywords(versionfile_abs):
if mo:
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
except OSError:
pass
return keywords

Expand All @@ -180,11 +179,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
refs = {r.strip() for r in refnames.strip("()").split(",")}
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
tags = {r[len(TAG):] for r in refs if r.startswith(TAG)}
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
Expand All @@ -193,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
tags = {r for r in refs if re.search(r'\d', r)}
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
Expand Down
1 change: 0 additions & 1 deletion saltfactories/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.exceptions
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/factories/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
3 changes: 1 addition & 2 deletions saltfactories/factories/manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.factories.manager
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -32,7 +31,7 @@
from saltfactories.utils.ports import get_unused_localhost_port


class SaltFactoriesManager(object):
class SaltFactoriesManager:
"""
The :class:`SaltFactoriesManager` is responsible for configuring and spawning Salt Daemons and
making sure that any salt CLI tools are "targetted" to the right daemon.
Expand Down
3 changes: 1 addition & 2 deletions saltfactories/factories/master.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.factories.master
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -19,7 +18,7 @@
from saltfactories.utils import ports


class MasterFactory(object):
class MasterFactory:
@staticmethod
def default_config(
root_dir, master_id, config_defaults=None, config_overrides=None, order_masters=False,
Expand Down
3 changes: 1 addition & 2 deletions saltfactories/factories/minion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.factories.minion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -19,7 +18,7 @@
from saltfactories.utils import ports


class MinionFactory(object):
class MinionFactory:
@staticmethod
def default_config(
root_dir, minion_id, config_defaults=None, config_overrides=None, master_port=None
Expand Down
3 changes: 1 addition & 2 deletions saltfactories/factories/proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.factories.proxy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -19,7 +18,7 @@
from saltfactories.utils import ports


class ProxyMinionFactory(object):
class ProxyMinionFactory:
@staticmethod
def default_config(
root_dir, proxy_minion_id, config_defaults=None, config_overrides=None, master_port=None,
Expand Down
3 changes: 1 addition & 2 deletions saltfactories/factories/syndic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.factories.minion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -19,7 +18,7 @@
from saltfactories.utils import ports


class SyndicFactory(object):
class SyndicFactory:
@staticmethod
def default_config(
root_dir,
Expand Down
1 change: 0 additions & 1 deletion saltfactories/hookspec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.hookspec
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.plugin
~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion saltfactories/plugins/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.plugins.factories
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/plugins/markers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.plugins.markers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/plugins/sysinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.plugins.sysinfo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/plugins/sysstats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.plugins.sysstats
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils
~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion saltfactories/utils/cli_scripts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.cli_scripts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
16 changes: 0 additions & 16 deletions saltfactories/utils/compat.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.compat
~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports compatability layer
"""
import sys
import weakref

# pragma: no cover
# pylint: disable=unused-import,invalid-name
try:
from unittest import mock
except ImportError:
import mock

if sys.version_info < (3,):
import backports.weakref

weakref.finalize = backports.weakref.finalize
# pylint: enable=unused-import,invalid-name


def has_unittest_attr(item, attr):
Expand Down
2 changes: 0 additions & 2 deletions saltfactories/utils/coverage/sitecustomize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

try:
import coverage

Expand Down
3 changes: 1 addition & 2 deletions saltfactories/utils/event_listener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.event_listener
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -20,7 +19,7 @@
log = logging.getLogger(__name__)


class EventListener(object):
class EventListener:
def __init__(self, timeout=60, auth_events_callback=None):
self.store = deque(maxlen=10000)
self.address = "tcp://127.0.0.1:{}".format(ports.get_unused_localhost_port())
Expand Down
1 change: 0 additions & 1 deletion saltfactories/utils/log_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
pytestsalt.fixtures.log_server_tornado
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 3 additions & 4 deletions saltfactories/utils/markers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.markers
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -93,14 +92,14 @@ def skip_if_no_local_network():
pubsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
pubsock.bind(("", check_port))
has_local_network = True
except socket.error:
except OSError:
# I wonder if we just have IPV6 support?
try:
with contextlib.closing(socket.socket(socket.AF_INET6, socket.SOCK_STREAM)) as pubsock:
pubsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
pubsock.bind(("", check_port))
has_local_network = True
except socket.error:
except OSError:
# Let's continue
pass
if has_local_network is False:
Expand Down Expand Up @@ -143,7 +142,7 @@ def skip_if_no_remote_network():
# We connected? Stop the loop
has_remote_network = True
break
except socket.error:
except OSError:
# Let's check the next IP
continue

Expand Down
1 change: 0 additions & 1 deletion saltfactories/utils/platform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.platform
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions saltfactories/utils/ports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.ports
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -62,6 +61,6 @@ def get_connectable_ports(ports):
log.debug("Port %s is connectable!", port)
connectable_ports.add(port)
sock.shutdown(socket.SHUT_RDWR)
except socket.error:
except OSError:
continue
return connectable_ports
1 change: 0 additions & 1 deletion saltfactories/utils/processes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.processes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 6 additions & 7 deletions saltfactories/utils/processes/bases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.processes.bases
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -14,6 +13,7 @@
import sys
import tempfile
import time
import weakref
from collections import namedtuple
from operator import itemgetter

Expand All @@ -28,7 +28,6 @@
# import error, but its safe to pass
pass

from saltfactories.utils import compat
from saltfactories.utils.processes.helpers import terminate_process
from saltfactories.exceptions import ProcessTimeout

Expand All @@ -51,8 +50,8 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__stdout = stdout
self.__stderr = stderr
compat.weakref.finalize(self, stdout.close)
compat.weakref.finalize(self, stderr.close)
weakref.finalize(self, stdout.close)
weakref.finalize(self, stderr.close)

def communicate(self, input=None): # pylint: disable=arguments-differ
super().communicate(input)
Expand Down Expand Up @@ -158,7 +157,7 @@ def __eq__(self, other):
return self.stdout == other


class FactoryProcess(object):
class FactoryProcess:
"""
Base class for subprocesses
"""
Expand Down Expand Up @@ -433,9 +432,9 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.python_executable = python_executable or sys.executable
# We really do not want buffered output
self.environ.setdefault(str("PYTHONUNBUFFERED"), str("1"))
self.environ.setdefault("PYTHONUNBUFFERED", "1")
# Don't write .pyc files or create them in __pycache__ directories
self.environ.setdefault(str("PYTHONDONTWRITEBYTECODE"), str("1"))
self.environ.setdefault("PYTHONDONTWRITEBYTECODE", "1")

def build_cmdline(self, *args, **kwargs):
cmdline = super().build_cmdline(*args, **kwargs)
Expand Down
1 change: 0 additions & 1 deletion saltfactories/utils/processes/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
saltfactories.utils.processes.helpers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit ca76bc0

Please sign in to comment.