Skip to content

Upgrade dependencies are reccomended by github's dependabot and poetry's show-outdated #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python_package_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
run_image:
runs-on: [ubuntu-latest]
container:
image: matanrubin/python-poetry:3.9
image: python:3.10

env:
TEST_REDIS_SERVER: True
Expand All @@ -31,7 +31,7 @@ jobs:
- run: make coverage

# Run pylint+mypy after installing psutil so they don't complain on missing dependencies
- run: poetry install --extras psutil
- run: poetry install --extras flask --extras fastapi --extras aiohttp --extras tornado --extras db --extras redis --extras psutil
- run: make check

# Run tests with coverage again - this adds tests that require psutil
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python_package_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
run_image:
runs-on: [ubuntu-latest]
container:
image: matanrubin/python-poetry:3.9
image: python:3.10

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ help:
@echo "- coverage Check test coverage"

bootstrap:
poetry --version || curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
poetry --version || curl -sSL https://install.python-poetry.org | python3 -
ln -s ${HOME}/.local/bin/poetry /usr/local/bin
poetry install

check: pylint mypy
Expand Down
2,177 changes: 1,896 additions & 281 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyctuator/health/aioredis_health_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from typing import Any, Coroutine, Mapping

from pyctuator.health.health_provider import Status
from pyctuator.health.redis_health_provider import RedisHealthStatus, RedisHealthDetails, RedisHealthProvider
Expand All @@ -7,7 +8,7 @@
class AioRedisHealthProvider(RedisHealthProvider):
def get_health(self) -> RedisHealthStatus:
try:
info = asyncio.run(self.redis.info())
info: Mapping[str, Any] = self.redis.info()

