Skip to content

Commit 5cb6f2f

Browse files
committed
Fix pylinting
1 parent 7de118b commit 5cb6f2f

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

setup.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
"""
2+
Setup script for DSF Python bindings
3+
This script uses setuptools to build the C++ core of DSF with Python bindings
4+
using pybind11 and CMake.
5+
It extracts the version from the C++ header file and configures the build
6+
process accordingly.
7+
"""
8+
19
import os
2-
import sys
10+
from pathlib import Path
311
import platform
4-
import subprocess
512
import re
13+
import sys
14+
import subprocess
15+
616
from setuptools import setup, Extension
717
from setuptools.command.build_ext import build_ext
8-
from pathlib import Path
918

1019

1120
def get_version_from_header():
1221
"""Extract version from C++ header file"""
1322
header_path = Path(__file__).parent / "src" / "dsf" / "dsf.hpp"
1423
try:
15-
with open(header_path, "r") as f:
16-
content = f.read()
24+
with open(header_path, "r", encoding="UTF-8") as header_file:
25+
content = header_file.read()
1726

1827
major_match = re.search(r"DSF_VERSION_MAJOR = (\d+)", content)
1928
minor_match = re.search(r"DSF_VERSION_MINOR = (\d+)", content)
@@ -23,25 +32,30 @@ def get_version_from_header():
2332
return (
2433
f"{major_match.group(1)}.{minor_match.group(1)}.{patch_match.group(1)}"
2534
)
26-
else:
27-
return "unknown"
35+
return "unknown"
2836
except (FileNotFoundError, AttributeError):
2937
# Fallback version if header can't be read
3038
return "unknown"
3139

3240

33-
class CMakeExtension(Extension):
41+
class CMakeExtension(Extension): # pylint: disable=too-few-public-methods
42+
"""Custom CMake extension class for setuptools"""
43+
3444
def __init__(self, name: str, sourcedir: str = ""):
3545
super().__init__(name, sources=[])
3646
self.sourcedir = os.path.abspath(sourcedir)
3747

3848

3949
class CMakeBuild(build_ext):
50+
"""Custom build_ext command to handle CMake extensions"""
51+
4052
def run(self):
4153
try:
4254
subprocess.check_output(["cmake", "--version"])
43-
except OSError:
44-
raise RuntimeError("CMake must be installed to build the extensions")
55+
except OSError as exc:
56+
raise RuntimeError(
57+
"CMake must be installed to build the extensions"
58+
) from exc
4559

4660
for ext in self.extensions:
4761
self.build_extension(ext)
@@ -81,22 +95,22 @@ def build_extension(self, ext: CMakeExtension):
8195

8296

8397
# Read long description from README.md if available
84-
long_description = ""
98+
LONG_DESCRIPTION = ""
8599
if os.path.exists("README.md"):
86100
with open("README.md", "r", encoding="utf-8") as f:
87-
long_description = f.read()
101+
LONG_DESCRIPTION = f.read()
88102

89103
# Get version from header file
90104
project_version = get_version_from_header()
91105

92-
if long_description:
106+
if LONG_DESCRIPTION:
93107
setup(
94108
name="dsf",
95109
version=project_version,
96110
author="Grufoony",
97111
author_email="gregorio.berselli@studio.unibo.it",
98112
description="DSF C++ core with Python bindings via pybind11",
99-
long_description=long_description,
113+
long_description=LONG_DESCRIPTION,
100114
long_description_content_type="text/markdown",
101115
ext_modules=[CMakeExtension("dsf")],
102116
cmdclass={"build_ext": CMakeBuild},

0 commit comments

Comments
 (0)