Compare commits
2 Commits
44602a1145
...
ed084d1fea
| Author | SHA1 | Date | |
|---|---|---|---|
| ed084d1fea | |||
| 19bc632a33 |
13
.flake8
Normal file
13
.flake8
Normal file
@@ -0,0 +1,13 @@
|
||||
[flake8]
|
||||
max-line-length = 88
|
||||
extend-ignore = E203, W503, E501
|
||||
exclude =
|
||||
.git,
|
||||
__pycache__,
|
||||
.venv,
|
||||
venv,
|
||||
build,
|
||||
dist,
|
||||
*.egg-info
|
||||
per-file-ignores =
|
||||
__init__.py:F401
|
||||
@@ -33,7 +33,7 @@ pip install -e .
|
||||
Set environment variables:
|
||||
|
||||
```bash
|
||||
export PLC_IP=192.168.1.15
|
||||
export PLC_IP=198.18.100.141
|
||||
export PLC_PORT=502
|
||||
export DATA_UPDATE_INTERVAL=5
|
||||
export LOG_LEVEL=INFO
|
||||
@@ -150,7 +150,7 @@ export PLC_IP=127.0.0.1 # For simulator
|
||||
# Production environment
|
||||
export FLASK_ENV=production
|
||||
export SECRET_KEY=your-secret-key
|
||||
export PLC_IP=192.168.1.15
|
||||
export PLC_IP=198.18.100.141
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
106
VSCODE_SETUP.md
Normal file
106
VSCODE_SETUP.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# VSCode Setup for Watermaker PLC API
|
||||
|
||||
This document explains how to use the VSCode configuration for development and debugging of the Watermaker PLC API project.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Python Extension**: Install the Python extension for VSCode
|
||||
2. **Virtual Environment**: The project virtual environment should be created (see main README)
|
||||
|
||||
## VSCode Configuration Files
|
||||
|
||||
The following VSCode configuration files have been created:
|
||||
|
||||
### `.vscode/settings.json`
|
||||
- Sets the Python interpreter to use the virtual environment (`./venv/bin/python`)
|
||||
- Enables automatic virtual environment activation in terminals
|
||||
- Configures linting with flake8
|
||||
- Sets up code formatting with black
|
||||
- Enables pytest for testing
|
||||
- Configures file exclusions for better performance
|
||||
|
||||
### `.vscode/launch.json`
|
||||
Provides several debug configurations:
|
||||
|
||||
1. **Python: Run Server** - Debug the main server with `--debug` flag
|
||||
2. **Python: Run Server (Custom PLC)** - Debug with custom PLC IP/port settings
|
||||
3. **Python: Current File** - Debug the currently open Python file
|
||||
4. **Python: Pytest** - Debug tests using pytest
|
||||
5. **Python: Attach to Remote** - Attach to a remote debugging session
|
||||
|
||||
### `.vscode/tasks.json`
|
||||
Provides common development tasks:
|
||||
|
||||
1. **Install Dependencies** - Install packages from requirements.txt
|
||||
2. **Run Server** - Start the server in debug mode
|
||||
3. **Run Tests** - Execute all tests with pytest
|
||||
4. **Install Package in Dev Mode** - Install the package in development mode
|
||||
5. **Activate Virtual Environment** - Run the activation script
|
||||
|
||||
## How to Use
|
||||
|
||||
### 1. Select Python Interpreter
|
||||
- Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on Mac)
|
||||
- Type "Python: Select Interpreter"
|
||||
- Choose the interpreter from `./venv/bin/python`
|
||||
|
||||
### 2. Running and Debugging
|
||||
- Press `F5` to start debugging with the default configuration
|
||||
- Or use `Ctrl+Shift+D` to open the Debug panel and select a configuration
|
||||
- Set breakpoints by clicking in the left margin of code files
|
||||
|
||||
### 3. Running Tasks
|
||||
- Press `Ctrl+Shift+P` and type "Tasks: Run Task"
|
||||
- Select from the available tasks (Install Dependencies, Run Server, etc.)
|
||||
|
||||
### 4. Testing
|
||||
- The Test Explorer should automatically discover tests in the `tests/` directory
|
||||
- Use the Test Explorer panel to run individual tests or all tests
|
||||
- Or use the "Python: Pytest" debug configuration
|
||||
|
||||
### 5. Code Formatting and Linting
|
||||
- Code will be automatically formatted with black on save
|
||||
- Linting errors will be highlighted using flake8
|
||||
- Use `Ctrl+Shift+I` to format the current file manually
|
||||
|
||||
## Remote Debugging
|
||||
|
||||
For remote debugging scenarios:
|
||||
|
||||
1. Install debugpy in your remote environment:
|
||||
```bash
|
||||
pip install debugpy
|
||||
```
|
||||
|
||||
2. Add this to your remote code where you want to start debugging:
|
||||
```python
|
||||
import debugpy
|
||||
debugpy.listen(5678)
|
||||
debugpy.wait_for_client()
|
||||
```
|
||||
|
||||
3. Use the "Python: Attach to Remote" configuration in VSCode
|
||||
|
||||
## Terminal Integration
|
||||
|
||||
- New terminals will automatically activate the virtual environment
|
||||
- The integrated terminal respects the virtual environment settings
|
||||
- Use the "Activate Virtual Environment" task if needed
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Python Interpreter Not Found
|
||||
- Ensure the virtual environment exists: `ls venv/bin/python`
|
||||
- Manually select the interpreter using the Command Palette
|
||||
|
||||
### Tasks Not Working
|
||||
- Ensure bash is available on your system
|
||||
- Check that the virtual environment is properly created
|
||||
|
||||
### Linting/Formatting Issues
|
||||
- Ensure flake8 and black are installed: `pip list | grep -E "(flake8|black)"`
|
||||
- Check the `.flake8` and `pyproject.toml` configuration files
|
||||
|
||||
### Tests Not Discovered
|
||||
- Ensure pytest is installed: `pip list | grep pytest`
|
||||
- Check that test files follow the naming convention (`test_*.py`)
|
||||
18
activate_venv.sh
Executable file
18
activate_venv.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# Activation script for the watermaker PLC API virtual environment
|
||||
|
||||
echo "Activating virtual environment..."
|
||||
source venv/bin/activate
|
||||
|
||||
echo "Virtual environment activated!"
|
||||
echo "Python version: $(python --version)"
|
||||
echo "Pip version: $(pip --version)"
|
||||
echo ""
|
||||
echo "To run the server:"
|
||||
echo " python run_server.py"
|
||||
echo ""
|
||||
echo "To run tests:"
|
||||
echo " python -m pytest"
|
||||
echo ""
|
||||
echo "To deactivate the virtual environment:"
|
||||
echo " deactivate"
|
||||
63
pyproject.toml
Normal file
63
pyproject.toml
Normal file
@@ -0,0 +1,63 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ['py38']
|
||||
include = '\.pyi?$'
|
||||
extend-exclude = '''
|
||||
/(
|
||||
# directories
|
||||
\.eggs
|
||||
| \.git
|
||||
| \.hg
|
||||
| \.mypy_cache
|
||||
| \.tox
|
||||
| \.venv
|
||||
| venv
|
||||
| _build
|
||||
| buck-out
|
||||
| build
|
||||
| dist
|
||||
)/
|
||||
'''
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "6.0"
|
||||
addopts = "-ra -q --strict-markers --cov=watermaker_plc_api --cov-report=term-missing --cov-report=html"
|
||||
testpaths = [
|
||||
"tests",
|
||||
]
|
||||
python_files = [
|
||||
"test_*.py",
|
||||
"*_test.py",
|
||||
]
|
||||
python_classes = [
|
||||
"Test*",
|
||||
]
|
||||
python_functions = [
|
||||
"test_*",
|
||||
]
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["watermaker_plc_api"]
|
||||
omit = [
|
||||
"*/tests/*",
|
||||
"*/venv/*",
|
||||
"setup.py",
|
||||
]
|
||||
|
||||
[tool.coverage.report]
|
||||
exclude_lines = [
|
||||
"pragma: no cover",
|
||||
"def __repr__",
|
||||
"if self.debug:",
|
||||
"if settings.DEBUG",
|
||||
"raise AssertionError",
|
||||
"raise NotImplementedError",
|
||||
"if 0:",
|
||||
"if __name__ == .__main__.:",
|
||||
"class .*\\bProtocol\\):",
|
||||
"@(abc\\.)?abstractmethod",
|
||||
]
|
||||
@@ -26,8 +26,8 @@ def parse_args():
|
||||
help='Host to bind to (default: 0.0.0.0)')
|
||||
parser.add_argument('--port', type=int, default=5000,
|
||||
help='Port to bind to (default: 5000)')
|
||||
parser.add_argument('--plc-ip', default='192.168.1.15',
|
||||
help='PLC IP address (default: 192.168.1.15)')
|
||||
parser.add_argument('--plc-ip', default='198.18.100.141',
|
||||
help='PLC IP address (default: 198.18.100.141)')
|
||||
parser.add_argument('--plc-port', type=int, default=502,
|
||||
help='PLC Modbus port (default: 502)')
|
||||
parser.add_argument('--debug', action='store_true',
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "/home/paulg/FCI/api"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"python.defaultInterpreterPath": "/home/paulg/FCI/api/venv/bin/python",
|
||||
"python.terminal.activateEnvironment": true,
|
||||
"terminal.integrated.cwd": "/home/paulg/FCI/api"
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ def parse_args():
|
||||
help='Host to bind to (default: 0.0.0.0)')
|
||||
parser.add_argument('--port', type=int, default=5000,
|
||||
help='Port to bind to (default: 5000)')
|
||||
parser.add_argument('--plc-ip', default='192.168.1.15',
|
||||
help='PLC IP address (default: 192.168.1.15)')
|
||||
parser.add_argument('--plc-ip', default='198.18.100.141',
|
||||
help='PLC IP address (default: 198.18.100.141)')
|
||||
parser.add_argument('--plc-port', type=int, default=502,
|
||||
help='PLC Modbus port (default: 502)')
|
||||
parser.add_argument('--debug', action='store_true',
|
||||
|
||||
@@ -14,7 +14,7 @@ class Config:
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'watermaker-plc-api-dev-key')
|
||||
|
||||
# PLC Connection Settings
|
||||
PLC_IP = os.getenv('PLC_IP', '192.168.1.15')
|
||||
PLC_IP = os.getenv('PLC_IP', '198.18.100.141')
|
||||
PLC_PORT = int(os.getenv('PLC_PORT', '502'))
|
||||
PLC_UNIT_ID = int(os.getenv('PLC_UNIT_ID', '1'))
|
||||
PLC_TIMEOUT = int(os.getenv('PLC_TIMEOUT', '3'))
|
||||
|
||||
Reference in New Issue
Block a user