This document provides information for developers who want to contribute to or modify the Jess terminal connection manager.
- Development Environment Setup
- Project Structure
- Testing
- Code Style
- Adding New Features
- Release Process
- Python 3.6 or higher
- Git
- pip package manager
- Clone the repository
git clone https://github.com/adamspera/jess.git
cd jess- Create and activate a virtual environment (recommended)
# Using venv
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Or using conda
conda create -n jess python=3.9
conda activate jess- Install in development mode with development dependencies
pip install -e ".[dev]"This installs the package in development mode, allowing you to modify the code without reinstalling, and includes all development dependencies.
The development environment includes:
- pytest: For running tests
- pytest-cov: For test coverage reporting
- flake8: For code linting
- black: For code formatting
- isort: For import sorting
- coverage: For detailed coverage analysis
The project follows a modular structure with clear separation of concerns:
jess/
├── __init__.py # Package metadata and version info
├── cli.py # Command-line interface and entry point
├── connection/ # Connection handling modules
│ ├── __init__.py
│ ├── manager.py # Connection orchestration
│ ├── ssh.py # SSH connection handlers
│ └── telnet.py # Telnet connection handler
├── inventory/ # Inventory management modules
│ ├── __init__.py
│ ├── manager.py # Inventory operations
│ └── parser.py # YAML parsing utilities
└── utils/ # Utility functions
├── __init__.py
└── colors.py # Terminal color formatting
tests/ # Test directory
├── __init__.py
├── test_cli.py # CLI tests
├── test_colors.py # Color utility tests
├── test_connection_manager.py # Connection manager tests
├── test_integration.py # End-to-end integration tests
├── test_inventory_manager.py # Inventory manager tests
├── test_mock_connections.py # Mock connection tests
├── test_parser.py # YAML parser tests
├── test_ssh_handler.py # SSH handler tests
└── test_telnet_handler.py # Telnet handler tests
examples/ # Example files
└── inventory_example.yaml # Example inventory configuration
-
CLI Interface (
cli.py)- Handles command-line arguments and user interaction
- Routes commands to appropriate manager methods
- Provides the main entry point for the application
-
Connection Manager (
connection/manager.py)- Orchestrates connection attempts and fallback logic
- Manages the connection workflow
- Handles connection success/failure reporting
-
Protocol Handlers (
connection/ssh.py,connection/telnet.py)- Implement specific connection protocols
- Handle protocol-specific authentication and session management
- Provide error handling for connection issues
-
Inventory Manager (
inventory/manager.py)- Manages device information storage and retrieval
- Handles inventory file operations (edit, load, show)
- Validates inventory data
-
YAML Parser (
inventory/parser.py)- Handles configuration file reading and writing
- Validates YAML structure
- Provides error handling for malformed YAML
-
Utilities (
utils/colors.py)- Provides colored terminal output functions
- Handles cross-platform color compatibility
The project uses pytest for testing. There are several ways to run the tests:
- Run all tests with coverage reporting
# Using the provided script
python run_tests_with_coverage.py
# Or directly with pytest
pytest --cov=jess- Run specific test files
# Run a specific test file
python run_tests_with_coverage.py tests/test_cli.py
# Or directly with pytest
pytest tests/test_cli.py- Run tests with verbose output
python run_tests_with_coverage.py -vAfter running tests with coverage, you can view the HTML coverage report:
# Open the HTML coverage report
open htmlcov/index.html # On macOS
# Or on Linux: xdg-open htmlcov/index.html
# Or on Windows: start htmlcov/index.htmlTests are organized to match the module structure:
- Unit Tests: Test individual components in isolation
- Integration Tests: Test interactions between components
- Mock Tests: Use mock objects to simulate network connections
When adding new features, follow these guidelines for writing tests:
- Create test files with the
test_prefix - Use descriptive test function names that explain what is being tested
- Group related tests in test classes
- Use fixtures for common setup and teardown
- Mock external dependencies (like network connections)
- Aim for high test coverage (>90%)
Example test structure:
import pytest
from unittest.mock import patch, MagicMock
def test_function_name_what_it_does():
# Arrange
# Act
# AssertThe project follows these style guidelines:
- PEP 8: Python style guide
- Black: Code formatting
- isort: Import sorting
- Docstrings: Google style docstrings
Format your code before committing:
# Format code with Black
black jess tests
# Sort imports
isort jess tests
# Check for style issues
flake8 jess testsWhen adding new features to Jess, follow these guidelines:
- Create a feature branch
git checkout -b feature/your-feature-name-
Implement the feature
- Follow the existing architecture and patterns
- Add appropriate tests
- Update documentation
-
Run tests and linting
python run_tests_with_coverage.py
flake8 jess tests
black jess tests
isort jess tests-
Update version number if necessary
- Update
__version__injess/__init__.py
- Update
-
Submit a pull request
- Include a clear description of the changes
- Reference any related issues
To add a new connection protocol:
- Create a new handler in the
connectionpackage - Implement the required connection methods
- Update the
ConnectionManagerto include the new protocol - Add appropriate tests
- Update documentation
To create a new release:
-
Update version number
- Update
__version__injess/__init__.py
- Update
-
Update documentation
- Update README.md with any new features
- Update DEVELOPER.md if necessary
-
Run final tests
python run_tests_with_coverage.py- Create a release tag
git tag -a v1.x.x -m "Version 1.x.x"
git push origin v1.x.x- Build and publish the package
# Build the package
python -m build
# Upload to PyPI (if applicable)
python -m twine upload dist/*-
Import errors after adding new modules
- Make sure to update
__init__.pyfiles with necessary imports - Reinstall the package in development mode:
pip install -e .
- Make sure to update
-
Test failures
- Check for recent changes that might affect other components
- Ensure mock objects correctly simulate the behavior they replace
- Verify that test fixtures are properly set up
-
Environment issues
- Ensure your virtual environment is activated
- Verify all dependencies are installed:
pip install -e ".[dev]"
- Use Python's built-in debugger:
import pdb; pdb.set_trace()- Add verbose logging for connection troubleshooting:
import logging
logging.basicConfig(level=logging.DEBUG)- Use pytest's debugging features:
pytest -xvs tests/test_file.py::test_function