Skip to content

Commit 6f32169

Browse files
fix: clean up setup.py
1 parent 7b555f9 commit 6f32169

File tree

2 files changed

+24
-224
lines changed

2 files changed

+24
-224
lines changed

sciencemode/sciencemode.cdef

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#define SMPT_DL_GUID_STRING_LENGTH ...
21
#define SMPT_DL_MAX_FILE_ID_LENGTH ...
3-
#define SMPT_DL_MAX_N_MEASUREMENTS ...
4-
#define SMPT_DL_MAX_FILE_NAME_LENGTH ...
5-
#define SMPT_DL_MAX_BLOCK_BYTES_LENGTH ...
6-
#define SMPT_DL_MAX_SAMPLE_VALUE ...
72
#define SMPT_DL_MAX_INVESTIGATOR_NAME_LENGTH ...
8-
#define SMPT_DL_FILE_SIZE_BYTES ...
93
#define SMPT_DL_MAX_CHANNELS ...
104
#define SMPT_DL_MAX_STRING_LENGTH ...
11-
#define SMPT_DL_4KHZ 4000
12-
13-
#define SMPT_DL_1KHZ ...
5+
#define SMPT_DL_GUID_STRING_LENGTH ...
146
#define SMPT_DL_2KHZ 2000
157

8+
#define SMPT_DL_1KHZ ...
9+
#define SMPT_DL_FILE_SIZE_BYTES ...
10+
#define SMPT_DL_MAX_BLOCK_BYTES_LENGTH ...
11+
#define SMPT_DL_MAX_FILE_NAME_LENGTH ...
1612
#define SMPT_DL_MAX_PATIENT_NAME_LENGTH ...
13+
#define SMPT_DL_MAX_N_MEASUREMENTS ...
14+
#define SMPT_DL_MAX_SAMPLE_VALUE ...
15+
#define SMPT_DL_4KHZ 4000
16+
1717
typedef enum
1818
{
1919
Smpt_Cmd_Ll_Init = ...,

setup.py

Lines changed: 15 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import sys
77

8-
from setuptools import Command, Extension, setup
8+
from setuptools import Command, setup
99

1010
VERSION = "1.0.0"
1111

@@ -46,100 +46,6 @@ def get_config():
4646
}
4747

4848

49-
class CMakeExtension(Extension):
50-
"""Extension class for CMake-based extensions."""
51-
52-
def __init__(self, name, sourcedir=""):
53-
Extension.__init__(self, name, sources=[])
54-
self.sourcedir = os.path.abspath(sourcedir)
55-
56-
57-
class BuildCFFIModuleCommand(Command):
58-
"""Custom command to build the CFFI module explicitly."""
59-
60-
description = "Build the CFFI module directly"
61-
user_options = [
62-
("build-type=", None, "Specify the CMake build type (Debug/Release)"),
63-
]
64-
65-
def initialize_options(self):
66-
self.build_type = "Release"
67-
68-
def finalize_options(self):
69-
if self.build_type not in ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"]:
70-
print(
71-
f"Warning: Unknown build type '{self.build_type}', "
72-
"defaulting to 'Release'"
73-
)
74-
self.build_type = "Release"
75-
76-
def run(self):
77-
"""Build the CFFI module directly using Python's subprocess."""
78-
print("=" * 80)
79-
print(f"Building CFFI module directly (Build type: {self.build_type})")
80-
print("=" * 80)
81-
82-
# Get the CFFI module path
83-
cffi_path = os.path.join(os.getcwd(), "sciencemode", "_cffi.py")
84-
if not os.path.exists(cffi_path):
85-
print(f"Error: CFFI module file {cffi_path} not found!")
86-
return
87-
88-
# Make sure the sciencemode package is importable
89-
sys.path.insert(0, os.path.dirname(os.getcwd()))
90-
91-
# Set environment variable for build type
92-
os.environ["CMAKE_BUILD_TYPE"] = self.build_type
93-
94-
try:
95-
# Run the CFFI module directly to build the extension
96-
print(f"Running {sys.executable} {cffi_path}")
97-
result = subprocess.run(
98-
[sys.executable, cffi_path],
99-
cwd=os.path.dirname(cffi_path),
100-
check=True,
101-
capture_output=True,
102-
text=True,
103-
)
104-
print("Output:")
105-
print(result.stdout)
106-
107-
if result.stderr:
108-
print("Errors:")
109-
print(result.stderr)
110-
111-
# Check if the module was created
112-
extension_name = "_sciencemode"
113-
if platform.system() == "Windows":
114-
ext_pattern = f"{extension_name}*.pyd"
115-
else:
116-
ext_pattern = f"{extension_name}*.so"
117-
118-
extensions = glob.glob(
119-
os.path.join(os.path.dirname(cffi_path), ext_pattern)
120-
)
121-
if extensions:
122-
print(
123-
f"Success! CFFI extension module(s) built: {', '.join(extensions)}"
124-
)
125-
else:
126-
print("Warning: No extension module files found after build.")
127-
print(
128-
"The build might have failed or saved the "
129-
"file in a different location."
130-
)
131-
132-
except subprocess.CalledProcessError as e:
133-
print(f"Error building CFFI module: {e}")
134-
if hasattr(e, "stdout") and e.stdout:
135-
print("Output:")
136-
print(e.stdout)
137-
if hasattr(e, "stderr") and e.stderr:
138-
print("Error details:")
139-
print(e.stderr)
140-
raise RuntimeError("CFFI module build failed!") from e
141-
142-
14349
class BuildLibraryCommand(Command):
14450
"""Custom command to build just the SMPT C library."""
14551

