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

[wip] Use pyproject toml and enable workflow for publishing on PyPI #480

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
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
118 changes: 118 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/podman
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/podman

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
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: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export PODMAN_VERSION ?= "5.3.0"
.PHONY: podman
podman:
rm dist/* || :
$(PYTHON) -m pip install --user -r requirements.txt
$(PYTHON) -m pip install -q build
PODMAN_VERSION=$(PODMAN_VERSION) \
$(PYTHON) setup.py sdist bdist bdist_wheel
$(PYTHON) -m build

.PHONY: lint
lint: tox
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
9 changes: 2 additions & 7 deletions podman/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
)
from podman.api.tar_utils import create_tar, prepare_containerfile, prepare_containerignore

from typing import Literal

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__ = [
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
Loading
Loading