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
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# Install the project in editable mode to pick up changes
pip install -r requirements.txt
pip install -e .
# Install test dependencies, including pytest-cov for coverage
pip install pytest typer numpy pytest-cov
Expand Down
65 changes: 64 additions & 1 deletion cli/commands/analyze.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
from InquirerPy import inquirer
import requests
import json
import hashlib
import os
import sys

from utils.get_translation import get_translation
from spice.analyze import analyze_file

# Add this at the top - server configuration
SERVER_URL = "http://localhost:3000/api/submit"

def get_file_hash(file_path):
"""Generate a hash for the file based on content and modification time"""
try:
with open(file_path, 'rb') as f:
file_content = f.read()

# Include file modification time to detect changes
mod_time = os.path.getmtime(file_path)
hash_input = file_content + str(mod_time).encode()

return hashlib.md5(hash_input).hexdigest()
except Exception as e:
print(f"Error generating hash: {e}")
return None

def send_to_server(data):
"""Send analysis data to the server"""
try:
response = requests.post(SERVER_URL, json=data, timeout=5)

if response.status_code == 200:
result = response.json()
if result.get('isDuplicate'):
print("✓ Data updated on server (file was modified)")
else:
print("✓ New analysis sent to server")
return True
else:
# print(f"⚠ Server responded with status {response.status_code}", file=sys.stderr)
return False

except requests.exceptions.ConnectionError:
# print("⚠ Could not connect to server - make sure it's running on localhost:3000", file=sys.stderr)
return False
except requests.exceptions.Timeout:
# print("⚠ Server request timed out", file=sys.stderr)
return False
except Exception as e:
# Linha para debugar erros, descomente se precisar:
# print(f"⚠ Error sending to server: {e}", file=sys.stderr)
return False



def analyze_command(file, all, json_output, LANG_FILE):
"""
Expand Down Expand Up @@ -79,6 +130,18 @@ def analyze_command(file, all, json_output, LANG_FILE):
# get analysis results from analyze_file
results = analyze_file(file, selected_stats=selected_stat_keys)

# Prepare data for server
server_data = {
"file_name": results.get("file_name"),
"file_path": results.get("file_path"),
"file_size": results.get("file_size"),
"file_extension": results.get("file_extension"),
**{k: v for k, v in results.items() if k not in ["file_name", "file_path", "file_size", "file_extension"]}
}

# Send to server (always attempt this, regardless of output mode)
send_to_server(server_data)

# output in JSON format if flag
if json_output:
import json
Expand Down Expand Up @@ -107,4 +170,4 @@ def analyze_command(file, all, json_output, LANG_FILE):
error_msg = str(e).replace('\n', ' ')
print(json.dumps({"error": error_msg}))
else:
print(f"{messages.get('error', 'Error')}: {e}")
print(f"{messages.get('error', 'Error')}: {e}")
6 changes: 6 additions & 0 deletions requirements-clean.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
InquirerPy==0.3.4
numpy==2.2.6
pytest==8.3.5
rich==14.0.0
setuptools==78.1.1
typer==0.15.4
37 changes: 36 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
InquirerPy==0.3.4
build==1.2.2.post1
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
colorama==0.4.6
docutils==0.21.2
id==1.5.0
idna==3.10
importlib==1.0.4
iniconfig==2.1.0
inquirerpy==0.3.4
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
keyring==25.6.0
markdown-it-py==3.0.0
mdurl==0.1.2
more-itertools==10.6.0
nh3==0.2.21
numpy==2.2.6
packaging==24.2
pfzy==0.3.4
pluggy==1.5.0
prompt_toolkit==3.0.50
Pygments==2.19.1
pyproject_hooks==1.2.0
pytest==8.3.5
pywin32-ctypes==0.2.3
readme_renderer==44.0
requests==2.32.3
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==14.0.0
setuptools==78.1.1
shellingham==1.5.4
twine==6.1.0
typer==0.15.4
typing_extensions==4.12.2
urllib3==2.3.0
wcwidth==0.2.13
wheel==0.45.1
43 changes: 43 additions & 0 deletions spicecloud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

/data
40 changes: 40 additions & 0 deletions spicecloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/pages/api-reference/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/pages/building-your-application/routing/api-routes) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/pages/building-your-application/routing/api-routes) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/pages/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn-pages-router) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/pages/building-your-application/deploying) for more details.
6 changes: 6 additions & 0 deletions spicecloud/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const nextConfig = {
/* config options here */
reactStrictMode: true,
};

export default nextConfig;
Loading