Skip to content

Commit

Permalink
Upgrade Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 9, 2024
1 parent 405294c commit 6c797a2
Show file tree
Hide file tree
Showing 42 changed files with 271 additions and 542 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ repos:
- --output-format=pylint
additional_dependencies:
- prospector-profile-duplicated==1.6.0 # pypi
- prospector-profile-utils==1.9.1 # pypi
- repo: https://github.com/sbrunner/jsonschema-validator
rev: 0.1.0
hooks:
Expand Down
51 changes: 10 additions & 41 deletions .prospector.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
inherits:
- utils:base
- utils:no-design-checks
- utils:fix
- duplicated
strictness: veryhigh
max-line-length: 110

doc-warnings: true

ignore-paths:
Expand All @@ -15,56 +17,23 @@ pylint:
- ujson
- lxml
disable:
- too-many-return-statements
- too-many-arguments
- too-many-branches
- too-many-instance-attributes
- too-few-public-methods
- global-statement
- line-too-long
- import-outside-toplevel
- invalid-name
- no-else-return
- no-else-raise
- no-self-use
- import-error
- unused-argument
- use-symbolic-message-instead
- missing-module-docstring
- missing-function-docstring
- missing-timeout # A default timeout is set

pycodestyle:
options:
max-line-length: 110
disable:
- E722 # do not use bare 'except', duplicated with pylint
- E261 # at least two spaces before inline comment, duplicated with black

pydocstyle:
disable:
- D102 # Missing docstring in public method
- D104 # Missing docstring in public package
- D105 # Missing docstring in magic method
- D107 # Missing docstring in __init__
- D202 # No blank lines allowed after function docstring (found 1)
- D203 # 1 blank line required before class docstring (found 0)
- D212 # Multi-line docstring summary should start at the first line
- D407 # Missing dashed underline after section ('Arguments')
- D412 # No blank lines allowed between a section header and its content ('Arguments')
mypy:
run: true

pycodestyle:
disable:
# Buggy checks with Python 3.12
- E221 # multiple spaces before operator
- E702 # multiple statements on one line (semicolon)

bandit:
run: true
options:
config: .bandit.yaml

pyroma:
run: true

mccabe:
run: false

dodgy:
run: false
207 changes: 50 additions & 157 deletions acceptance_tests/app/poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion acceptance_tests/app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ coverage = "7.6.1"

