-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheck_lib_packaging.py
More file actions
34 lines (28 loc) · 982 Bytes
/
check_lib_packaging.py
File metadata and controls
34 lines (28 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# SPDX-FileCopyrightText: 2023 Alec Delaney, for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Script for checking the packaging of libraries.
Author(s): Alec Delaney, for Adafruit Industries
"""
import pathlib
import sys
import tomllib
from collections.abc import Iterable
with open("pyproject.toml", mode="rb") as tomlfile:
settings = tomllib.load(tomlfile)
is_package = settings["tool"]["setuptools"].get("packages") is not None
libnames: Iterable[str] = (
settings["tool"]["setuptools"]["packages"]
if is_package
else settings["tool"]["setuptools"]["py-modules"]
)
for libname in libnames:
full_libname = libname.replace(".", "/")
library_path = pathlib.Path(full_libname)
if library_path.is_dir() != is_package:
REQUIRED_CHANGE = "package" if library_path.is_dir() else "module"
print(
f"Library {full_libname} should be specified as a {REQUIRED_CHANGE} in pyproject.toml!"
)
sys.exit(1)