diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..62ab8f9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,45 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +pip-log.txt +pip-delete-this-directory.txt +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.git +.mypy_cache +.pytest_cache +.hypothesis + +# Local environment +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +dist/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f777af1 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# Copy this to .env and fill in your credentials +CHECKWATT_USERNAME=your_eib_username +CHECKWATT_PASSWORD=your_eib_password \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8cb124e..a9a55ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ dist/ __pycache__/ pipx_shared.pth -cw_test.py \ No newline at end of file +cw_test.py +.env \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..b9c3e2c --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,16 @@ +FROM python:3.11-slim + +WORKDIR /app +# Dependencies +RUN pip install --no-cache-dir poetry +COPY pyproject.toml poetry.lock ./ + +RUN poetry config virtualenvs.create false \ + && poetry install --only main --no-root --no-interaction --no-ansi + +# Dev dependencies +RUN pip install black flake8 + +ENV PYTHONPATH="${PYTHONPATH}:/app" + +CMD ["python"] \ No newline at end of file diff --git a/README.md b/README.md index 028cf4c..b1e91ec 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,39 @@ Export: 668.539 kWh ``` +## Docker Development + +For developers who prefer not to install Python locally, a Docker-based development environment is available. + +### Prerequisites + +- Docker and Docker Compose installed +- CheckWatt EnergyInBalance credentials + +### Quick Start + +1. **Set up credentials** + ```bash + cp .env.example .env + # Edit .env with your CheckWatt credentials + ``` + +2. **Build, run & cleanup** + ```bash + # Build the development container + docker compose -f docker-compose.dev.yml build + + # Run the example + docker compose -f docker-compose.dev.yml run --rm pycheckwatt-dev python examples/example.py + + # Clean up containers + docker compose -f docker-compose.dev.yml down + ``` + +Inside the container local code changes are automatically synced and you can run standard Python development commands. + + + # Acknowledgements This module was developed as a team effort by the following contributors. diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..efebec4 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,18 @@ +services: + pycheckwatt-dev: + build: + context: . + dockerfile: Dockerfile.dev + volumes: + - .:/app + - pip-cache:/root/.cache/pip + environment: + - CHECKWATT_USERNAME=${CHECKWATT_USERNAME:-} + - CHECKWATT_PASSWORD=${CHECKWATT_PASSWORD:-} + - PYTHONPATH=/app + stdin_open: true + tty: true + working_dir: /app + +volumes: + pip-cache: \ No newline at end of file diff --git a/examples/example.py b/examples/example.py index b85b955..d78bac5 100644 --- a/examples/example.py +++ b/examples/example.py @@ -2,14 +2,14 @@ import argparse import json +import os from pycheckwatt import CheckwattManager async def main(show_details=False): - """Fetch username and password from environment variables.""" - username = "EIB username" - password = "EiB password" + username = os.getenv("CHECKWATT_USERNAME") + password = os.getenv("CHECKWATT_PASSWORD") # Create the async class async with CheckwattManager(username, password) as check_watt_instance: