Compare commits

...

3 Commits

5 changed files with 152 additions and 1 deletions

1
.gitignore vendored
View File

@ -2,7 +2,6 @@
__pycache__/
*.py[cod]
*$py.class
*.so
*.egg
*.egg-info/
dist/

83
app/ipm/README_en.md Normal file
View File

@ -0,0 +1,83 @@
# IPM native integration (app.ipm)
This folder contains the Python wrapper that calls the native refifc libraries.
Goals
- Centralize the Python wrapper under `app/ipm` so application code can import `app.ipm.simple_refrig_api`.
- Provide a clear location for native binaries (DLLs for Windows, .so for Linux).
Where to place native binaries
- Windows (local/dev): place DLL files in `app/ipm/lib/windows/`.
- Linux (container/production): place .so files in `app/ipm/lib/linux/`.
The wrapper `app/ipm/simple_refrig_api.py` will look first in `app/ipm/lib/<platform>` (`windows` or `linux`) and fall back to the package directory if nothing is found.
Do NOT commit native binaries
--------------------------------
Native binaries should not be committed to the repo (size, licensing, portability). The repo contains a `.gitignore` rule excluding `app/ipm/lib/windows/*.dll` and `app/ipm/lib/linux/*.so`.
CI/CD
- Store binaries in a secure artifact repository (releases, internal storage, S3, etc.).
- During CI, download them and copy into `app/ipm/lib/<platform>` before building the image or deploying.
Quick local test
1. Copy the binaries into the correct folder (e.g. `app/ipm/lib/windows/refifc.dll`).
2. Test locally:
```powershell
.venv\Scripts\python -c "import app.ipm.simple_refrig_api as s; r=s.Refifc('R290'); print('hsl_px exists', hasattr(r,'hsl_px'))"
```
Best practices
- Avoid committing binaries in Git.
- Record the exact origin and version of native binaries in release notes.
- Provide small helper scripts (`scripts/copy-ipm-libs.*`) to automate copying binaries into build environments.
# IPM native integration (app.ipm)
This folder contains the Python wrapper that calls the native refifc libraries.
Goals
- Centralize the Python wrapper under `app/ipm` so application code can import `app.ipm.simple_refrig_api`.
- Provide a clear location for native binaries (DLLs for Windows, .so for Linux).
Where to place native binaries
- Windows (local/dev): place DLL files in `app/ipm/lib/windows/`.
- Linux (container/production): place .so files in `app/ipm/lib/linux/`.
The wrapper `app/ipm/simple_refrig_api.py` will look first in `app/ipm/lib/<platform>` (`windows` or `linux`) and fall back to the package directory if nothing is found.
Do NOT commit native binaries
--------------------------------
Native binaries should not be committed to the repo (size, licensing, portability). The repo contains a `.gitignore` rule excluding `app/ipm/lib/windows/*.dll` and `app/ipm/lib/linux/*.so`.
Deployment / Docker
- The Dockerfile should copy the appropriate native binaries into `app/ipm/lib/<platform>` during the build. Example (Linux image):
```Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY . /app
# Copy native linux libs into the package
COPY path/to/linlibs/*.so /app/app/ipm/lib/linux/
RUN pip install --no-cache-dir -r requirements.txt
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
```
CI/CD
- Store binaries in a secure artifact repository (releases, internal storage, S3, etc.).
- During CI, download them and copy into `app/ipm/lib/<platform>` before building the image or deploying.
Quick local test
1. Copy the binaries into the correct folder (e.g. `app/ipm/lib/windows/refifc.dll`).
2. Test locally:
```powershell
.venv\Scripts\python -c "import app.ipm.simple_refrig_api as s; r=s.Refifc('R290'); print('hsl_px exists', hasattr(r,'hsl_px'))"
```
Best practices
- Avoid committing binaries in Git.
- Record the exact origin and version of native binaries in release notes.
- Provide small helper scripts (`scripts/copy-ipm-libs.*`) to automate copying binaries into build environments.

34
app/ipm/README_fr.md Normal file
View File

@ -0,0 +1,34 @@
# Intégration IPM native (app.ipm)
Ce dossier contient le wrapper Python qui appelle les bibliothèques natives (refifc).
Objectifs
- Centraliser le wrapper Python dans `app/ipm` pour que le code applicatif importe depuis `app.ipm.simple_refrig_api`.
- Fournir un emplacement clair pour les binaires natifs (DLL pour Windows, .so pour Linux).
Où placer les binaires
- Windows (local/dev) : placez vos DLL dans `app/ipm/lib/windows/`.
- Linux (container/production) : placez vos .so dans `app/ipm/lib/linux/`.
Le wrapper `app/ipm/simple_refrig_api.py` recherche automatiquement, en priorité, le répertoire `app/ipm/lib/<platform>` (`windows` ou `linux`) puis retombe sur le répertoire du package s'il ne trouve rien.
Ne pas committer les binaires
--------------------------------
Les fichiers natifs ne doivent pas être committés dans Git (poids, licence, portabilité). Le dépôt inclut une règle `.gitignore` qui exclut `app/ipm/lib/windows/*.dll` et `app/ipm/lib/linux/*.so`.
CI/CD
- Stockez les binaires dans un artefact sécurisé (release, storage interne, S3, etc.).
- Lors du pipeline, téléchargez-les et copiez-les dans `app/ipm/lib/<platform>` avant l'étape de build ou de déploiement.
Test rapide local
1. Copier les binaires dans le bon dossier (ex. `app/ipm/lib/windows/refifc.dll`).
2. Tester en local :
```powershell
.venv\Scripts\python -c "import app.ipm.simple_refrig_api as s; r=s.Refifc('R290'); print('hsl_px exists', hasattr(r,'hsl_px'))"
```
Bonnes pratiques
- Ne stockez pas les binaires dans Git.
- Documentez la provenance et la version des fichiers natifs dans vos notes de release.
- Préparez un script `scripts/copy-ipm-libs.*` pour automatiser la copie des binaires dans les environnements de build.

21
scripts/copy-ipm-libs.ps1 Normal file
View File

@ -0,0 +1,21 @@
param(
[string]$SourceDir = "C:\ipm_binaries",
[switch]$Force
)
# Copies Windows DLLs from SourceDir to app/ipm/lib/windows.
$dest = Resolve-Path -Path "..\app\ipm\lib\windows"
if (-not (Test-Path $dest)) { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
Write-Host "Copying DLLs from $SourceDir to $dest"
Get-ChildItem -Path $SourceDir -Filter *.dll -File -ErrorAction SilentlyContinue | ForEach-Object {
$dst = Join-Path $dest $_.Name
if (Test-Path $dst -and -not $Force) {
Write-Host "Skipping existing: $($_.Name)"
} else {
Copy-Item $_.FullName -Destination $dst -Force
Write-Host "Copied: $($_.Name)"
}
}
Write-Host "Done."

14
scripts/copy-ipm-libs.sh Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
SOURCE_DIR=${1:-/opt/ipm_binaries}
DEST_DIR="$(dirname "$0")/../app/ipm/lib/linux"
mkdir -p "$DEST_DIR"
echo "Copying .so files from $SOURCE_DIR to $DEST_DIR"
shopt -s nullglob
for f in "$SOURCE_DIR"/*.so; do
echo "Copying $(basename "$f")"
cp -f "$f" "$DEST_DIR/"
done
echo "Done."