Skip to content

Commit

Permalink
Reformat using black (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner authored Apr 3, 2021
1 parent 3f88275 commit 08fd8e3
Show file tree
Hide file tree
Showing 40 changed files with 1,397 additions and 1,134 deletions.
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ doc: clean-docs
@echo "open file://`pwd`/docs/_build/html/index.html"

isort:
isort aiopg
isort tests
isort examples
isort --use-parentheses --multi-line 3 --combine-as --trailing-comma aiopg
isort --use-parentheses --multi-line 3 --combine-as --trailing-comma tests
isort --use-parentheses --multi-line 3 --combine-as --trailing-comma examples

black:
black --line-length 79 aiopg
black --line-length 79 tests
black --line-length 79 examples

lint: .lint

Expand All @@ -19,13 +24,18 @@ lint: .lint
$(shell find examples -type f)
flake8 aiopg tests examples
python setup.py check -rms
@if ! isort -c aiopg tests examples; then \
@if ! black --line-length 79 --check aiopg tests examples; then \
echo "Format errors, run 'make black' to fix them!!!"; \
false; \
fi
@if ! isort --use-parentheses --multi-line 3 --combine-as --trailing-comma -c aiopg tests examples; then \
echo "Import sort errors, run 'make isort' to fix them!!!"; \
isort --diff aiopg tests examples; \
false; \
fi
@if ! mypy --strict --ignore-missing-imports --exclude sa aiopg; then \
echo "Typing errors"; \
false; \
fi

test: flake
Expand Down
59 changes: 34 additions & 25 deletions aiopg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import warnings
from collections import namedtuple

from .connection import TIMEOUT as DEFAULT_TIMEOUT
from .connection import (
TIMEOUT as DEFAULT_TIMEOUT,
Connection,
Cursor,
DefaultCompiler,
Expand All @@ -20,44 +20,53 @@
from .utils import get_running_loop

warnings.filterwarnings(
'always', '.*',
"always",
".*",
category=ResourceWarning,
module=r'aiopg(\.\w+)+',
append=False
module=r"aiopg(\.\w+)+",
append=False,
)

__all__ = ('connect', 'create_pool', 'get_running_loop',
'Connection', 'Cursor', 'Pool', 'version', 'version_info',
'DEFAULT_TIMEOUT', 'IsolationLevel', 'Transaction')
__all__ = (
"connect",
"create_pool",
"get_running_loop",
"Connection",
"Cursor",
"Pool",
"version",
"version_info",
"DEFAULT_TIMEOUT",
"IsolationLevel",
"Transaction",
)

__version__ = '1.3.0b2'
__version__ = "1.3.0b2"

version = f'{__version__}, Python {sys.version}'
version = f"{__version__}, Python {sys.version}"

VersionInfo = namedtuple('VersionInfo',
'major minor micro releaselevel serial')
VersionInfo = namedtuple(
"VersionInfo", "major minor micro releaselevel serial"
)


def _parse_version(ver: str) -> VersionInfo:
RE = (
r'^'
r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)'
r'((?P<releaselevel>[a-z]+)(?P<serial>\d+)?)?'
r'$'
r"^"
r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)"
r"((?P<releaselevel>[a-z]+)(?P<serial>\d+)?)?"
r"$"
)
match = re.match(RE, ver)
if not match:
raise ImportError(f"Invalid package version {ver}")
try:
major = int(match.group('major'))
minor = int(match.group('minor'))
micro = int(match.group('micro'))
levels = {'rc': 'candidate',
'a': 'alpha',
'b': 'beta',
None: 'final'}
releaselevel = levels[match.group('releaselevel')]
serial = int(match.group('serial')) if match.group('serial') else 0
major = int(match.group("major"))
minor = int(match.group("minor"))
micro = int(match.group("micro"))
levels = {"rc": "candidate", "a": "alpha", "b": "beta", None: "final"}
releaselevel = levels[match.group("releaselevel")]
serial = int(match.group("serial")) if match.group("serial") else 0
return VersionInfo(major, minor, micro, releaselevel, serial)
except Exception as e:
raise ImportError(f"Invalid package version {ver}") from e
Expand All @@ -80,5 +89,5 @@ def _parse_version(ver: str) -> VersionInfo:
DefaultCompiler,
ReadCommittedCompiler,
RepeatableReadCompiler,
SerializableCompiler
SerializableCompiler,
)
Loading

0 comments on commit 08fd8e3

Please sign in to comment.