Skip to content

Commit 820e763

Browse files
authored
Merge pull request #19 from tekktrik/dev/pkg-check
Check if library is correctly identified as module/package
2 parents bba5e7e + d14ce03 commit 820e763

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ repos:
1313
- id: check-yaml
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
16+
- repo: https://github.com/python/black
17+
rev: 23.3.0
18+
hooks:
19+
- id: black
20+
- repo: https://github.com/pycqa/pylint
21+
rev: v2.17.4
22+
hooks:
23+
- id: pylint
24+
name: pylint
25+
types: [python]

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)