Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add numpy dependency and environment validation #667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions docs/Installation/INSTALLATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Installation Guide

## Prerequisites
- Python 3.8 or higher
- pip (Python package installer)

## Installation Steps

1. Clone the repository:
```bash
git clone https://github.com/stitionai/devika.git
cd devika
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

## Common Issues

### Missing numpy dependency
If you encounter an error about numpy not being available, install it explicitly:
```bash
pip install numpy>=1.24.0
```

## Troubleshooting
If you encounter any installation issues:
1. Ensure you have Python 3.8 or higher installed
2. Try upgrading pip: `pip install --upgrade pip`
3. Install numpy explicitly if needed: `pip install numpy>=1.24.0`
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = ["setuptools>=42.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
addopts = "-v"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy>=1.24.0
flask
flask-cors
toml
Expand Down
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup, find_packages

setup(
name="devika",
version="0.1.0",
packages=find_packages(),
install_requires=[
"numpy>=1.24.0",
"requests>=2.25.1",
"pytest>=6.0.0",
],
python_requires=">=3.8",
)
14 changes: 13 additions & 1 deletion src/init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import os
import importlib.util

# Validate numpy dependency first
try:
import numpy
print(f"numpy version {numpy.__version__} found")
except ImportError:
raise ImportError(
"numpy is required but not installed. Please install it using:\n"
"pip install numpy>=1.24.0"
)

from src.config import Config
from src.logger import Logger

Expand All @@ -8,7 +20,7 @@ def init_devika():

logger.info("Initializing Devika...")
logger.info("checking configurations...")

config = Config()

sqlite_db = config.get_sqlite_db()
Expand Down
25 changes: 25 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
from unittest.mock import patch
import numpy

def test_numpy_import():
"""Test that numpy can be imported and has correct version."""
assert numpy.__version__ >= "1.24.0"

def test_init_devika_numpy_validation():
"""Test that init_devika validates numpy dependency."""
from src.init import init_devika

# Should not raise any ImportError
init_devika()

@patch("importlib.import_module")
def test_init_devika_numpy_missing(mock_import):
"""Test that init_devika handles missing numpy correctly."""
mock_import.side_effect = ImportError("No module named numpy")

with pytest.raises(ImportError) as exc_info:
from src.init import init_devika
init_devika()

assert "numpy is required but not installed" in str(exc_info.value)