@@ -285,34 +191,18 @@ def run(self): # noqa: C901
285191
print(f"Found the following SMPT libraries in {lib_dir}:")
286192
for lib in found_libs:
287193
print(f" - {os.path.basename(lib)}")
288-
print("\nSuccess! The SMPT library has been built and installed.")
194+
print("\\nSuccess! The SMPT library has been built and installed.")
289195
else:
290196
print(f"Warning: No SMPT libraries found in {lib_dir}")
291197
print("The library build may have failed. Check the CMake output.")
292198
else:
293199
print("*" * 80)
294-
295-
print(
296-
"WARNING: No libraries found to copy. "
297-
"The library may not have been built properly."
298-
)
299-
print("Check build_temp directory for build artifacts.")
300-
print("*" * 80)
301-
302-
303-
# Package data setup
304-
# Package data setup - include headers and libraries
305-
package_data = {
306-
"sciencemode": [
307-
"*.dll",
308-
"*.so",
309-
"*.so.*",
310-
"*.dylib",
311-
"*.a",
312-
"*.lib", # Libraries
313-
"include/**/*.h", # Headers (recursive)
314-
]
315-
}
200+
print(
201+
"WARNING: No libraries found to copy. "
202+
"The library may not have been built properly."
203+
)
204+
print("Check build_temp directory for build artifacts.")
205+
print("*" * 80)
316206

317207

318208
def create_symlinks(directory, source, targets):
@@ -463,7 +353,7 @@ def copy_headers_to_package():
463353
print(f"Warning: Could not copy headers to package: {e}")
464354

465355

466-
# Package data setup - include headers and libraries
356+
# Package data setup - include headers, libraries, and static CFFI definitions
467357
package_data = {
468358
"sciencemode": [
469359
"*.dll",
@@ -472,50 +362,12 @@ def copy_headers_to_package():
472362
"*.dylib",
473363
"*.a",
474364
"*.lib", # Libraries
365+
"*.cdef", # Static CFFI definitions
475366
"include/**/*.h", # Headers (recursive)
476367
]
477368
}
478369

479370

