Skip to content
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

Enable many ruff checks #476

Open
wants to merge 20 commits into
base: main
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.0
rev: v0.8.1
hooks:
# Run the linter.
- id: ruff
Expand Down
4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ class PatchedPythonDomain(PythonDomain):
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
if 'refspecific' in node:
del node['refspecific']
return super(PatchedPythonDomain, self).resolve_xref(
env, fromdocname, builder, typ, target, node, contnode
)
return super().resolve_xref(env, fromdocname, builder, typ, target, node, contnode)


def skip(app, what, name, obj, would_skip, options):
Expand Down
4 changes: 0 additions & 4 deletions podman/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Podman client module."""

import sys

assert sys.version_info >= (3, 6), "Python 3.6 or greater is required."

from podman.client import PodmanClient, from_env
from podman.version import __version__

Expand Down
8 changes: 0 additions & 8 deletions podman/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,12 @@

DEFAULT_CHUNK_SIZE = 2 * 1024 * 1024

try:
from typing import Literal
except (ImportError, ModuleNotFoundError):
try:
from typing_extensions import Literal
except (ImportError, ModuleNotFoundError):
from podman.api.typing_extensions import Literal # pylint: disable=ungrouped-imports

# isort: unique-list
__all__ = [
'APIClient',
'COMPATIBLE_VERSION',
'DEFAULT_CHUNK_SIZE',
'Literal',
'VERSION',
'cached_property',
'create_tar',
Expand Down
3 changes: 2 additions & 1 deletion podman/api/adapter_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utility functions for working with Adapters."""

from typing import NamedTuple, Mapping
from typing import NamedTuple
from collections.abc import Mapping


def _key_normalizer(key_class: NamedTuple, request_context: Mapping) -> Mapping:
Expand Down
21 changes: 14 additions & 7 deletions podman/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import json
import warnings
import urllib.parse
from typing import Any, ClassVar, IO, Iterable, List, Mapping, Optional, Tuple, Type, Union
from typing import (
Any,
ClassVar,
IO,
Optional,
Union,
)
from collections.abc import Iterable, Mapping

import requests
from requests.adapters import HTTPAdapter
Expand All @@ -20,12 +27,12 @@
str,
bytes,
Mapping[str, Any],
Iterable[Tuple[str, Optional[str]]],
Iterable[tuple[str, Optional[str]]],
IO,
]
"""Type alias for request data parameter."""

_Timeout = Union[None, float, Tuple[float, float], Tuple[float, None]]
_Timeout = Union[None, float, tuple[float, float], tuple[float, None]]
"""Type alias for request timeout parameter."""


Expand Down Expand Up @@ -58,7 +65,7 @@ def __getattr__(self, item: str):
"""Forward any query for an attribute not defined in this proxy class to wrapped class."""
return getattr(self._response, item)

def raise_for_status(self, not_found: Type[APIError] = NotFound) -> None:
def raise_for_status(self, not_found: type[APIError] = NotFound) -> None:
"""Raises exception when Podman service reports one."""
if self.status_code < 400:
return
Expand All @@ -81,7 +88,7 @@ class APIClient(requests.Session):
# Abstract methods (delete,get,head,post) are specialized and pylint cannot walk hierarchy.
# pylint: disable=too-many-instance-attributes,arguments-differ,arguments-renamed

