Skip to content

Commit a84717b

Browse files
authored
Merge pull request #194 from spicecodecli/spicecloud
Spicecloud base version
2 parents 2af1b5a + 5c5a15e commit a84717b

25 files changed

+6763
-2
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
run: |
2626
python -m pip install --upgrade pip
2727
# Install the project in editable mode to pick up changes
28+
pip install -r requirements.txt
2829
pip install -e .
2930
# Install test dependencies, including pytest-cov for coverage
3031
pip install pytest typer numpy pytest-cov

cli/commands/analyze.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
from InquirerPy import inquirer
2+
import requests
3+
import json
4+
import hashlib
5+
import os
6+
import sys
27

38
from utils.get_translation import get_translation
49
from spice.analyze import analyze_file
510

11+
# Add this at the top - server configuration
12+
SERVER_URL = "http://localhost:3000/api/submit"
13+
14+
def get_file_hash(file_path):
15+
"""Generate a hash for the file based on content and modification time"""
16+
try:
17+
with open(file_path, 'rb') as f:
18+
file_content = f.read()
19+
20+
# Include file modification time to detect changes
21+
mod_time = os.path.getmtime(file_path)
22+
hash_input = file_content + str(mod_time).encode()
23+
24+
return hashlib.md5(hash_input).hexdigest()
25+
except Exception as e:
26+
print(f"Error generating hash: {e}")
27+
return None
28+
29+
def send_to_server(data):
30+
"""Send analysis data to the server"""
31+
try:
32+
response = requests.post(SERVER_URL, json=data, timeout=5)
33+
34+
if response.status_code == 200:
35+
result = response.json()
36+
if result.get('isDuplicate'):
37+
print("✓ Data updated on server (file was modified)")
38+
else:
39+
print("✓ New analysis sent to server")
40+
return True
41+
else:
42+
# print(f"⚠ Server responded with status {response.status_code}", file=sys.stderr)
43+
return False
44+
45+
except requests.exceptions.ConnectionError:
46+
# print("⚠ Could not connect to server - make sure it's running on localhost:3000", file=sys.stderr)
47+
return False
48+
except requests.exceptions.Timeout:
49+
# print("⚠ Server request timed out", file=sys.stderr)
50+
return False
51+
except Exception as e:
52+
# Linha para debugar erros, descomente se precisar:
53+
# print(f"⚠ Error sending to server: {e}", file=sys.stderr)
54+
return False
55+
56+
657

758
def analyze_command(file, all, json_output, LANG_FILE):
859
"""
@@ -79,6 +130,18 @@ def analyze_command(file, all, json_output, LANG_FILE):
79130
# get analysis results from analyze_file
80131
results = analyze_file(file, selected_stats=selected_stat_keys)
81132

133+
# Prepare data for server
134+
server_data = {
135+
"file_name": results.get("file_name"),
136+
"file_path": results.get("file_path"),
137+
"file_size": results.get("file_size"),
138+
"file_extension": results.get("file_extension"),
139+
**{k: v for k, v in results.items() if k not in ["file_name", "file_path", "file_size", "file_extension"]}
140+
}
141+
142+
# Send to server (always attempt this, regardless of output mode)
143+
send_to_server(server_data)
144+
82145
# output in JSON format if flag
83146
if json_output:
84147
import json
@@ -107,4 +170,4 @@ def analyze_command(file, all, json_output, LANG_FILE):
107170
error_msg = str(e).replace('\n', ' ')
108171
print(json.dumps({"error": error_msg}))
109172
else:
110-
print(f"{messages.get('error', 'Error')}: {e}")
173+
print(f"{messages.get('error', 'Error')}: {e}")

requirements-clean.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
InquirerPy==0.3.4
2+
numpy==2.2.6
3+
pytest==8.3.5
4+
rich==14.0.0
5+
setuptools==78.1.1
6+
typer==0.15.4

requirements.txt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
1-
InquirerPy==0.3.4
1+
build==1.2.2.post1
2+
certifi==2025.1.31
3+
charset-normalizer==3.4.1
4+
click==8.1.8
5+
colorama==0.4.6
6+
docutils==0.21.2
7+
id==1.5.0
8+
idna==3.10
9+
importlib==1.0.4
10+
iniconfig==2.1.0
11+
inquirerpy==0.3.4
12+
jaraco.classes==3.4.0
13+
jaraco.context==6.0.1
14+
jaraco.functools==4.1.0
15+
keyring==25.6.0
16+
markdown-it-py==3.0.0
17+
mdurl==0.1.2
18+
more-itertools==10.6.0
19+
nh3==0.2.21
220
numpy==2.2.6
21+
packaging==24.2
22+
pfzy==0.3.4
23+
pluggy==1.5.0
24+
prompt_toolkit==3.0.50
25+
Pygments==2.19.1
26+
pyproject_hooks==1.2.0
327
pytest==8.3.5
28+
pywin32-ctypes==0.2.3
29+
readme_renderer==44.0
30+
requests==2.32.3
31+
requests-toolbelt==1.0.0
32+
rfc3986==2.0.0
433
rich==14.0.0
534
setuptools==78.1.1
35+
shellingham==1.5.4
36+
twine==6.1.0
637
typer==0.15.4
38+
typing_extensions==4.12.2
39+
urllib3==2.3.0
40+
wcwidth==0.2.13
41+
wheel==0.45.1

spicecloud/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts
42+
43+
/data

spicecloud/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/pages/api-reference/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
20+
21+
[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`.
22+
23+
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.
24+
25+
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.
26+
27+
## Learn More
28+
29+
To learn more about Next.js, take a look at the following resources:
30+
31+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
32+
- [Learn Next.js](https://nextjs.org/learn-pages-router) - an interactive Next.js tutorial.
33+
34+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
35+
36+
## Deploy on Vercel
37+
38+
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.
39+
40+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/pages/building-your-application/deploying) for more details.

spicecloud/next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const nextConfig = {
2+
/* config options here */
3+
reactStrictMode: true,
4+
};
5+
6+
export default nextConfig;

0 commit comments

Comments
 (0)