Skip to content

Commit b5a74a4

Browse files
committed
Add script for checking library packaging
1 parent bba5e7e commit b5a74a4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

check_lib_packaging.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2023 Alec Delaney, for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Script for checking the packaging of libraries.
7+
8+
Author(s): Alec Delaney, for Adafruit Industries
9+
"""
10+
11+
import pathlib
12+
import sys
13+
import tomllib
14+
from collections.abc import Iterable
15+
16+
with open("pyproject.toml", mode="rb") as tomlfile:
17+
settings = tomllib.load(tomlfile)
18+
19+
is_package = settings["tool"]["setuptools"].get("packages") is not None
20+
libnames: Iterable[str] = (
21+
settings["tool"]["setuptools"]["packages"]
22+
if is_package
23+
else settings["tool"]["setuptools"]["py-modules"]
24+
)
25+
26+
for libname in libnames:
27+
library_path = pathlib.Path(libname)
28+
if library_path.is_dir() != is_package:
29+
REQUIRED_CHANGE = "package" if library_path.is_dir() else "module"
30+
print(
31+
f"Library {libname} should be specified as a {REQUIRED_CHANGE} in pyproject.toml!"
32+
)
33+
sys.exit(1)

0 commit comments

Comments
 (0)