Skip to content

Commit f6b4373

Browse files
committed
Reorganize dynamic library architecture with dlibs/ structure
Improved organization by creating platform-specific subdirectories: - Created dlibs/ directory with platform subdirectories (windows/, macos/, linux/) - Moved all 33 Windows DLL files to dlibs/windows/ (~64MB Swift runtime) - Moved macOS .dylib file to dlibs/macos/ - Updated api.py to load libraries from new dlibs/ structure - Updated build.sh to copy libraries to appropriate platform directories - Added __init__.py to make dlibs a proper Python package Benefits: ✅ Clean separation of library files from Python source code ✅ Clear platform organization for cross-platform development ✅ Scalable architecture for future platform additions ✅ All functionality preserved - tests passing
1 parent 08da694 commit f6b4373

38 files changed

Lines changed: 33 additions & 18 deletions

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ swift build --configuration release
1010
# Detect the operating system and set the library paths
1111
if [[ "$OSTYPE" == "darwin"* ]]; then
1212
SOURCE_LIB=".build/release/libLoopAlgorithmToPython.dylib"
13-
DEST_LIB="./loop_to_python_api/libLoopAlgorithmToPython.dylib"
13+
DEST_LIB="./loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib"
1414
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
1515
SOURCE_LIB=".build/release/libLoopAlgorithmToPython.so"
16-
DEST_LIB="./loop_to_python_api/libLoopAlgorithmToPython.so"
16+
DEST_LIB="./loop_to_python_api/dlibs/linux/libLoopAlgorithmToPython.so"
1717
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
1818
SOURCE_LIB=".build/release/LoopAlgorithmToPython.dll"
19-
DEST_LIB="./loop_to_python_api/libLoopAlgorithmToPython.dll"
19+
DEST_LIB="./loop_to_python_api/dlibs/windows/libLoopAlgorithmToPython.dll"
2020
else
2121
echo "Unsupported operating system: $OSTYPE"
2222
exit 1

examples/main.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import pandas as pd
22
import loop_to_python_api.api as api
33

4-
# Read from csv file
4+
5+
# USING REAL DATA
56
# file_path = 'examples/EXAMPLE.csv'
6-
# data = pd.read_csv(file_path, parse_dates=['date'], index_col='date', low_memory=False)
7+
# df = pd.read_csv(file_path, parse_dates=['date'], index_col='date', low_memory=False)
8+
9+
# USING MOCK DATA
10+
def get_mock_data():
11+
# Generate datetime index with 5-minute intervals
12+
n_rows = 100
13+
index = pd.date_range(start="2024-02-28 00:00", periods=n_rows, freq="5min")
714

8-
# Generate datetime index with 5-minute intervals
9-
index = pd.date_range(start="2024-02-28 00:00", periods=60, freq="5T")
15+
# Create DataFrame
16+
return pd.DataFrame({
17+
"bolus": [10] + [0.0] * (n_rows - 1), # First row is 10, rest are 0
18+
"basal": [1] * n_rows, # Always 1 (U/hr)
19+
"CGM": [100] * n_rows,
20+
}, index=index)
1021

11-
# Create DataFrame
12-
df = pd.DataFrame({
13-
"bolus": [10] + [0] * 59, # First row is 10, rest are 0
14-
"basal": [1] * 60, # Always 1
15-
"CGM": 100 * 60
16-
}, index=index)
1722

18-
insulin_type = "afrezza"
23+
df = get_mock_data()
24+
insulin_type = "novolog"
1925
df = api.add_insulin_on_board_to_df(df, 1, 45, 12, insulin_type=insulin_type)
2026
df = api.add_insulin_counteraction_effect_to_df(df, 1, 45, 12, insulin_type=insulin_type)
2127

22-
print("Dataframe with iob and ice:", df)
28+
print("Dataframe with iob and ice:", df.tail())

loop_to_python_api/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
import ast
1212

1313
current_dir = os.path.dirname(os.path.abspath(__file__))
14+
dlibs_dir = os.path.join(current_dir, 'dlibs')
1415

1516
if os.name == 'posix':
1617
if os.uname().sysname == 'Darwin': # MacOS
17-
lib_path = os.path.join(current_dir, 'libLoopAlgorithmToPython.dylib')
18+
lib_path = os.path.join(dlibs_dir, 'macos', 'libLoopAlgorithmToPython.dylib')
1819
else: # Linux
19-
lib_path = os.path.join(current_dir, 'libLoopAlgorithmToPython.so')
20+
lib_path = os.path.join(dlibs_dir, 'linux', 'libLoopAlgorithmToPython.so')
2021

2122
elif os.name == 'nt': # Windows
22-
lib_path = os.path.join(current_dir, 'libLoopAlgorithmToPython.dll')
23+
lib_path = os.path.join(dlibs_dir, 'windows', 'libLoopAlgorithmToPython.dll')
2324

2425
else:
2526
raise OSError("Unsupported operating system")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Dynamic Library Directory
3+
4+
This package contains platform-specific dynamic libraries for the Loop Algorithm Python API:
5+
- windows/: Windows .dll files (Swift runtime + compiled library)
6+
- macos/: macOS .dylib files
7+
- linux/: Linux .so files
8+
"""

loop_to_python_api/libLoopAlgorithmToPython.dylib renamed to loop_to_python_api/dlibs/macos/libLoopAlgorithmToPython.dylib

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

loop_to_python_api/FoundationInternationalization.dll renamed to loop_to_python_api/dlibs/windows/FoundationInternationalization.dll

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)