primethink-cli 1.0.0__tar.gz

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.
@@ -0,0 +1,500 @@
1
+ # PrimeThink CLI - Developer Guide
2
+
3
+ ## Table of Contents
4
+
5
+ 1. [Development Setup](#development-setup)
6
+ 2. [Project Structure](#project-structure)
7
+ 3. [Architecture](#architecture)
8
+ 4. [Adding New Commands](#adding-new-commands)
9
+ 5. [Testing](#testing)
10
+ 6. [Code Style](#code-style)
11
+ 7. [Contributing](#contributing)
12
+ 8. [Release Process](#release-process)
13
+
14
+ ## Development Setup
15
+
16
+ ### Prerequisites
17
+
18
+ - Python 3.7 or higher
19
+ - pip (Python package installer)
20
+ - git
21
+
22
+ ### Clone and Install
23
+
24
+ ```bash
25
+ # Clone the repository
26
+ git clone https://github.com/primethink-ai/primethink-cli.git
27
+ cd primethink-cli
28
+
29
+ # Create a virtual environment (recommended)
30
+ python -m venv venv
31
+ source venv/bin/activate # On Windows: venv\Scripts\activate
32
+
33
+ # Install in development mode
34
+ pip install -e ".[dev]"
35
+ ```
36
+
37
+ ### Development Dependencies
38
+
39
+ The development dependencies include:
40
+
41
+ - `pytest` - Testing framework
42
+ - `pytest-cov` - Code coverage plugin
43
+ - `click` - CLI framework
44
+ - `requests` - HTTP library
45
+
46
+ Install development dependencies:
47
+
48
+ ```bash
49
+ pip install -e ".[dev]"
50
+ ```
51
+
52
+ ## Project Structure
53
+
54
+ ```
55
+ primethink-cli/
56
+ ├── primethink.py # Main CLI implementation
57
+ ├── setup.py # Package configuration
58
+ ├── requirements.txt # Runtime dependencies
59
+ ├── requirements-dev.txt # Development dependencies
60
+ ├── README.md # User documentation
61
+ ├── SPECS.md # API specifications
62
+ ├── DEVELOPER.md # This file
63
+ ├── USER_GUIDE.md # User guide
64
+ ├── INTEGRATION_PAGE_TEXT.md # Integration documentation
65
+ ├── .gitignore # Git ignore rules
66
+ ├── pytest.ini # Pytest configuration
67
+ ├── Makefile # Build and test commands
68
+ ├── docs/ # Documentation files
69
+ │ ├── openapi.json # OpenAPI specification
70
+ │ └── primethink_help_llms.txt # API help text
71
+ └── tests/ # Test suite
72
+ ├── __init__.py
73
+ └── test_cli.py # CLI tests
74
+ ```
75
+
76
+ ## Architecture
77
+
78
+ ### Core Components
79
+
80
+ #### 1. Configuration Management
81
+
82
+ The CLI uses a JSON-based configuration system stored in `~/.primethink/config.json`.
83
+
84
+ **Config Structure**:
85
+ ```python
86
+ {
87
+ "active_profile": "default",
88
+ "profiles": {
89
+ "profile_name": {
90
+ "token": "api_token",
91
+ "env": "prod" # or "dev"
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ **Key Functions**:
98
+ - `load_config()`: Loads configuration from disk
99
+ - `save_config(config)`: Saves configuration to disk
100
+ - `get_active_config()`: Returns the active profile's configuration
101
+
102
+ #### 2. Command Structure
103
+
104
+ The CLI uses Click framework for command definition. Each command follows this pattern:
105
+
106
+ ```python
107
+ @cli.command()
108
+ @click.option('--param', '-p', required=True, help='Parameter description')
109
+ def command_name(param):
110
+ """Command description."""
111
+ config = get_active_config()
112
+ api_url = ENVIRONMENTS[config['env']]
113
+ token = config['token']
114
+
115
+ # Make API request
116
+ response = requests.method(
117
+ f"{api_url}/endpoint",
118
+ headers={"Authorization": f"Token {token}"}
119
+ )
120
+
121
+ # Handle response
122
+ if response.status_code == 200:
123
+ click.echo(json.dumps(response.json(), indent=2))
124
+ else:
125
+ click.echo(f"Error: {response.status_code}")
126
+ sys.exit(1)
127
+ ```
128
+
129
+ #### 3. API Client
130
+
131
+ The CLI uses the `requests` library for HTTP communication with the PrimeThink API.
132
+
133
+ **Authentication**:
134
+ ```python
135
+ headers = {
136
+ "Authorization": f"Token {token}",
137
+ "accept": "application/json"
138
+ }
139
+ ```
140
+
141
+ **File Uploads**:
142
+ ```python
143
+ files_data = []
144
+ for file_path in files:
145
+ files_data.append(('files', open(file_path, 'rb')))
146
+
147
+ response = requests.post(
148
+ url,
149
+ data=form_data,
150
+ files=files_data
151
+ )
152
+
153
+ # Always close file handles
154
+ for _, file_handle in files_data:
155
+ file_handle.close()
156
+ ```
157
+
158
+ ## Adding New Commands
159
+
160
+ ### Step 1: Define the Command
161
+
162
+ Add a new command decorator and function in `primethink.py`:
163
+
164
+ ```python
165
+ @cli.command()
166
+ @click.argument('required_arg')
167
+ @click.option('--optional', '-o', help='Optional parameter')
168
+ def new_command(required_arg, optional):
169
+ """Brief description of what the command does."""
170
+ config = get_active_config()
171
+ api_url = ENVIRONMENTS[config['env']]
172
+ token = config['token']
173
+
174
+ try:
175
+ response = requests.get(
176
+ f"{api_url}/api/v1/your-endpoint",
177
+ headers={
178
+ "Authorization": f"Token {token}",
179
+ "accept": "application/json"
180
+ }
181
+ )
182
+
183
+ if response.status_code == 200:
184
+ result = response.json()
185
+ click.echo(json.dumps(result, indent=2))
186
+ else:
187
+ click.echo(f"Error: {response.status_code} - {response.text}")
188
+ sys.exit(1)
189
+ except requests.exceptions.RequestException as e:
190
+ click.echo(f"Error connecting to API: {e}")
191
+ sys.exit(1)
192
+ ```
193
+
194
+ ### Step 2: Add Tests
195
+
196
+ Create test cases in `tests/test_cli.py`:
197
+
198
+ ```python
199
+ @patch('primethink.get_active_config')
200
+ @patch('primethink.requests.get')
201
+ def test_new_command(mock_get, mock_config_fn, runner):
202
+ """Test new_command."""
203
+ mock_config_fn.return_value = {'token': 'test-token', 'env': 'prod'}
204
+
205
+ mock_response = MagicMock()
206
+ mock_response.status_code = 200
207
+ mock_response.json.return_value = {'result': 'success'}
208
+ mock_get.return_value = mock_response
209
+
210
+ result = runner.invoke(new_command, ['arg1', '--optional', 'value'])
211
+
212
+ assert result.exit_code == 0
213
+ mock_get.assert_called_once()
214
+ assert 'success' in result.output
215
+ ```
216
+
217
+ ### Step 3: Update Documentation
218
+
219
+ Update the following files:
220
+ - `README.md` - Add command to usage examples
221
+ - `SPECS.md` - Add API endpoint specification
222
+ - `USER_GUIDE.md` - Add user-friendly guide for the command
223
+
224
+ ### Step 4: Run Tests
225
+
226
+ ```bash
227
+ pytest tests/ -v
228
+ ```
229
+
230
+ ## Testing
231
+
232
+ ### Running Tests
233
+
234
+ ```bash
235
+ # Run all tests
236
+ pytest
237
+
238
+ # Run with verbose output
239
+ pytest -v
240
+
241
+ # Run specific test file
242
+ pytest tests/test_cli.py
243
+
244
+ # Run specific test
245
+ pytest tests/test_cli.py::test_configure_command
246
+
247
+ # Run with coverage
248
+ pytest --cov=primethink --cov-report=html
249
+ ```
250
+
251
+ ### Test Structure
252
+
253
+ Tests use the following tools:
254
+ - `pytest` - Test framework
255
+ - `click.testing.CliRunner` - CLI testing
256
+ - `unittest.mock` - Mocking dependencies
257
+
258
+ ### Writing Tests
259
+
260
+ Example test pattern:
261
+
262
+ ```python
263
+ def test_command(runner, mock_config):
264
+ """Test description."""
265
+ # Arrange
266
+ with patch('primethink.load_config') as mock_load:
267
+ mock_load.return_value = mock_config
268
+
269
+ # Act
270
+ result = runner.invoke(command_name, ['arg'])
271
+
272
+ # Assert
273
+ assert result.exit_code == 0
274
+ assert 'expected output' in result.output
275
+ ```
276
+
277
+ ### Mocking API Responses
278
+
279
+ ```python
280
+ @patch('primethink.requests.post')
281
+ def test_api_call(mock_post, runner):
282
+ mock_response = MagicMock()
283
+ mock_response.status_code = 200
284
+ mock_response.json.return_value = {'data': 'value'}
285
+ mock_post.return_value = mock_response
286
+
287
+ # Test implementation
288
+ ```
289
+
290
+ ## Code Style
291
+
292
+ ### Python Style Guide
293
+
294
+ Follow PEP 8 guidelines:
295
+
296
+ - Use 4 spaces for indentation
297
+ - Maximum line length: 100 characters
298
+ - Use descriptive variable names
299
+ - Add docstrings to all functions
300
+
301
+ ### Naming Conventions
302
+
303
+ - **Functions**: `snake_case`
304
+ - **Classes**: `PascalCase`
305
+ - **Constants**: `UPPER_SNAKE_CASE`
306
+ - **Private methods**: `_leading_underscore`
307
+
308
+ ### Documentation
309
+
310
+ - Add docstrings to all public functions
311
+ - Use type hints where appropriate
312
+ - Keep comments concise and meaningful
313
+
314
+ Example:
315
+
316
+ ```python
317
+ def get_active_config() -> Dict[str, str]:
318
+ """Get active profile configuration.
319
+
320
+ Returns:
321
+ Dict containing 'token' and 'env' keys.
322
+
323
+ Raises:
324
+ SystemExit: If no active profile is configured.
325
+ """
326
+ config = load_config()
327
+ # Implementation
328
+ ```
329
+
330
+ ## Contributing
331
+
332
+ ### Workflow
333
+
334
+ 1. Fork the repository
335
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
336
+ 3. Make your changes
337
+ 4. Write tests for new functionality
338
+ 5. Ensure all tests pass: `pytest`
339
+ 6. Commit your changes: `git commit -m "Add my feature"`
340
+ 7. Push to your fork: `git push origin feature/my-feature`
341
+ 8. Create a Pull Request
342
+
343
+ ### Pull Request Guidelines
344
+
345
+ - Include a clear description of changes
346
+ - Reference any related issues
347
+ - Ensure all tests pass
348
+ - Update documentation as needed
349
+ - Add tests for new features
350
+
351
+ ### Code Review Process
352
+
353
+ All pull requests require:
354
+ - At least one approval
355
+ - Passing CI/CD checks
356
+ - Updated documentation
357
+ - Code coverage maintained or improved
358
+
359
+ ## Release Process
360
+
361
+ ### Version Numbering
362
+
363
+ Follow Semantic Versioning (SemVer):
364
+ - **MAJOR**: Breaking changes
365
+ - **MINOR**: New features (backward compatible)
366
+ - **PATCH**: Bug fixes (backward compatible)
367
+
368
+ ### Release Checklist
369
+
370
+ 1. Update version in `setup.py`
371
+ 2. Update `CHANGELOG.md`
372
+ 3. Run full test suite: `pytest`
373
+ 4. Build package: `python setup.py sdist bdist_wheel`
374
+ 5. Test installation in clean environment
375
+ 6. Tag release: `git tag v1.0.0`
376
+ 7. Push tags: `git push --tags`
377
+ 8. Publish to PyPI: `twine upload dist/*`
378
+
379
+ ### Build Commands
380
+
381
+ ```bash
382
+ # Clean previous builds
383
+ rm -rf build dist *.egg-info
384
+
385
+ # Build distribution packages
386
+ python setup.py sdist bdist_wheel
387
+
388
+ # Test package installation
389
+ pip install dist/primethink_cli-1.0.0-py3-none-any.whl
390
+ ```
391
+
392
+ ## Debugging
393
+
394
+ ### Enable Verbose Output
395
+
396
+ Set debug environment variable:
397
+
398
+ ```bash
399
+ export PRIMETHINK_DEBUG=1
400
+ primethink command
401
+ ```
402
+
403
+ ### Common Issues
404
+
405
+ #### Import Errors
406
+
407
+ ```bash
408
+ # Reinstall in development mode
409
+ pip install -e .
410
+ ```
411
+
412
+ #### Config File Issues
413
+
414
+ ```bash
415
+ # Check config location
416
+ cat ~/.primethink/config.json
417
+
418
+ # Reset config
419
+ rm ~/.primethink/config.json
420
+ primethink configure --token YOUR_TOKEN
421
+ ```
422
+
423
+ #### API Errors
424
+
425
+ ```bash
426
+ # Test with curl
427
+ curl -X GET \
428
+ 'https://api.primethink.ai/api/v1/tasks/available_task_actions' \
429
+ -H 'Authorization: Token YOUR_TOKEN'
430
+ ```
431
+
432
+ ## Performance Considerations
433
+
434
+ ### File Handling
435
+
436
+ Always close file handles after upload:
437
+
438
+ ```python
439
+ files_data = []
440
+ for file_path in files:
441
+ files_data.append(('files', open(file_path, 'rb')))
442
+
443
+ try:
444
+ response = requests.post(url, files=files_data)
445
+ finally:
446
+ for _, file_handle in files_data:
447
+ file_handle.close()
448
+ ```
449
+
450
+ ### Request Timeout
451
+
452
+ Set reasonable timeouts for API requests:
453
+
454
+ ```python
455
+ response = requests.get(url, timeout=30)
456
+ ```
457
+
458
+ ### Memory Usage
459
+
460
+ For large files, consider streaming:
461
+
462
+ ```python
463
+ with open(file_path, 'rb') as f:
464
+ files = {'file': f}
465
+ response = requests.post(url, files=files)
466
+ ```
467
+
468
+ ## Security Best Practices
469
+
470
+ 1. **Never log API tokens**
471
+ 2. **Use environment variables for sensitive data**
472
+ 3. **Validate user inputs**
473
+ 4. **Sanitize file paths**
474
+ 5. **Use HTTPS for all API calls**
475
+ 6. **Store config with restricted permissions**
476
+
477
+ ```python
478
+ # Set secure permissions on config file
479
+ import os
480
+ os.chmod(CONFIG_FILE, 0o600)
481
+ ```
482
+
483
+ ## Resources
484
+
485
+ - [Click Documentation](https://click.palletsprojects.com/)
486
+ - [Requests Documentation](https://requests.readthedocs.io/)
487
+ - [Pytest Documentation](https://docs.pytest.org/)
488
+ - [PrimeThink API Documentation](https://docs.primethink.ai/)
489
+ - [PEP 8 Style Guide](https://pep8.org/)
490
+
491
+ ## Support
492
+
493
+ For development questions or issues:
494
+ - Open an issue on GitHub
495
+ - Email: support@primethink.ai
496
+ - Join our developer community
497
+
498
+ ## License
499
+
500
+ This project is licensed under the MIT License. See LICENSE file for details.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 PrimeThink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ include README.md
2
+ include LICENSE
3
+ include SPECS.md
4
+ include USER_GUIDE.md
5
+ include DEVELOPER.md
6
+ recursive-include docs *.md *.txt
7
+ recursive-include install *.sh *.ps1 *.cmd *.rb
8
+ recursive-include scripts *.sh
9
+ global-exclude __pycache__
10
+ global-exclude *.py[co]
11
+ global-exclude .DS_Store