Skip to content

Commit

Permalink
Migrate to development with Poetry (#45)
Browse files Browse the repository at this point in the history
* Move to Poetry dev environment

* Move package code to src folder

* Move examples to seperate folder

* Update development environment setup in README.md

* Add and run black

* Update CI tests workflow to use Poetry

* Bump minimal python version to 3.11

* Update coverage report fail_under threshold to 60

* add blank line to file
  • Loading branch information
klaasnicolaas authored Apr 26, 2024
1 parent f7fa998 commit 6e53f8e
Show file tree
Hide file tree
Showing 13 changed files with 1,048 additions and 58 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ jobs:

steps:
- uses: actions/[email protected]
- name: 🏗 Set up Poetry
run: pipx install poetry
- name: Set up Python 3.11
uses: actions/[email protected]
with:
python-version: 3.11
- name: Install dependencies
- name: 🏗 Install workflow dependencies
run: |
pip install .
pip install -r requirements-test.txt
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: 🏗 Install dependencies
run: poetry install --no-interaction
- name: Lint with flake8
run: |
flake8 forecast_solar
- name: Run tests
poetry run flake8 src/forecast_solar
- name: 🚀 Run pytest
run: |
pytest tests
poetry run pytest -v --cov src tests
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ Would you like to contribute to the development of this project? Then read the p

Thank you for being involved! :heart_eyes:

## Setting up development environment

This Python project relies on [Poetry][poetry] as its dependency manager,
providing comprehensive management and control over project dependencies.

You need at least:

- Python 3.11+
- [Poetry][poetry-install]

Install all packages, including all development requirements:

```bash
poetry install
```

Poetry creates by default an virtual environment where it installs all
necessary pip packages, to enter or exit the venv run the following commands:

```bash
poetry shell
exit
```

To run just the Python tests:

```bash
poetry run pytest
```

## License

MIT License
Expand Down Expand Up @@ -149,3 +179,6 @@ SOFTWARE.
[commits-shield]: https://img.shields.io/github/commit-activity/y/home-assistant-libs/forecast_solar.svg?style=for-the-badge
[commits]: https://github.com/home-assistant-libs/forecast_solar/commits/master
[last-commit-shield]: https://img.shields.io/github/last-commit/home-assistant-libs/forecast_solar.svg?style=for-the-badge

[poetry-install]: https://python-poetry.org/docs/#installation
[poetry]: https://python-poetry.org
File renamed without changes.
915 changes: 915 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[tool.poetry]
name = "forecast-solar"
version = "0.0.0"
description = "Asynchronous Python client for getting forecast solar information"
authors = ["Klaas Schoute <[email protected]>"]
maintainers = ["Klaas Schoute <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/home-assistant-libs/forecast_solar"
repository = "https://github.com/home-assistant-libs/forecast_solar"
documentation = "https://github.com/home-assistant-libs/forecast_solar"
keywords = ["forecast", "solar", "power", "energy", "api", "async", "client"]
classifiers = [
"Framework :: AsyncIO",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
]
packages = [
{ include = "forecast_solar", from = "src" },
]

[tool.poetry.dependencies]
aiohttp = ">=3.0.0"
aiodns = ">=3.0.0"
python = "^3.11"
yarl = ">=1.6.0"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/home-assistant-libs/forecast_solar/issues"
Changelog = "https://github.com/home-assistant-libs/forecast_solar/releases"

[tool.poetry.group.dev.dependencies]
black = "24.4.2"
covdefaults = "2.3.0"
coverage = {version = "7.5.0", extras = ["toml"]}
flake8 = "7.0.0"
pytest = "8.1.1"
pytest-asyncio = "0.23.6"
pytest-cov = "5.0.0"

[tool.coverage.run]
plugins = ["covdefaults"]
source = ["forecast_solar"]

[tool.coverage.report]
fail_under = 60
show_missing = true

[tool.pytest.ini_options]
addopts = "--cov"
asyncio_mode = "auto"

[build-system]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]
2 changes: 0 additions & 2 deletions requirements-test.txt

This file was deleted.

50 changes: 0 additions & 50 deletions setup.py

This file was deleted.

25 changes: 25 additions & 0 deletions src/forecast_solar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Asynchronous Python client for the Forecast.Solar API."""

from .exceptions import (
ForecastSolarError,
ForecastSolarConnectionError,
ForecastSolarConfigError,
ForecastSolarAuthenticationError,
ForecastSolarRequestError,
ForecastSolarRatelimit,
)
from .models import Estimate, AccountType, Ratelimit
from .forecast_solar import ForecastSolar

__all__ = [
"AccountType",
"Estimate",
"ForecastSolar",
"ForecastSolarAuthenticationError",
"ForecastSolarConfigError",
"ForecastSolarConnectionError",
"ForecastSolarError",
"ForecastSolarRatelimit",
"ForecastSolarRequestError",
"Ratelimit",
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exceptions for Forecast.Solar."""

from datetime import datetime


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Asynchronous Python client for the Forecast.Solar API."""

from __future__ import annotations

from collections.abc import Mapping
Expand Down
1 change: 1 addition & 0 deletions forecast_solar/models.py → src/forecast_solar/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data models for the Forecast.Solar API."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests."""

from datetime import datetime
from unittest.mock import patch, Mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the models."""

from datetime import datetime
from forecast_solar import models
from . import PAYLOAD, patch_now, patch_previous_day, patch_near_end_today
Expand Down

0 comments on commit 6e53f8e

Please sign in to comment.