480-
def check_cffi_prerequisites():
481-
"""Check that all required CFFI files exist and libraries can be found."""
482-
cffi_path = os.path.join("sciencemode", "_cffi.py")
483-
if not os.path.exists(cffi_path):
484-
print(f"Warning: {cffi_path} not found. CFFI module may not build correctly.")
485-
return False
486-
487-
# Check for library files
488-
lib_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib")
489-
if not os.path.exists(lib_dir):
490-
print(
491-
f"Warning: Library directory {lib_dir} not found. "
492-
"Libraries may not be available."
493-
)
494-
return False
495-
496-
platform_config = PlatformConfig.get_config()
497-
lib_found = False
498-
499-
for pattern in platform_config["lib_patterns"]:
500-
libs = glob.glob(os.path.join(lib_dir, pattern))
501-
if libs:
502-
lib_found = True
503-
print(
504-
f"Found library files: "
505-
f"{', '.join(os.path.basename(lib) for lib in libs)}"
506-
)
507-
break
508-
509-
if not lib_found:
510-
print(
511-
f"Warning: No libraries found in {lib_dir}. "
512-
"CFFI module may not build correctly."
513-
)
514-
return False
515-
516-
return True
517-
518-
519371
# Determine if we're just building the library or doing a full install
520372
if "build_lib" in sys.argv:
521373
# Simple setup just for building the library
@@ -528,64 +380,14 @@ def check_cffi_prerequisites():
528380
},
529381
)
530382
else:
531-
# Check CFFI prerequisites before proceeding
532-
cffi_ready = check_cffi_prerequisites()
533-
534-
# Full setup with CFFI for normal installation
535-
try:
536-
# First try to build the CFFI module directly if we're on Windows
537-
if platform.system() == "Windows":
538-
try:
539-
# Build the module directly without using the Command class
540-
cffi_path = os.path.join(os.getcwd(), "sciencemode", "_cffi.py")
541-
if os.path.exists(cffi_path):
542-
print("Building CFFI module directly for Windows...")
543-
result = subprocess.run(
544-
[sys.executable, cffi_path],
545-
cwd=os.path.dirname(cffi_path),
546-
check=True,
547-
capture_output=True,
548-
text=True,
549-
)
550-
print("Direct CFFI build result:")
551-
print(result.stdout)
552-
if result.stderr:
553-
print("Errors:")
554-
print(result.stderr)
555-
556-
# Since we've already built the module directly,
557-
# we don't need to use cffi_modules
558-
cffi_modules_list = []
559-
else:
560-
print(f"Warning: CFFI module file {cffi_path} not found!")
561-
cffi_modules_list = (
562-
[os.sep.join(["sciencemode", "_cffi.py:ffi"])]
563-
if cffi_ready
564-
else []
565-
)
566-
except Exception as e:
567-
print(f"Direct CFFI build failed: {e}")
568-
cffi_modules_list = (
569-
[os.sep.join(["sciencemode", "_cffi.py:ffi"])] if cffi_ready else []
570-
)
571-
else:
572-
# On non-Windows platforms, use the standard cffi_modules approach
573-
cffi_modules_list = (
574-
[os.sep.join(["sciencemode", "_cffi.py:ffi"])] if cffi_ready else []
575-
)
576-
except Exception as e:
577-
print(f"Warning: Direct CFFI module build failed: {e}")
578-
print("Falling back to standard cffi_modules approach")
579-
cffi_modules_list = (
580-
[os.sep.join(["sciencemode", "_cffi.py:ffi"])] if cffi_ready else []
581-
)
582-
383+
# Full setup for normal installation using static CFFI definitions
384+
# Note: cffi_modules is removed since we now use static definitions
583385
setup(
584386
name="sciencemode-cffi",
585387
packages=["sciencemode"],
586388
package_data=package_data,
587389
version=VERSION,
588-
description="CFFI wrapper for SCIENCEMODE",
390+
description="CFFI wrapper for SCIENCEMODE using static definitions",
589391
author="Holger Nahrstaedt",
590392
author_email="holger.nahrstaedt@hasomed.de",
591393
license="MIT",
@@ -595,13 +397,11 @@ def check_cffi_prerequisites():
595397
"Development Status :: 3 - Alpha",
596398
"Programming Language :: Python :: 3",
597399
],
598-
setup_requires=["cffi>=1.0.0", "pycparser>=2.14"],
599-
cffi_modules=cffi_modules_list,
400+
# Only cffi is required at runtime now (no pycparser needed)
600401
install_requires=["cffi>=1.0.0"],
601402
cmdclass={
602403
"build_lib": BuildLibraryCommand,
603-
"build_cffi": BuildCFFIModuleCommand,
604404
},
605-
# Make sure library is included in the package
405+
# Make sure library and static definitions are included in the package
606406
include_package_data=True,
607407
)

0 commit comments

Comments
 (0)