Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Download spaCy model
run: python -m spacy download en_core_web_lg

- name: Lint with ruff
run: ruff check sentinelguard/

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Download spaCy model
run: python -m spacy download en_core_web_lg

- name: Run tests
run: pytest tests/ -v --tb=short

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies = [
"presidio-analyzer>=2.2.0",
"presidio-anonymizer>=2.2.0",
"spacy>=3.6.0",
"en-core-web-lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.8.0/en_core_web_lg-3.8.0-py3-none-any.whl",
# Model-based detection (HuggingFace)
"transformers>=4.30.0",
"torch>=2.0.0",
Expand Down
41 changes: 39 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
"""Backwards-compatible setup.py for sentinelguard."""
"""Setup with post-install hook to download spaCy model for Presidio PII detection."""

import subprocess
import sys
from setuptools import setup
from setuptools.command.install import install


class PostInstallCommand(install):
"""Post-installation: download spaCy model required by Presidio."""

def run(self):
install.run(self)
self._download_spacy_model()

def _download_spacy_model(self):
model = "en_core_web_lg"
print(f"🔍 Checking spaCy model: {model}")
try:
import spacy
try:
spacy.load(model)
print(f"✅ {model} — already installed")
except OSError:
print(f"⬇️ {model} — downloading...")
subprocess.check_call(
[sys.executable, "-m", "spacy", "download", model]
)
print(f"✅ {model} — installed")
except ImportError:
print("⚠️ spaCy not installed, skipping model download")
except Exception as e:
print(f"⚠️ Could not download {model}: {e}")
print(f" Run manually: python -m spacy download {model}")


if __name__ == "__main__":
setup()
setup(
cmdclass={
"install": PostInstallCommand,
},
)
Loading