From: Vincent Fazio <vfazio@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Vincent Fazio <vfazio@gmail.com>
Subject: [libgpiod][PATCH 3/9] bindings: python: setup: add type annotations
Date: Tue, 31 Mar 2026 19:14:52 -0500 [thread overview]
Message-ID: <20260401001459.19159-3-vfazio@gmail.com> (raw)
In-Reply-To: <20260401001459.19159-1-vfazio@gmail.com>
Add type annotations to help with lint checks.
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
bindings/python/setup.py | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index 7bf9246..4061328 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -1,8 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
+from collections.abc import Callable
from os import getenv, path, unlink
from shutil import copy, copytree, rmtree
+from typing import TypeVar
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext as orig_build_ext
@@ -10,6 +12,8 @@ from setuptools.command.sdist import log
from setuptools.command.sdist import sdist as orig_sdist
from setuptools.errors import BaseError
+T = TypeVar("T", "sdist", "build_ext")
+
LINK_SYSTEM_LIBGPIOD = getenv("LINK_SYSTEM_LIBGPIOD") == "1"
LIBGPIOD_MINIMUM_VERSION = "2.1"
LIBGPIOD_VERSION = getenv("LIBGPIOD_VERSION")
@@ -20,7 +24,7 @@ SHA256_CHUNK_SIZE = 2048
LICENSE_FILE = "LICENSE"
-def sha256(filename):
+def sha256(filename: str) -> str:
"""
Return a sha256sum for a specific filename, loading the file in chunks
to avoid potentially excessive memory use.
@@ -35,7 +39,7 @@ def sha256(filename):
return sha256sum.hexdigest()
-def find_sha256sum(asc_file, tar_filename):
+def find_sha256sum(asc_file: str, tar_filename: str) -> str:
"""
Search through a local copy of sha256sums.asc for a specific filename
and return the associated sha256 sum.
@@ -49,7 +53,7 @@ def find_sha256sum(asc_file, tar_filename):
raise BaseError(f"no signature found for {tar_filename}")
-def fetch_tarball(command):
+def fetch_tarball(func: Callable[[T], None]) -> Callable[[T], None]:
"""
Verify the requested LIBGPIOD_VERSION tarball exists in sha256sums.asc,
fetch it from https://mirrors.edge.kernel.org/pub/software/libs/libgpiod/
@@ -61,10 +65,10 @@ def fetch_tarball(command):
# If no LIBGPIOD_VERSION is specified in env, just run the command
if LIBGPIOD_VERSION is None:
- return command
+ return func
# If LIBGPIOD_VERSION is specified, apply the tarball wrapper
- def wrapper(self):
+ def wrapper(cmd: T) -> None:
# Just-in-time import of tarfile and urllib.request so these are
# not required for Yocto to build a vendored or linked package
import sys
@@ -83,7 +87,7 @@ def fetch_tarball(command):
try:
if open("libgpiod-version.txt", "r").read() == LIBGPIOD_VERSION:
log.info(f"skipping tarball fetch")
- command(self)
+ func(cmd)
return
except OSError:
pass
@@ -175,13 +179,13 @@ def fetch_tarball(command):
# For further details, see `egg_info.find_sources` and
# `manifest_maker.add_license_files`
copy(_path, LICENSE_FILE)
- self.distribution.metadata.license_files = [LICENSE_FILE]
+ cmd.distribution.metadata.license_files = [LICENSE_FILE] # type: ignore[attr-defined]
# Save the libgpiod version for sdist
open("libgpiod-version.txt", "w").write(LIBGPIOD_VERSION)
# Run the command
- command(self)
+ func(cmd)
# Clean up the build directory
if path.exists(LICENSE_FILE):
@@ -206,8 +210,9 @@ class build_ext(orig_build_ext):
"""
@fetch_tarball
- def run(self):
+ def run(self) -> None:
# Try to get the gpiod version from the .txt file included in sdist
+ libgpiod_version: str | None
try:
libgpiod_version = open("libgpiod-version.txt", "r").read()
except OSError:
@@ -251,7 +256,7 @@ class sdist(orig_sdist):
"""
@fetch_tarball
- def run(self):
+ def run(self) -> None:
super().run()
--
2.43.0
next prev parent reply other threads:[~2026-04-01 0:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 0:14 [libgpiod][PATCH 1/9] bindings: python: build_tests: do not fallback to distutils Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 2/9] bindings: python: build_tests: simplify the Distribution Vincent Fazio
2026-04-01 0:14 ` Vincent Fazio [this message]
2026-04-01 0:14 ` [libgpiod][PATCH 4/9] bindings: python: setup: apply linter recommendations Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 5/9] bindings: python: setup: use logging module Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 6/9] bindings: python: examples: add type annotations Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 7/9] bindings: python: examples: apply linter recommendations Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 8/9] bindings: python: add a lint dependency group Vincent Fazio
2026-04-01 0:14 ` [libgpiod][PATCH 9/9] bindings: python: update linter configuration Vincent Fazio
2026-04-02 14:37 ` Bartosz Golaszewski
2026-04-02 15:55 ` Vincent Fazio
2026-04-02 16:42 ` Bartosz Golaszewski
2026-04-02 17:01 ` Vincent Fazio
2026-04-03 9:02 ` Bartosz Golaszewski
2026-04-03 13:09 ` Vincent Fazio
2026-04-03 9:01 ` [libgpiod][PATCH 1/9] bindings: python: build_tests: do not fallback to distutils Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260401001459.19159-3-vfazio@gmail.com \
--to=vfazio@gmail.com \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.