This guide is for developers who want to contribute to the Tor VPN System.
git clone https://github.com/AutoBotSolutions/TOR-VPN-SYSTEM.git
cd tor_vpn
# Using venv
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# or
.venv\Scripts\activate # Windows
# Using conda (alternative)
conda create -n tor_vpn python=3.11
conda activate tor_vpn
# Base dependencies
pip install -r requirements.txt
# Development dependencies
pip install -r requirements-dev.txt
# Linux
sudo apt install tor
# macOS
brew install tor
# Windows
# Download from https://www.torproject.org/
# Check Python version
python --version
# Check dependencies
pip list
# Check Tor
tor --version
# Run tests (if available)
pytest
Create .vscode/settings.json:
{
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.rulers": [88, 120]
}
.venv directoryInstall pre-commit hooks:
pip install pre-commit
pre-commit install
Run hooks manually:
pre-commit run --all-files
tor_vpn/
├── docs/ # Documentation
├── wiki/ # GitHub wiki
├── diagnostics/ # Diagnostic outputs
├── tests/ # Test files (to be created)
├── tor_vpn_beta.py # Main GUI application
├── tor_custom_config.py # Custom config generator
├── tor_auto_torrc_config.py # Automated setup
├── tor_diagnostic_repair.py # Diagnostic tool
├── tor_network_test.py # Network tester
├── tor_route_traffic_setup.py # Transparent proxy
├── tor_vpn_inclued.py # Startup validation
├── setup_tor_custom.sh # Bash setup script
├── tor_auto_proxy.sh # Proxy GUI
├── requirements.txt # Python dependencies
├── requirements-dev.txt # Dev dependencies
├── .gitignore # Git ignore
├── CHANGELOG.md # Version history
├── LICENSE # MIT License
└── README.md # Main README
main - Production-ready codedevelop - Development branchfeature/* - New featuresbugfix/* - Bug fixesdocs/* - Documentation changesgit checkout develop
git pull origin develop
git checkout -b feature/your-feature-name
Follow conventional commit format:
type(scope): subject
body
footer
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changesrefactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksExamples:
feat(gui): add country search filter
Add a search box in the servers tab to filter countries
by name or code.
Closes #123
Follow PEP 8 guidelines:
# Good
def connect_to_tor(country_code):
"""Connect to Tor using the specified country code."""
if not country_code:
raise ValueError("Country code is required")
try:
# Implementation
pass
except Exception as e:
logging.error(f"Failed to connect: {e}")
raise
Use Google style docstrings:
def authenticate_to_tor(controller, password):
"""Authenticate to Tor controller using password.
Args:
controller (Controller): Stem controller instance
password (str): Plain-text password for authentication
Returns:
bool: True if authentication successful, False otherwise
Raises:
AuthenticationError: If authentication fails
"""
try:
controller.authenticate(password=password)
return True
except Exception as e:
raise AuthenticationError(f"Authentication failed: {e}")
Use custom exceptions for domain-specific errors
:::python
try:
result = subprocess.run(command, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
logging.error(f"Command failed: {command}")
logging.error(f"Error output: {e.stderr}")
raise TorCommandError(f"Failed to execute command: {e}")
⚠️ CRITICAL: Never commit:
Use environment variables:
# Good
import os
password = os.environ.get("TOR_PASSWORD")
if not password:
raise ValueError("TOR_PASSWORD environment variable not set")
# Bad
password = "hardcoded_password_123"
tests/
├── __init__.py
├── utils.py # Test utilities and helpers
├── fixtures/
│ ├── __init__.py
│ └── conftest.py # Pytest fixtures (100+ fixtures)
├── unit/ # Unit tests for individual modules
│ ├── __init__.py
│ ├── test_tor_vpn_beta.py
│ ├── test_tor_custom_config.py
│ ├── test_tor_auto_torrc_config.py
│ ├── test_tor_diagnostic_repair.py
│ ├── test_tor_network_test.py
│ ├── test_tor_route_traffic_setup.py
│ └── test_tor_vpn_inclued.py
└── integration/ # Integration tests
├── __init__.py
└── test_full_workflow.py
# Run all tests
pytest
# Run unit tests only
pytest -m unit
# Run integration tests only
pytest -m integration
# Run with coverage
pytest --cov=.
# Run specific test file
pytest tests/unit/test_tor_vpn_beta.py
# Run with verbose output
pytest -v
# Run with coverage and detailed report
pytest --cov=. --cov-report=html --cov-report=term-missing
# Run tests matching a pattern
pytest -k "test_connect"
# Run tests excluding slow tests
pytest -m "not slow"
# Run tests requiring Tor (will be skipped if Tor not available)
pytest -m tor
# Run tests requiring root (will be skipped if not root)
pytest -m root
# Run tests requiring GUI (will be skipped if no GUI environment)
pytest -m gui
# Run tests requiring network (will be skipped if no network)
pytest -m network
The project aims for high test coverage:
The test suite uses pytest markers to categorize tests:
@pytest.mark.unit - Unit tests (fast, no external dependencies)@pytest.mark.integration - Integration tests (slower, may require external services)@pytest.mark.tor - Tests requiring Tor to be installed/running@pytest.mark.network - Tests requiring network access@pytest.mark.root - Tests requiring root privileges@pytest.mark.gui - Tests requiring GUI environment@pytest.mark.slow - Slow-running tests# Run all tests
pytest
# Run unit tests only
pytest -m unit
# Run integration tests only
pytest -m integration
# Run with coverage
pytest --cov=.
# Run specific test file
pytest tests/unit/test_tor_vpn_beta.py
# Run with verbose output
pytest -v
# Run with coverage and detailed report
pytest --cov=. --cov-report=html --cov-report=term-missing
# Run tests matching a pattern
pytest -k "test_connect"
# Run tests excluding slow tests
pytest -m "not slow"
# Run tests requiring Tor (will be skipped if Tor not available)
pytest -m tor
# Run tests requiring root (will be skipped if not root)
pytest -m root
# Run tests requiring GUI (will be skipped if no GUI environment)
pytest -m gui
# Run tests requiring network (will be skipped if no network)
pytest -m network
import pytest
from tor_custom_config import generate_hashed_password
def test_generate_hashed_password_success(mocker):
"""Test successful password hashing."""
mock_result = mocker.Mock()
mock_result.stdout = "16:ABCD1234"
mocker.patch('subprocess.run', return_value=mock_result)
result = generate_hashed_password("test_password")
assert result == "16:ABCD1234"
Aim for:
Create setup.py:
from setuptools import setup, find_packages
setup(
name="tor-vpn",
version="1.0.0",
packages=find_packages(),
install_requires=[
"stem~=1.8.2",
"psutil~=7.0.0",
],
python_requires=">=3.10",
)
Build package:
pip install build
python -m build
pip install pyinstaller
pyinstaller --onefile tor_vpn_beta.py
Last Updated: 2024-04-23