maya-cli 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- maya_cli/cli.py +124 -29
- {maya_cli-0.1.3.dist-info → maya_cli-0.1.4.dist-info}/METADATA +64 -7
- {maya_cli-0.1.3.dist-info → maya_cli-0.1.4.dist-info}/RECORD +6 -6
- {maya_cli-0.1.3.dist-info → maya_cli-0.1.4.dist-info}/WHEEL +1 -1
- {maya_cli-0.1.3.dist-info → maya_cli-0.1.4.dist-info}/entry_points.txt +0 -0
- {maya_cli-0.1.3.dist-info → maya_cli-0.1.4.dist-info}/top_level.txt +0 -0
maya_cli/cli.py
CHANGED
@@ -8,6 +8,7 @@ import openai
|
|
8
8
|
from .project_generator import create_project_structure, PROJECT_STRUCTURE
|
9
9
|
from .refactor import process_directory
|
10
10
|
from maya_cli.scripts import optimize # This will trigger optimize_event_handler automatically
|
11
|
+
import subprocess
|
11
12
|
|
12
13
|
|
13
14
|
# Setup logging
|
@@ -21,6 +22,107 @@ logging.basicConfig(
|
|
21
22
|
# Load environment variables from .env
|
22
23
|
load_dotenv()
|
23
24
|
|
25
|
+
# ✅ Function to check if OPENAI_API_KEY is set before executing commands
|
26
|
+
def require_openai_key():
|
27
|
+
"""Ensure the OpenAI API key is set before executing commands."""
|
28
|
+
api_key = get_openai_key()
|
29
|
+
|
30
|
+
if not api_key:
|
31
|
+
logging.error("❌ OPENAI_API_KEY is not set. Please set it before proceeding.")
|
32
|
+
print("❌ OPENAI_API_KEY is not set. Please set it before proceeding.")
|
33
|
+
oak = input("Enter OPENAI_API_KEY: ").strip()
|
34
|
+
|
35
|
+
if not oak:
|
36
|
+
print("❌ No API key provided. Exiting.")
|
37
|
+
sys.exit(1)
|
38
|
+
|
39
|
+
set_env_func("OPENAI_API_KEY", oak) # Call set_env to save the key
|
40
|
+
|
41
|
+
verify_openai_key()
|
42
|
+
|
43
|
+
verify_openai_key()
|
44
|
+
|
45
|
+
def get_openai_key():
|
46
|
+
"""Retrieve the OpenAI API key, checking multiple sources."""
|
47
|
+
api_key = os.getenv("OPENAI_API_KEY") # Check normal env first
|
48
|
+
|
49
|
+
if not api_key:
|
50
|
+
# ✅ Force fetch from User-level env variables in Windows
|
51
|
+
if os.name == "nt":
|
52
|
+
api_key = subprocess.run(
|
53
|
+
["powershell", "-Command",
|
54
|
+
'[System.Environment]::GetEnvironmentVariable("OPENAI_API_KEY", "User")'],
|
55
|
+
capture_output=True, text=True
|
56
|
+
).stdout.strip()
|
57
|
+
|
58
|
+
return api_key
|
59
|
+
|
60
|
+
# ✅ CLI Command to set environment variables
|
61
|
+
@click.command()
|
62
|
+
@click.argument("key")
|
63
|
+
@click.argument("value")
|
64
|
+
def set_env(key, value):
|
65
|
+
set_env_func(key, value)
|
66
|
+
|
67
|
+
def set_env_func(key, value):
|
68
|
+
"""Set an environment variable in .env file."""
|
69
|
+
env_file = ".env"
|
70
|
+
|
71
|
+
try:
|
72
|
+
if not os.path.exists(env_file):
|
73
|
+
with open(env_file, "w") as f:
|
74
|
+
f.write("# Maya CLI Environment Variables\n")
|
75
|
+
logging.info("Created new .env file.")
|
76
|
+
|
77
|
+
set_key(env_file, key, value)
|
78
|
+
|
79
|
+
# ✅ Set environment variable for current session
|
80
|
+
os.environ[key] = value
|
81
|
+
|
82
|
+
# ✅ Set environment variable permanently (Windows & Linux/Mac)
|
83
|
+
if os.name == "nt": # Windows
|
84
|
+
os.system(f'setx {key} "{value}"')
|
85
|
+
|
86
|
+
# Set for PowerShell (User Scope)
|
87
|
+
subprocess.run(["powershell", "-Command",
|
88
|
+
f'[System.Environment]::SetEnvironmentVariable("{key}", "{value}", "User")'])
|
89
|
+
|
90
|
+
# ✅ Immediately update PowerShell session so $env:OPENAI_API_KEY works instantly
|
91
|
+
subprocess.run(["powershell", "-Command",
|
92
|
+
f'$env:{key} = "{value}"'])
|
93
|
+
|
94
|
+
print(f"✅ Environment variable '{key}' set successfully for CMD & PowerShell!")
|
95
|
+
|
96
|
+
else: # Linux/Mac
|
97
|
+
os.system(f'export {key}="{value}"')
|
98
|
+
|
99
|
+
click.echo(f"✅ Environment variable '{key}' set successfully!")
|
100
|
+
logging.info(f"Set environment variable: {key}={value}")
|
101
|
+
|
102
|
+
except Exception as e:
|
103
|
+
logging.error(f"Error setting environment variable {key}: {str(e)}")
|
104
|
+
click.echo(f"❌ Error setting environment variable: {str(e)}")
|
105
|
+
|
106
|
+
# ✅ Function to verify OpenAI API key is set
|
107
|
+
def verify_openai_key():
|
108
|
+
"""Check if OPENAI_API_KEY is set in environment variables."""
|
109
|
+
openai_key = os.getenv("OPENAI_API_KEY")
|
110
|
+
if not openai_key:
|
111
|
+
logging.error("OPENAI_API_KEY is not set. Please set it before proceeding.")
|
112
|
+
return False
|
113
|
+
pass
|
114
|
+
|
115
|
+
# ✅ Function to execute CLI commands
|
116
|
+
def execute_maya_cli_command(command):
|
117
|
+
"""Executes a CLI command after verifying the OpenAI API key."""
|
118
|
+
if not verify_openai_key():
|
119
|
+
return
|
120
|
+
|
121
|
+
try:
|
122
|
+
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
123
|
+
logging.info("Command Output:\n%s", result.stdout.strip())
|
124
|
+
except subprocess.CalledProcessError as e:
|
125
|
+
logging.error("Error executing command: %s", e.stderr.strip())
|
24
126
|
|
25
127
|
@click.group()
|
26
128
|
def maya():
|
@@ -31,6 +133,7 @@ def maya():
|
|
31
133
|
@click.command()
|
32
134
|
@click.argument("project_name")
|
33
135
|
def create(project_name):
|
136
|
+
require_openai_key()
|
34
137
|
"""Create a new AI project structure"""
|
35
138
|
try:
|
36
139
|
base_path = os.path.join(os.getcwd(), project_name)
|
@@ -48,9 +151,11 @@ def create(project_name):
|
|
48
151
|
logging.error(f"Error while creating project: {str(e)}")
|
49
152
|
click.echo(f"❌ An error occurred: {str(e)}")
|
50
153
|
|
154
|
+
|
51
155
|
@click.command()
|
52
156
|
@click.argument("path", nargs=-1, required=True)
|
53
157
|
def check_best_practices(path):
|
158
|
+
require_openai_key()
|
54
159
|
"""CLI Command: maya check-best-practices [folder] [sub-folder] ... [filename]"""
|
55
160
|
click.echo("🚀 Running Best Practices Check...")
|
56
161
|
|
@@ -71,33 +176,12 @@ def check_best_practices(path):
|
|
71
176
|
|
72
177
|
click.echo("✅ Best practices check completed!")
|
73
178
|
|
74
|
-
|
75
|
-
@click.command()
|
76
|
-
@click.argument("key")
|
77
|
-
@click.argument("value")
|
78
|
-
def set_env(key, value):
|
79
|
-
"""Set an environment variable in .env file"""
|
80
|
-
env_file = ".env"
|
81
|
-
|
82
|
-
try:
|
83
|
-
if not os.path.exists(env_file):
|
84
|
-
with open(env_file, "w") as f:
|
85
|
-
f.write("# Maya CLI Environment Variables\n")
|
86
|
-
logging.info("Created new .env file.")
|
87
|
-
|
88
|
-
set_key(env_file, key, value)
|
89
|
-
click.echo(f"✅ Environment variable '{key}' set successfully!")
|
90
|
-
logging.info(f"Set environment variable: {key}={value}")
|
91
|
-
|
92
|
-
except Exception as e:
|
93
|
-
logging.error(f"Error setting environment variable {key}: {str(e)}")
|
94
|
-
click.echo(f"❌ Error setting environment variable: {str(e)}")
|
95
|
-
|
96
179
|
@click.command()
|
97
180
|
@click.argument("parent_folder", required=True)
|
98
181
|
@click.argument("sub_folder", required=True)
|
99
182
|
@click.argument("filename", required=True)
|
100
183
|
def optimize(parent_folder, sub_folder, filename):
|
184
|
+
require_openai_key()
|
101
185
|
"""Optimize a file by importing optimize.py from maya_cli.scripts."""
|
102
186
|
|
103
187
|
# Construct the full file path
|
@@ -136,17 +220,13 @@ def inject_import(filepath):
|
|
136
220
|
logging.error(f"Error injecting import into '{filepath}': {str(e)}")
|
137
221
|
click.echo(f"❌ Error injecting import into '{filepath}': {str(e)}")
|
138
222
|
|
139
|
-
import os
|
140
|
-
import json
|
141
|
-
import click
|
142
|
-
import logging
|
143
|
-
import openai
|
144
223
|
|
145
224
|
@click.command()
|
146
225
|
@click.argument("parent_folder", required=True)
|
147
226
|
@click.argument("sub_folder", required=True)
|
148
227
|
@click.argument("filename", required=True)
|
149
228
|
def is_secured(parent_folder, sub_folder, filename):
|
229
|
+
require_openai_key()
|
150
230
|
"""Check and enforce API security measures: Authentication, Encryption, and Rate Limiting."""
|
151
231
|
click.echo("🔍 Running API Security Check...")
|
152
232
|
|
@@ -243,11 +323,13 @@ def apply_rate_limiting(filepath):
|
|
243
323
|
with open(filepath, "a", encoding="utf-8") as f:
|
244
324
|
f.write("\n# TODO: Enforce API Rate Limiting & Quotas\n")
|
245
325
|
|
326
|
+
|
246
327
|
@click.command()
|
247
328
|
@click.argument("parent_folder", required=True)
|
248
329
|
@click.argument("sub_folder", required=True)
|
249
330
|
@click.argument("filename", required=False)
|
250
331
|
def check_ethics(parent_folder, sub_folder, filename=None):
|
332
|
+
require_openai_key()
|
251
333
|
"""Check code for efficiency, accuracy, and best practices."""
|
252
334
|
click.echo("\U0001F50D Running Code Ethics Check...")
|
253
335
|
ethics_issues = []
|
@@ -332,11 +414,13 @@ def validate_ethics_with_ai(code):
|
|
332
414
|
logging.error(f"Error in AI validation: {str(e)}")
|
333
415
|
return {"efficiency": False, "accuracy": False, "best_practices": False}
|
334
416
|
|
417
|
+
|
335
418
|
@click.command()
|
336
419
|
@click.argument("parent_folder")
|
337
420
|
@click.argument("sub_folder")
|
338
421
|
@click.argument("filename")
|
339
422
|
def doc(parent_folder, sub_folder, filename):
|
423
|
+
require_openai_key()
|
340
424
|
"""Generate README.md documentation for the given file."""
|
341
425
|
click.echo("📄 Generating Documentation...")
|
342
426
|
|
@@ -377,11 +461,13 @@ def generate_documentation(code):
|
|
377
461
|
"""Generate structured documentation based on the given Python code."""
|
378
462
|
return f"# Auto-Generated Documentation\n\n```python\n{code}\n```"
|
379
463
|
|
464
|
+
|
380
465
|
@click.command()
|
381
466
|
@click.argument("parent_folder")
|
382
467
|
@click.argument("sub_folder")
|
383
468
|
@click.argument("filename", required=False)
|
384
469
|
def codex(parent_folder, sub_folder, filename=None):
|
470
|
+
require_openai_key()
|
385
471
|
"""Provide in-depth analysis and recommendations for a file or all Python files in a directory."""
|
386
472
|
click.echo("📚 Creating Code Codex Report...")
|
387
473
|
|
@@ -431,11 +517,15 @@ def generate_codex_report(code):
|
|
431
517
|
"""Generate an in-depth analysis and recommendations based on the given Python code."""
|
432
518
|
return f"# Code Analysis & Recommendations\n\n```python\n{code}\n```\n\n## Recommendations:\n- Improve efficiency\n- Enhance readability\n- Optimize performance\n"
|
433
519
|
|
520
|
+
|
434
521
|
@click.command()
|
435
522
|
@click.argument("parent_folder")
|
436
523
|
@click.argument("sub_folder")
|
437
524
|
@click.argument("filename", required=False)
|
438
525
|
def regulate(parent_folder, sub_folder, filename=None):
|
526
|
+
# Ensure OpenAI API key is available before running logic
|
527
|
+
require_openai_key()
|
528
|
+
|
439
529
|
"""Ensure code compliance with GDPR, CCPA, AI Act, and ISO 42001 AI governance standards."""
|
440
530
|
click.echo("🔍 Running Compliance & Regulation Check...")
|
441
531
|
|
@@ -552,7 +642,7 @@ def generate_compliance_report(filepath, feedback):
|
|
552
642
|
🛠 *Generated by Compliance Checker*
|
553
643
|
"""
|
554
644
|
|
555
|
-
# Add commands to Maya CLI
|
645
|
+
# ✅ Add commands to Maya CLI
|
556
646
|
maya.add_command(is_secured)
|
557
647
|
maya.add_command(check_ethics)
|
558
648
|
maya.add_command(doc)
|
@@ -563,5 +653,10 @@ maya.add_command(check_best_practices)
|
|
563
653
|
maya.add_command(set_env)
|
564
654
|
maya.add_command(optimize)
|
565
655
|
|
656
|
+
# ✅ Run CLI
|
566
657
|
if __name__ == "__main__":
|
567
|
-
|
658
|
+
try:
|
659
|
+
maya()
|
660
|
+
except Exception as e:
|
661
|
+
logger.exception("Unexpected error: %s", str(e))
|
662
|
+
sys.exit(1)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: maya-cli
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: Maya CLI - AI Project Generator
|
5
5
|
Home-page: https://github.com/anointingmayami/Maya.ai
|
6
6
|
Author: King Anointing Joseph Mayami
|
@@ -26,6 +26,63 @@ Dynamic: summary
|
|
26
26
|
## Overview
|
27
27
|
Maya CLI is a command-line interface (CLI) designed to assist in AI project generation, optimization, security enforcement, and best practices validation. This documentation provides a guide on how to use each CLI command effectively.
|
28
28
|
|
29
|
+
# Quick Guide to Getting Started with Maya AI
|
30
|
+
|
31
|
+
## Step 1: Installation and Setup Development Environment
|
32
|
+
To begin using Maya AI, you need to set up your development environment. Follow these steps:
|
33
|
+
|
34
|
+
1. Ensure you have Python installed (preferably Python 3.8+).
|
35
|
+
2. Install the required dependencies using pip:
|
36
|
+
```sh
|
37
|
+
pip install click python-dotenv openai
|
38
|
+
```
|
39
|
+
3. Clone the Maya AI repository (if applicable) or set up your project directory.
|
40
|
+
|
41
|
+
## Step 2: Set Up OpenAI Key in Environment Variables
|
42
|
+
To integrate OpenAI services, you must configure your API key in an `.env` file:
|
43
|
+
|
44
|
+
1. Create a `.env` file in your project directory.
|
45
|
+
2. Use the `set_env` command to store your OpenAI API key:
|
46
|
+
```sh
|
47
|
+
maya set-env OPENAI_API_KEY your_api_key_here
|
48
|
+
```
|
49
|
+
This command will securely save your key in the `.env` file.
|
50
|
+
|
51
|
+
## Step 3: Create a Maya AI Project
|
52
|
+
Once the environment is set up, you can create a new AI project using the Maya CLI:
|
53
|
+
|
54
|
+
1. Run the following command to create a new project:
|
55
|
+
```sh
|
56
|
+
maya create your_project_name
|
57
|
+
```
|
58
|
+
2. This will generate the necessary project structure for your AI application.
|
59
|
+
3. Navigate into your project directory and start developing.
|
60
|
+
|
61
|
+
## Additional Maya AI CLI Commands
|
62
|
+
- **Check Best Practices:**
|
63
|
+
```sh
|
64
|
+
maya check-best-practices path_to_project
|
65
|
+
```
|
66
|
+
Ensures your project follows AI development best practices.
|
67
|
+
|
68
|
+
- **Optimize a File:**
|
69
|
+
```sh
|
70
|
+
maya optimize parent_folder sub_folder filename
|
71
|
+
```
|
72
|
+
Automatically imports optimization scripts to improve performance.
|
73
|
+
|
74
|
+
- **Check API Security:**
|
75
|
+
```sh
|
76
|
+
maya is-secured parent_folder sub_folder filename
|
77
|
+
```
|
78
|
+
Runs an AI-based security check on your API implementations.
|
79
|
+
|
80
|
+
- **Check Code Ethics:**
|
81
|
+
```sh
|
82
|
+
maya check-ethics parent_folder sub_folder filename
|
83
|
+
```
|
84
|
+
Reviews code for efficiency, accuracy, and ethical standards.
|
85
|
+
|
29
86
|
## Installation
|
30
87
|
Before using Maya CLI, ensure that the required dependencies are installed:
|
31
88
|
```sh
|
@@ -49,27 +106,27 @@ maya create my_ai_project
|
|
49
106
|
### 2. Check Best Practices
|
50
107
|
#### Command:
|
51
108
|
```sh
|
52
|
-
maya
|
109
|
+
maya check-best-practices [folder] [filename]
|
53
110
|
```
|
54
111
|
#### Description:
|
55
112
|
Validates Python code against best practices.
|
56
113
|
|
57
114
|
#### Example:
|
58
115
|
```sh
|
59
|
-
maya
|
116
|
+
maya check-best-practices api my_script.py
|
60
117
|
```
|
61
118
|
|
62
119
|
### 3. Set Environment Variable
|
63
120
|
#### Command:
|
64
121
|
```sh
|
65
|
-
maya
|
122
|
+
maya set-env <key> <value>
|
66
123
|
```
|
67
124
|
#### Description:
|
68
125
|
Sets a key-value pair in the `.env` file.
|
69
126
|
|
70
127
|
#### Example:
|
71
128
|
```sh
|
72
|
-
maya
|
129
|
+
maya set-env OPENAI_API_KEY my_api_key
|
73
130
|
```
|
74
131
|
|
75
132
|
### 4. Optimize AI Scripts
|
@@ -101,14 +158,14 @@ maya isSecured api my_api.py
|
|
101
158
|
### 6. Check Code Ethics
|
102
159
|
#### Command:
|
103
160
|
```sh
|
104
|
-
maya
|
161
|
+
maya check-ethics <target> [filename]
|
105
162
|
```
|
106
163
|
#### Description:
|
107
164
|
Validates code efficiency, accuracy, and best practices.
|
108
165
|
|
109
166
|
#### Example:
|
110
167
|
```sh
|
111
|
-
maya
|
168
|
+
maya check-ethics my_project
|
112
169
|
```
|
113
170
|
|
114
171
|
### 7. Generate Documentation
|
@@ -1,11 +1,11 @@
|
|
1
1
|
maya_cli/__init__.py,sha256=d7ktJFCti7GbZZJJHwTLpLy9EyI3lJmkqtL3YnR-cm8,69
|
2
|
-
maya_cli/cli.py,sha256=
|
2
|
+
maya_cli/cli.py,sha256=XfD_SadKZltJHiuKPkoVwUcHwVgsMuX-MkEi6J3CVUM,25372
|
3
3
|
maya_cli/project_generator.py,sha256=AB9uV_lBe-KPywMJ3uDH9YPSTRHXFP7qzqpPdxDB5GY,2967
|
4
4
|
maya_cli/refactor.py,sha256=ipi3iabQOcyQyJn20PErpgi-Hb4cb8f8p7zW0HO22_s,3890
|
5
5
|
maya_cli/scripts/__init__.py,sha256=yY3Tbs-t4HSl4I0Ev0RcHMnHU7SwljlWRveiRJkeCB8,10
|
6
6
|
maya_cli/scripts/optimize.py,sha256=UqDIHyyYPXZkhAb4GSvjbN0IvwXM2aFnpSh4k0Jzobo,4820
|
7
|
-
maya_cli-0.1.
|
8
|
-
maya_cli-0.1.
|
9
|
-
maya_cli-0.1.
|
10
|
-
maya_cli-0.1.
|
11
|
-
maya_cli-0.1.
|
7
|
+
maya_cli-0.1.4.dist-info/METADATA,sha256=Y4vy4YBBqodUu67Q4spqEGSGQCyHPbSdiKLJrWpLPwI,5373
|
8
|
+
maya_cli-0.1.4.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
9
|
+
maya_cli-0.1.4.dist-info/entry_points.txt,sha256=K4mI6r7-idKvOmz7zpMpK6HaEnraRoRt4nSW1jTfCgE,43
|
10
|
+
maya_cli-0.1.4.dist-info/top_level.txt,sha256=nZzw8c5hxqres4pU9UUFCTjwBSHUDNjqCTM7yOFnnrE,9
|
11
|
+
maya_cli-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|