return RedisHealthStatus(
status=Status.UP,
Expand Down
34 changes: 10 additions & 24 deletions pyctuator/impl/aiohttp_pyctuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,27 @@ class AioHttpPyctuator(PyctuatorRouter):
def __init__(self, app: web.Application, pyctuator_impl: PyctuatorImpl, disabled_endpoints: Endpoints) -> None:
super().__init__(app, pyctuator_impl)

custom_dumps = partial(
json.dumps, default=self._custom_json_serializer
)

async def empty_handler(request: web.Request) -> web.Response:
return web.Response(text='')

async def get_endpoints(request: web.Request) -> web.Response:
return web.json_response(self.get_endpoints_data(), dumps=custom_dumps)
return web.json_response(self.get_endpoints_data)

async def get_environment(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_environment(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_environment)

async def get_info(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_app_info(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_app_info)

async def get_health(request: web.Request) -> web.Response:
health = pyctuator_impl.get_health()
return web.json_response(health, status=health.http_status(), dumps=custom_dumps)
return web.json_response(health, status=health.http_status)

async def get_metric_names(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_metric_names(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_metric_names)

async def get_loggers(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.logging.get_loggers(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.logging.get_loggers)

async def set_logger_level(request: web.Request) -> web.Response:
request_dict = await request.json()
Expand All @@ -57,19 +53,17 @@ async def set_logger_level(request: web.Request) -> web.Response:

async def get_logger(request: web.Request) -> web.Response:
logger_name = request.match_info["logger_name"]
return web.json_response(pyctuator_impl.logging.get_logger(logger_name), dumps=custom_dumps)
return web.json_response(pyctuator_impl.logging.get_logger(logger_name))

async def get_thread_dump(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_thread_dump(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_thread_dump)

async def get_httptrace(request: web.Request) -> web.Response:
raw_data = pyctuator_impl.http_tracer.get_httptrace()
return web.json_response(raw_data, dumps=custom_dumps)
return web.json_response(raw_data)

async def get_metric_measurement(request: web.Request) -> web.Response:
return web.json_response(
pyctuator_impl.get_metric_measurement(request.match_info["metric_name"]),
dumps=custom_dumps)
return web.json_response( pyctuator_impl.get_metric_measurement(request.match_info["metric_name"]))

async def get_logfile(request: web.Request) -> web.Response:
range_header = request.headers.get("range")
Expand Down Expand Up @@ -153,14 +147,6 @@ async def intercept_requests_and_responses(request: web.Request, handler: Callab
app.add_routes(routes)
app.middlewares.append(intercept_requests_and_responses)

def _custom_json_serializer(self, value: Any) -> Any:
if dataclasses.is_dataclass(value):
return dataclasses.asdict(value)

if isinstance(value, datetime):
return str(value)
return None

def _create_headers_dictionary(self, headers: CIMultiDictProxy[str]) -> Mapping[str, List[str]]:
headers_dict: Mapping[str, List[str]] = defaultdict(list)
for (key, value) in headers.items():
Expand Down
28 changes: 14 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyctuator"
version = "1.2.0"
version = "1.8.0"
description = "A Python implementation of the Spring Actuator API for popular web frameworks"
authors = [
"Michael Yakobi <michael.yakobi@solaredge.com>",
Expand Down Expand Up @@ -35,24 +35,24 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.9"
psutil = { version = "^5.6", optional = true }
psutil = { version = "^6.0.0", optional = true }
flask = { version = "^2.3.0", optional = true }
fastapi = { version = "^0.100.1", optional = true }
uvicorn = { version = "^0.23.0", optional = true }
sqlalchemy = {version = "^2.0.4", optional = true}
PyMySQL = {version = "^1.0.2", optional = true}
fastapi = { version = "^0.111.1", optional = true }
uvicorn = { version = "^0.30.1", optional = true }
sqlalchemy = {version = "^2.0.31", optional = true}
PyMySQL = {version = "^1.1.1", optional = true}
cryptography = {version = ">=39.0.1,<40.0.0", optional = true}
redis = {version = "^4.3.4", optional = true}
aiohttp = {version = "^3.6.2", optional = true}
tornado = {version = "^6.0.4", optional = true}
redis = {version = "^5.0.7", optional = true}
aiohttp = {version = "^3.9.4", optional = true}
tornado = {version = "^6.4.1", optional = true}

[tool.poetry.dev-dependencies]
requests = "^2.22"
pytest = "^7.1.3"
mypy = "^1.0.1"
requests = "^2.32.3"
pytest = "^8.2.2"
mypy = "^1.11.0"
pylint = "^2.15.0" # v2.5 does not properly run on docker image...
pytest-cov = "^4.0.0"
autopep8 = "^2.0.0"
pytest-cov = "^5.0.0"
autopep8 = "^2.3.1"

[tool.poetry.extras]
psutil = ["psutil"]
Expand Down
4 changes: 3 additions & 1 deletion tests/health/test_aioredis_health_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import importlib.util
import os
from typing import Any

import pytest
from redis import Redis

@pytest.fixture
def require_redis() -> None:
Expand All @@ -28,7 +30,7 @@ def test_aioredis_health(redis_host: str) -> None:
from pyctuator.health.health_provider import Status
from pyctuator.health.aioredis_health_provider import AioRedisHealthProvider, RedisHealthStatus, RedisHealthDetails

redis_instance = AioRedis(host=redis_host)
redis_instance: Redis[bytes] = AioRedis(host=redis_host)

health = AioRedisHealthProvider(redis_instance).get_health()
assert health == RedisHealthStatus(Status.UP, RedisHealthDetails("5.0.3", "standalone"))
Expand Down
4 changes: 2 additions & 2 deletions tests/health/test_redis_health_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_redis_health(redis_host: str) -> None:
from pyctuator.health.redis_health_provider import RedisHealthProvider, RedisHealthStatus, RedisHealthDetails

health = RedisHealthProvider(redis.Redis(host=redis_host)).get_health()
assert health == RedisHealthStatus(Status.UP, RedisHealthDetails("5.0.3", "standalone"))
assert health == RedisHealthStatus(Status.UP, RedisHealthDetails("7.2.5", "standalone"))


@pytest.mark.usefixtures("require_redis", "require_redis_server")
Expand All @@ -41,4 +41,4 @@ def test_redis_bad_password(redis_host: str) -> None:

health = RedisHealthProvider(redis.Redis(host=redis_host, password="blabla")).get_health()
assert health.status == Status.DOWN
assert "Client sent AUTH, but no password is set" in str(health.details.failure)
assert "called without any password configured for the default user" in str(health.details.failure)
Loading