supported_schemes: ClassVar[List[str]] = (
supported_schemes: ClassVar[list[str]] = (
"unix",
"http+unix",
"ssh",
Expand Down Expand Up @@ -156,7 +163,7 @@ def __init__(
self.mount("http://", HTTPAdapter(**http_adapter_kwargs))
self.mount("https://", HTTPAdapter(**http_adapter_kwargs))
else:
assert False, "APIClient.supported_schemes changed without adding a branch here."
raise PodmanError("APIClient.supported_schemes changed without adding a branch here.")

self.version = version or VERSION
self.path_prefix = f"/v{self.version}/libpod/"
Expand Down Expand Up @@ -235,7 +242,7 @@ def get(
self,
path: Union[str, bytes],
*,
params: Union[None, bytes, Mapping[str, List[str]]] = None,
params: Union[None, bytes, Mapping[str, list[str]]] = None,
headers: Optional[Mapping[str, str]] = None,
timeout: _Timeout = None,
stream: Optional[bool] = False,
Expand Down
21 changes: 11 additions & 10 deletions podman/api/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import base64
import collections.abc
import json
from typing import Dict, List, Mapping, Optional, Union, Any
from typing import Optional, Union, Any
from collections.abc import Mapping


def prepare_filters(filters: Union[str, List[str], Mapping[str, str]]) -> Optional[str]:
"""Return filters as an URL quoted JSON Dict[str, List[Any]]."""
def prepare_filters(filters: Union[str, list[str], Mapping[str, str]]) -> Optional[str]:
"""Return filters as an URL quoted JSON dict[str, list[Any]]."""

if filters is None or len(filters) == 0:
return None

criteria: Dict[str, List[str]] = {}
criteria: dict[str, list[str]] = {}
if isinstance(filters, str):
_format_string(filters, criteria)
elif isinstance(filters, collections.abc.Mapping):
Expand Down Expand Up @@ -42,12 +43,12 @@ def _format_dict(filters, criteria):
for key, value in filters.items():
if value is None:
continue
value = str(value)
str_value = str(value)

if key in criteria:
criteria[key].append(value)
criteria[key].append(str_value)
else:
criteria[key] = [value]
criteria[key] = [str_value]


def _format_string(filters, criteria):
Expand All @@ -67,7 +68,7 @@ def prepare_body(body: Mapping[str, Any]) -> str:
return json.dumps(body, sort_keys=True)


def _filter_values(mapping: Mapping[str, Any], recursion=False) -> Dict[str, Any]:
def _filter_values(mapping: Mapping[str, Any], recursion=False) -> dict[str, Any]:
"""Returns a canonical dictionary with values == None or empty Iterables removed.

Dictionary is walked using recursion.
Expand All @@ -91,13 +92,13 @@ def _filter_values(mapping: Mapping[str, Any], recursion=False) -> Dict[str, Any
else:
proposal = value

if not recursion and proposal not in (None, str(), [], {}):
if not recursion and proposal not in (None, "", [], {}):
canonical[key] = proposal
elif recursion and proposal not in (None, [], {}):
canonical[key] = proposal

return canonical


def encode_auth_header(auth_config: Dict[str, str]) -> str:
def encode_auth_header(auth_config: dict[str, str]) -> str:
return base64.urlsafe_b64encode(json.dumps(auth_config).encode('utf-8'))
11 changes: 6 additions & 5 deletions podman/api/parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import json
import struct
from datetime import datetime
from typing import Any, Dict, Iterator, Optional, Tuple, Union
from typing import Any, Optional, Union
from collections.abc import Iterator

from requests import Response
from .output_utils import demux_output


def parse_repository(name: str) -> Tuple[str, Optional[str]]:
def parse_repository(name: str) -> tuple[str, Optional[str]]:
"""Parse repository image name from tag or digest

Returns:
Expand All @@ -31,7 +32,7 @@ def parse_repository(name: str) -> Tuple[str, Optional[str]]:
return name, None


def decode_header(value: Optional[str]) -> Dict[str, Any]:
def decode_header(value: Optional[str]) -> dict[str, Any]:
"""Decode a base64 JSON header value."""
if value is None:
return {}
Expand Down Expand Up @@ -82,7 +83,7 @@ def frames(response: Response) -> Iterator[bytes]:

def stream_frames(
response: Response, demux: bool = False
) -> Iterator[Union[bytes, Tuple[bytes, bytes]]]:
) -> Iterator[Union[bytes, tuple[bytes, bytes]]]:
"""Returns each frame from multiplexed streamed payload.

If ``demux`` then output will be tuples where the first position is ``STDOUT`` and the second
Expand All @@ -109,7 +110,7 @@ def stream_frames(

def stream_helper(
response: Response, decode_to_json: bool = False
) -> Union[Iterator[bytes], Iterator[Dict[str, Any]]]:
) -> Union[Iterator[bytes], Iterator[dict[str, Any]]]:
"""Helper to stream results and optionally decode to json"""
for value in response.iter_lines():
if decode_to_json:
Expand Down
10 changes: 5 additions & 5 deletions podman/api/tar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import tarfile
import tempfile
from fnmatch import fnmatch
from typing import BinaryIO, List, Optional
from typing import BinaryIO, Optional

import sys


def prepare_containerignore(anchor: str) -> List[str]:
def prepare_containerignore(anchor: str) -> list[str]:
"""Return the list of patterns for filenames to exclude.

.containerignore takes precedence over .dockerignore.
Expand All @@ -24,7 +24,7 @@ def prepare_containerignore(anchor: str) -> List[str]:
with ignore.open(encoding='utf-8') as file:
return list(
filter(
lambda l: l and not l.startswith("#"),
lambda L: L and not L.startswith("#"),
(line.strip() for line in file.readlines()),
)
)
Expand Down Expand Up @@ -53,7 +53,7 @@ def prepare_containerfile(anchor: str, dockerfile: str) -> str:


def create_tar(
anchor: str, name: str = None, exclude: List[str] = None, gzip: bool = False
anchor: str, name: str = None, exclude: list[str] = None, gzip: bool = False
) -> BinaryIO:
"""Create a tarfile from context_dir to send to Podman service.

Expand Down Expand Up @@ -119,7 +119,7 @@ def add_filter(info: tarfile.TarInfo) -> Optional[tarfile.TarInfo]:
return open(name.name, "rb") # pylint: disable=consider-using-with


def _exclude_matcher(path: str, exclude: List[str]) -> bool:
def _exclude_matcher(path: str, exclude: list[str]) -> bool:
"""Returns True if path matches an entry in exclude.

Note:
Expand Down
Loading
Loading