Skip to content

Commit

Permalink
Reformat and fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Oct 8, 2024
1 parent 8be24db commit 6eee29e
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 75 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ jobs:
strategy:
matrix:
linter:
- lint
- mypy
- pylama aiofile tests
- mypy aiofile tests

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setting up python 3.10
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
architecture: x64

- name: Installing tox
run: python -m pip install tox
- name: Poetry install
run: python -m pip install poetry && poetry install

- name: tox ${{ matrix.linter }}
run: tox
env:
TOXENV: ${{ matrix.linter }}
- name: ${{ matrix.linter }}
run: poetry run ${{ matrix.linter }}

tests:
strategy:
Expand Down
1 change: 0 additions & 1 deletion aiofile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
BinaryFileWrapper, FileIOWrapperBase, LineReader, Reader, TextFileWrapper,
Writer, async_open,
)

from .version import (
__author__, __version__, author_info, package_info, package_license,
project_home, team_email, version_info,
Expand Down
2 changes: 1 addition & 1 deletion aiofile/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def from_fp(cls, fp: FileIOType, **kwargs: Any) -> "AIOFile":
return afp

def _run_in_thread(
self, func: "Callable[..., _T]", *args: Any, **kwargs: Any
self, func: "Callable[..., _T]", *args: Any, **kwargs: Any,
) -> "asyncio.Future[_T]":
return self.__context.loop.run_in_executor(
self._executor, partial(func, *args, **kwargs),
Expand Down
2 changes: 1 addition & 1 deletion aiofile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ async def readline(self, size: int = -1, newline: str = "\n") -> str:

def async_open(
file_specifier: Union[str, Path, FileIOType],
mode: str = "r", *args: Any, **kwargs: Any
mode: str = "r", *args: Any, **kwargs: Any,
) -> Union[BinaryFileWrapper, TextFileWrapper]:
if isinstance(file_specifier, (str, Path)):
afp = AIOFile(str(file_specifier), mode, *args, **kwargs)
Expand Down
19 changes: 10 additions & 9 deletions aiofile/version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import importlib.metadata

package_metadata = importlib.metadata.metadata('aiofile')

__author__ = package_metadata['Author']
__version__ = package_metadata['Version']
author_info = [(package_metadata['Author'], package_metadata['Author-email'])]
package_info = package_metadata['Summary']
package_license = package_metadata['License']
project_home = package_metadata['Home-page']
team_email = package_metadata['Author-email']
version_info = tuple(map(int, __version__.split('.')))
package_metadata = importlib.metadata.metadata("aiofile")

__author__ = package_metadata["Author"]
__version__ = package_metadata["Version"]
author_info = [(package_metadata["Author"], package_metadata["Author-email"])]
package_info = package_metadata["Summary"]
package_license = package_metadata["License"]
project_home = package_metadata["Home-page"]
team_email = package_metadata["Author-email"]
version_info = tuple(map(int, __version__.split(".")))
168 changes: 167 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pytest = ">=8.2.0,<8.3.0"
aiomisc-pytest = "^1.2.1"
pytest-cov = "^5.0.0"
coveralls = "<4"
pylama = "^8.4.1"
setuptools = "^75.1.0"
mypy = "^1.11.2"

[build-system]
requires = ["poetry-core"]
Expand All @@ -64,12 +67,22 @@ strict_optional = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true
files = [
"aiofile",
"tests",
]

[tool.mypy.tests]
ignore_errors = true
[[tool.mypy.overrides]]
module = ["tests.*"]
check_untyped_defs = true
disallow_incomplete_defs = false
disallow_untyped_calls = false
disallow_untyped_decorators = false
disallow_untyped_defs = false
warn_unused_ignores = false

[tool.pylama]
skip = ["env*", ".tox*", "*build*"]
skip = ["*env*", ".*", "*build*"]

[tool.pylama.pycodestyle]
max_line_length = 80
Expand Down
24 changes: 14 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from functools import partial
from types import ModuleType
from typing import List, Union

import pytest
from caio import python_aio_asyncio
Expand All @@ -9,35 +11,37 @@
try:
from caio import thread_aio_asyncio
except ImportError:
thread_aio_asyncio = None
thread_aio_asyncio = None # type: ignore

try:
from caio import linux_aio_asyncio
except ImportError:
linux_aio_asyncio = None
linux_aio_asyncio = None # type: ignore


class DefaultContext:
__name__ = "default"


IMPLEMENTATIONS = list(
IMPLEMENTATIONS: List[Union[ModuleType, None]] = list(
filter(
None, [
linux_aio_asyncio,
thread_aio_asyncio,
python_aio_asyncio,
DefaultContext(),
],
),
)

IMPLEMENTATION_NAMES = map(lambda x: x.__name__, IMPLEMENTATIONS)
IMPLEMENTATIONS.insert(0, None)

IMPLEMENTATION_NAMES: List[str] = list(
map(
lambda x: x.__name__ if x is not None else "default",
IMPLEMENTATIONS
)
)


@pytest.fixture(params=IMPLEMENTATIONS, ids=IMPLEMENTATION_NAMES)
async def aio_context(request, event_loop):
if isinstance(request.param, DefaultContext):
if request.param is None:
yield None
return

Expand Down
6 changes: 4 additions & 2 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from unittest.mock import Mock, call
from uuid import uuid4

import caio
import pytest
import caio # type: ignore
import pytest # type: ignore

from aiofile import AIOFile
from aiofile.utils import (
Expand Down Expand Up @@ -236,6 +236,8 @@ async def test_line_reader(aio_file_maker, temp_file, uuid):
chunk = b64encode(os.urandom(max_length)).decode()
lines = [chunk[:i] for i in range(max_length)]

line: str | bytes

for line in lines:
await writer(line)
await writer("\n")
Expand Down
Loading

0 comments on commit 6eee29e

Please sign in to comment.