Skip to content

Commit

Permalink
[feature] add Python 3.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gr1N committed Apr 29, 2019
1 parent 70f3125 commit 713026d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
17 changes: 15 additions & 2 deletions .github/main.workflow
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@ workflow "run linters and tests" {
resolves = ["notify build succeeded"]
}

action "py3.6 linting and testing" {
uses = "docker://python:3.6"
runs = ["sh", "-c", "make ci-quality-basic"]
secrets = [
"CODECOV_TOKEN",
]
}

action "py3.7 linting and testing" {
uses = "docker://python:3.7.2"
needs = [
"py3.6 linting and testing",
]
uses = "docker://python:3.7"
runs = ["sh", "-c", "make ci-quality"]
secrets = [
"CODECOV_TOKEN",
]
}

action "notify build succeeded" {
needs = "py3.7 linting and testing"
needs = [
"py3.7 linting and testing",
]
uses = "docker://gr1n/the-telegram-action:master"
env = {
TELEGRAM_MESSAGE = "`aiodogstatsd` build succeeded"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.4.0 (2019-XX-XX)

- Added Python 3.6.* support.

## 0.3.0 (2019-04-21)

- Fixed datagram format.
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ test:
publish:
@$(POETRY) publish --username=$(PYPI_USERNAME) --password=$(PYPI_PASSWORD) --build

.PHONY: ci-quality-basic
ci-quality-basic: install lint test

.PHONY: ci-quality
ci-quality: install lint test
ci-quality: ci-quality-basic
@$(POETRY) run codecov --token=$(CODECOV_TOKEN)

.PHONY: ci-publish
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ async def main():
await client.close()


asyncio.run(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```

...or you can also use client as a context manager:
Expand All @@ -47,7 +48,8 @@ async def main():
client.increment("users.online")


asyncio.run(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```

Look at `examples/` to find more examples of library usage.
Expand Down
17 changes: 13 additions & 4 deletions aiodogstatsd/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import asyncio
import sys
from asyncio.transports import DatagramTransport
from random import random
from typing import Optional
Expand Down Expand Up @@ -61,15 +60,15 @@ def __init__(
self._read_timeout = read_timeout
self._close_timeout = close_timeout

async def __aenter__(self) -> Client:
async def __aenter__(self) -> "Client":
await self.connect()
return self

async def __aexit__(self, *args) -> None:
await self.close()

async def connect(self) -> None:
loop = asyncio.get_running_loop()
loop = _get_event_loop()
await loop.create_datagram_endpoint(
lambda: self._protocol, remote_addr=(self._host, self._port)
)
Expand Down Expand Up @@ -249,3 +248,13 @@ def send(self, data: bytes) -> None:
except Exception:
# Errors should fail silently so they don't affect anything else
pass


def _get_event_loop_factory(): # pragma: no cover
if sys.version_info >= (3, 7):
return asyncio.get_running_loop # type: ignore

return asyncio.get_event_loop


_get_event_loop = _get_event_loop_factory()
3 changes: 2 additions & 1 deletion examples/contextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ async def main():


if __name__ == "__main__":
asyncio.run(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
3 changes: 2 additions & 1 deletion examples/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ async def main():


if __name__ == "__main__":
asyncio.run(main())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.6"

[tool.poetry.dev-dependencies]
black = { version = ">=18.9b0", allows-prereleases = true }
Expand Down

0 comments on commit 713026d

Please sign in to comment.