[tool.poetry.dev-dependencies]
# pylint = { version = "2.15.6" }
prospector = { extras = ["with_bandit", "with_mypy"], version = "1.11.0" }
prospector = { extras = ["with_bandit", "with_mypy"], version = "1.12.0" }
prospector-profile-duplicated = "1.6.0"
prospector-profile-utils = "1.9.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
1 change: 0 additions & 1 deletion c2cwsgiutils/acceptance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def retry(
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
Arguments:
exception_to_check: the exception to check. may be a tuple of exceptions to check
tries: number of times to try (not retry) before giving up
delay: initial delay between retries in seconds
Expand Down
3 changes: 1 addition & 2 deletions c2cwsgiutils/acceptance/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def get_xml(
**kwargs: Any,
) -> Any:
"""Get the given URL (relative to the root of API)."""

from lxml import etree # nosec
from lxml import etree # nosec # pylint: disable=import-outside-toplevel

with self.session.get(
self.base_url + url,
Expand Down
13 changes: 6 additions & 7 deletions c2cwsgiutils/acceptance/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import subprocess # nosec
from typing import TYPE_CHECKING, Any, Optional

import numpy as np
import skimage.color
import skimage.io
import skimage.metrics
import skimage.transform
import numpy as np # pylint: disable=import-error
import skimage.color # pylint: disable=import-error
import skimage.io # pylint: disable=import-error
import skimage.metrics # pylint: disable=import-error
import skimage.transform # pylint: disable=import-error

if TYPE_CHECKING:
from typing import TypeAlias
Expand Down Expand Up @@ -189,7 +189,7 @@ def check_screenshot(
See also `check_image` for the other parameters.
Args:
Arguments:
url: The URL to screenshot
width: The width of the generated screenshot
height: The height of the generated screenshot
Expand All @@ -202,7 +202,6 @@ def check_screenshot(
generate_expected_image: See `check_image`
use_mask: See `check_image`
"""

if headers is None:
headers = {}
if media is None:
Expand Down
4 changes: 4 additions & 0 deletions c2cwsgiutils/acceptance/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ def wait_ready(self, timeout: int = 60, app: str = "default") -> None:
utils.retry_timeout(functools.partial(self.get_capabilities, app=app), timeout=timeout)

def get_capabilities(self, app: str) -> Any:
"""Get the capabilities for the given application."""
return self.get_json(app + "/capabilities.json", cache_expected=connection.CacheExpected.YES)

def get_example_requests(self, app: str) -> dict[str, Any]:
"""Get the example requests for the given application."""
samples = self.get_json(app + "/exampleRequest.json", cache_expected=connection.CacheExpected.YES)
out = {}
for name, value in samples.items():
out[name] = json.loads(value)
return out

def get_pdf(self, app: str, request: dict[str, Any], timeout: int = 60) -> requests.Response:
"""Create a report and wait for it to be ready."""
create_report = self.post_json(app + "/report.pdf", json=request)
LOG.debug("create_report=%s", create_report)
ref = create_report["ref"]
Expand All @@ -59,4 +62,5 @@ def _check_completion(self, ref: str) -> Optional[Any]:
return None

def get_apps(self) -> Any:
"""Get the list of available applications."""
return self.get_json("apps.json", cache_expected=connection.CacheExpected.YES)
4 changes: 1 addition & 3 deletions c2cwsgiutils/acceptance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ def retry_timeout(what: Callable[[], Any], timeout: float = _DEFAULT_TIMEOUT, in
Retry the function until the timeout.
Arguments:
what: the function to try
timeout: the timeout to get a success
interval: the interval between try
"""

timeout = time.perf_counter() + timeout
while True:
error = ""
Expand All @@ -58,7 +56,7 @@ def approx(struct: Any, **kwargs: Any) -> Any:
See pytest.approx
"""
import boltons.iterutils
import boltons.iterutils # pylint: disable=import-outside-toplevel

if isinstance(struct, float):
return pytest.approx(struct, **kwargs)
Expand Down
8 changes: 4 additions & 4 deletions c2cwsgiutils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ def check_access(
If the authentication type is not GitHub, this function is equivalent to is_auth.
`repo` is the repository to check access to (<organization>/<repository>).
`access_type` is the type of access to check (admin|push|pull).
Arguments:
request: is the request object.
repo: is the repository to check access to (<organization>/<repository>).
access_type: is the type of access to check (admin|push|pull).
"""

if not is_auth(request):
return False

Expand Down Expand Up @@ -243,7 +244,6 @@ def check_access(

def check_access_config(request: pyramid.request.Request, auth_config: AuthConfig) -> bool:
"""Check if the user has access to the resource."""

auth, user = is_auth_user(request)
if not auth:
return False
Expand Down
9 changes: 4 additions & 5 deletions c2cwsgiutils/broadcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def _get(need_init: bool = False) -> interface.BaseBroadcaster:

def cleanup() -> None:
"""Cleanup the broadcaster to force to reinitialize it."""

global _broadcaster
_broadcaster = None

Expand Down Expand Up @@ -96,21 +95,21 @@ def broadcast(

# We can also templatise the argument with Python 3.10
# See: https://www.python.org/dev/peps/pep-0612/
_DECORATOR_RETURN = TypeVar("_DECORATOR_RETURN")
_DecoratorReturn = TypeVar("_DecoratorReturn")


def decorator(
channel: Optional[str] = None, expect_answers: bool = False, timeout: float = 10
) -> Callable[[Callable[..., _DECORATOR_RETURN]], Callable[..., Optional[list[_DECORATOR_RETURN]]]]:
) -> Callable[[Callable[..., _DecoratorReturn]], Callable[..., Optional[list[_DecoratorReturn]]]]:
"""
Decorate function will be called through the broadcast functionality.
If expect_answers is set to True, the returned value will be a list of all the answers.
"""

def impl(func: Callable[..., _DECORATOR_RETURN]) -> Callable[..., Optional[list[_DECORATOR_RETURN]]]:
def impl(func: Callable[..., _DecoratorReturn]) -> Callable[..., Optional[list[_DecoratorReturn]]]:
@functools.wraps(func)
def wrapper(**kwargs: Any) -> Optional[list[_DECORATOR_RETURN]]:
def wrapper(**kwargs: Any) -> Optional[list[_DecoratorReturn]]:
return broadcast(_channel, params=kwargs, expect_answers=expect_answers, timeout=timeout)

if channel is None:
Expand Down
3 changes: 3 additions & 0 deletions c2cwsgiutils/broadcast/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ class BaseBroadcaster:

@abstractmethod
def subscribe(self, channel: str, callback: Callable[..., Any]) -> None:
"""Subscribe to a channel."""
pass # pragma: no cover

@abstractmethod
def unsubscribe(self, channel: str) -> None:
"""Unsubscribe from a channel."""
pass # pragma: no cover

@abstractmethod
def broadcast(
self, channel: str, params: Mapping[str, Any], expect_answers: bool, timeout: float
) -> Optional[list[Any]]:
"""Broadcast a message to a channel."""
pass # pragma: no cover
1 change: 1 addition & 0 deletions c2cwsgiutils/broadcast/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def broadcast(
return answers if expect_answers else None

def get_subscribers(self) -> Mapping[str, Callable[..., Any]]:
"""Get the subscribers for testing purposes."""
return self._subscribers
3 changes: 2 additions & 1 deletion c2cwsgiutils/broadcast/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
master: "redis.client.Redis[str]",
slave: "redis.client.Redis[str]",
) -> None:
from c2cwsgiutils import redis_utils
from c2cwsgiutils import redis_utils # pylint: disable=import-outside-toplevel

self._master = master
self._slave = slave
Expand Down Expand Up @@ -121,5 +121,6 @@ def _broadcast(self, channel: str, message: Mapping[str, Any]) -> int:
return nb_received

def copy_local_subscriptions(self, prev_broadcaster: local.LocalBroadcaster) -> None:
"""Copy the subscriptions from a local broadcaster."""
for channel, callback in prev_broadcaster.get_subscribers().items():
self.subscribe(channel, callback)
1 change: 1 addition & 0 deletions c2cwsgiutils/client_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ def _handle_forwarded(environ: dict[str, str]) -> None:

def filter_factory(*args: Any, **kwargs: Any) -> Callable[..., Any]:
"""Get the filter."""
del args, kwargs # unused
return Filter
3 changes: 2 additions & 1 deletion c2cwsgiutils/coverage_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def init() -> None:

def includeme(config: Optional[pyramid.config.Configurator] = None) -> None:
"""Initialize the code coverage."""
del config # unused
if os.environ.get("COVERAGE", "0") != "1":
return
import coverage
import coverage # pylint: disable=import-outside-toplevel

LOG.warning("Setting up code coverage")
report_dir = "/tmp/coverage/api" # nosec
Expand Down
Loading

0 comments on commit 6c797a2

Please sign in to comment.