From 4ac97e7f96f3b7f1e0de605dce77cd6a4259143d Mon Sep 17 00:00:00 2001 From: Kimmo Huoman Date: Tue, 15 Oct 2024 21:54:06 +0300 Subject: [PATCH] Test and pylint -fixes (#38) * Test and pylint -fixes * Drop support for Python 3.9, just can't be arsed * Remove coveralls for now, need to check later * Remove pypy tests at least for now --- .github/workflows/python-test.yml | 31 ++++----- nordpool/base.py | 5 +- nordpool/elbas.py | 20 +++--- nordpool/elspot.py | 12 ++-- poetry.lock | 107 +++++++++++++++++++++++++++++- pyproject.toml | 4 +- 6 files changed, 141 insertions(+), 38 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index a2fa292..7ec8186 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -15,12 +15,9 @@ jobs: strategy: matrix: python-version: - - "3.9" - "3.10" - "3.11" - "3.12" - - "pypy-3.9" - - "pypy-3.10" steps: - uses: actions/checkout@v2 @@ -32,7 +29,7 @@ jobs: run: | python -m pip install --upgrade pip pip install poetry - poetry install --with test + poetry install --with dev - name: Lint run: | poetry run flake8 nordpool --max-line-length=88 @@ -40,17 +37,17 @@ jobs: - name: Run tests run: | poetry run coverage run -m unittest discover -b - - name: Coveralls - uses: AndreMiras/coveralls-python-action@develop - with: - parallel: true - flag-name: run-${{ matrix.test_number }} + # - name: Coveralls + # uses: AndreMiras/coveralls-python-action@develop + # with: + # parallel: true + # flag-name: run-${{ matrix.test_number }} - finish: - needs: test - runs-on: ubuntu-latest - steps: - - name: Coveralls Finished - uses: AndreMiras/coveralls-python-action@develop - with: - parallel-finished: true + # finish: + # needs: test + # runs-on: ubuntu-latest + # steps: + # - name: Coveralls Finished + # uses: AndreMiras/coveralls-python-action@develop + # with: + # parallel-finished: true diff --git a/nordpool/base.py b/nordpool/base.py index 11e146f..53afe3a 100644 --- a/nordpool/base.py +++ b/nordpool/base.py @@ -1,12 +1,13 @@ +# pylint: disable=missing-module-docstring from dateutil.parser import parse as parse_dt from pytz import timezone, utc -class CurrencyMismatch(ValueError): +class CurrencyMismatch(ValueError): # pylint: disable=missing-class-docstring pass -class Base(object): +class Base: # pylint: disable=too-few-public-methods """Class for fetching Nord Pool Elspot prices.""" def __init__(self, currency="EUR", timeout=None): diff --git a/nordpool/elbas.py b/nordpool/elbas.py index 461ad13..7e946b2 100644 --- a/nordpool/elbas.py +++ b/nordpool/elbas.py @@ -1,8 +1,5 @@ -# -*- encoding: utf-8 -*- -from __future__ import unicode_literals - +# pylint: disable=missing-module-docstring from datetime import date, datetime, timedelta -from socket import timeout import requests from dateutil.parser import parse as parse_dt @@ -16,7 +13,7 @@ class Prices(Base): HOURLY = 194 API_URL = "https://www.nordpoolgroup.com/api/marketdata/page/%i" - def _parse_json(self, data, columns, areas): + def _parse_json(self, data, columns, areas): # pylint: disable=too-many-branches """ Parse json response from fetcher. Returns dictionary with @@ -51,10 +48,9 @@ def _parse_json(self, data, columns, areas): # Loop through columns if r["Name"] is None: continue - else: - name = " ".join(r["Name"].split("-")).split(" ") + name = " ".join(r["Name"].split("-")).split(" ") # Picks only "PH" product (hourly) - if not (name[0] == "PH"): + if not name[0] == "PH": continue row_start_time = self._parse_dt( "-".join([name[1], format(int(name[2]) - 1, "02")]) @@ -118,7 +114,7 @@ def _fetch_json(self, data_type, areas, end_date=None): # Return JSON response return r.json() - def fetch(self, data_type, columns, end_date=None, areas=[]): + def fetch(self, data_type, columns, end_date=None, areas=None): """ Fetch data from API. Inputs: @@ -145,8 +141,10 @@ def fetch(self, data_type, columns, end_date=None, areas=[]): def hourly( self, end_date=None, - areas=[], - columns=["Product", "High", "Low", "Last", "Avg", "Volume"], + areas=None, + columns=None, ): """Helper to fetch hourly data, see Prices.fetch()""" + if columns is None: + columns = ["Product", "High", "Low", "Last", "Avg", "Volume"] return self.fetch(self.HOURLY, columns, end_date, areas) diff --git a/nordpool/elspot.py b/nordpool/elspot.py index 1becf64..dbc012b 100644 --- a/nordpool/elspot.py +++ b/nordpool/elspot.py @@ -1,3 +1,4 @@ +# pylint: disable=missing-module-docstring from datetime import date, datetime, timedelta from pytz import utc @@ -203,21 +204,24 @@ def yearly(self, end_date=None, areas=None): class AioPrices(Prices): + """Class for fetching Nord Pool Elspot prices.""" + + # pylint: disable=invalid-overridden-method + def __init__(self, currency, client): super().__init__(currency) self.client = client async def _io(self, url, params): - import inspect + import inspect # pylint: disable=import-outside-toplevel resp = await self.client.get(url, params=params) # aiohttp if inspect.isawaitable(resp.json()): return await resp.json() - else: - # Httpx and asks - return resp.json() + # Httpx and asks + return resp.json() async def _fetch_json(self, data_type, end_date=None, areas=None): """Fetch JSON from API""" diff --git a/poetry.lock b/poetry.lock index 95c0bbd..4aa4dd3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,19 @@ # This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +[[package]] +name = "astroid" +version = "3.3.5" +description = "An abstract syntax tree for Python with inference support." +optional = false +python-versions = ">=3.9.0" +files = [ + {file = "astroid-3.3.5-py3-none-any.whl", hash = "sha256:a9d1c946ada25098d790e079ba2a1b112157278f3fb7e718ae6a9252f5835dc8"}, + {file = "astroid-3.3.5.tar.gz", hash = "sha256:5cfc40ae9f68311075d27ef68a4841bdc5cc7f6cf86671b49f00607d30188e2d"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.11\""} + [[package]] name = "black" version = "24.10.0" @@ -267,9 +281,56 @@ files = [ {file = "coverage-7.6.3.tar.gz", hash = "sha256:bb7d5fe92bd0dc235f63ebe9f8c6e0884f7360f88f3411bfed1350c872ef2054"}, ] +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + [package.extras] toml = ["tomli"] +[[package]] +name = "coveralls" +version = "4.0.1" +description = "Show coverage stats online via coveralls.io" +optional = false +python-versions = "<3.13,>=3.8" +files = [ + {file = "coveralls-4.0.1-py3-none-any.whl", hash = "sha256:7a6b1fa9848332c7b2221afb20f3df90272ac0167060f41b5fe90429b30b1809"}, + {file = "coveralls-4.0.1.tar.gz", hash = "sha256:7b2a0a2bcef94f295e3cf28dcc55ca40b71c77d1c2446b538e85f0f7bc21aa69"}, +] + +[package.dependencies] +coverage = {version = ">=5.0,<6.0.dev0 || >6.1,<6.1.1 || >6.1.1,<8.0", extras = ["toml"]} +docopt = ">=0.6.1,<0.7.0" +requests = ">=1.0.0,<3.0.0" + +[package.extras] +yaml = ["pyyaml (>=3.10,<7.0)"] + +[[package]] +name = "dill" +version = "0.3.9" +description = "serialize all of Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "dill-0.3.9-py3-none-any.whl", hash = "sha256:468dff3b89520b474c0397703366b7b95eebe6303f108adf9b19da1f702be87a"}, + {file = "dill-0.3.9.tar.gz", hash = "sha256:81aa267dddf68cbfe8029c42ca9ec6a4ab3b22371d1c450abc54422577b4512c"}, +] + +[package.extras] +graph = ["objgraph (>=1.7.2)"] +profile = ["gprof2dot (>=2022.7.29)"] + +[[package]] +name = "docopt" +version = "0.6.2" +description = "Pythonic argument parser, that will make you smile" +optional = false +python-versions = "*" +files = [ + {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, +] + [[package]] name = "flake8" version = "7.1.1" @@ -607,6 +668,35 @@ files = [ {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, ] +[[package]] +name = "pylint" +version = "3.3.1" +description = "python code static checker" +optional = false +python-versions = ">=3.9.0" +files = [ + {file = "pylint-3.3.1-py3-none-any.whl", hash = "sha256:2f846a466dd023513240bc140ad2dd73bfc080a5d85a710afdb728c420a5a2b9"}, + {file = "pylint-3.3.1.tar.gz", hash = "sha256:9f3dcc87b1203e612b78d91a896407787e708b3f189b5fa0b307712d49ff0c6e"}, +] + +[package.dependencies] +astroid = ">=3.3.4,<=3.4.0-dev0" +colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} +dill = [ + {version = ">=0.2", markers = "python_version < \"3.11\""}, + {version = ">=0.3.7", markers = "python_version >= \"3.12\""}, + {version = ">=0.3.6", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, +] +isort = ">=4.2.5,<5.13.0 || >5.13.0,<6" +mccabe = ">=0.6,<0.8" +platformdirs = ">=2.2.0" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +tomlkit = ">=0.10.1" + +[package.extras] +spelling = ["pyenchant (>=3.2,<4.0)"] +testutils = ["gitpython (>3)"] + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -805,6 +895,17 @@ files = [ {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, ] +[[package]] +name = "tomlkit" +version = "0.13.2" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tomlkit-0.13.2-py3-none-any.whl", hash = "sha256:7a974427f6e119197f670fbbbeae7bef749a6c14e793db934baefc1b5f03efde"}, + {file = "tomlkit-0.13.2.tar.gz", hash = "sha256:fff5fe59a87295b278abd31bec92c15d9bc4a06885ab12bcea52c71119392e79"}, +] + [[package]] name = "typing-extensions" version = "4.12.2" @@ -864,7 +965,7 @@ files = [ PyYAML = "*" urllib3 = [ {version = "*", markers = "platform_python_implementation != \"PyPy\" and python_version >= \"3.10\""}, - {version = "<2", markers = "platform_python_implementation == \"PyPy\" or python_version < \"3.10\""}, + {version = "<2", markers = "platform_python_implementation == \"PyPy\""}, ] wrapt = "*" yarl = "*" @@ -1065,5 +1166,5 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.0" -python-versions = "^3.9" -content-hash = "f3ec30173dcfcb2d9a964bb83bef15e6d98eb87d058acb93bda6b253a6e0ab61" +python-versions = ">=3.10,<3.13" +content-hash = "694520606ca5cdc9d18c083a388f5a3fe0132861afa8dd17b130a75dded7c804" diff --git a/pyproject.toml b/pyproject.toml index 9a4e04c..547be2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ homepage = "https://github.com/kipe/nordpool" repository = "https://github.com/kipe/nordpool" [tool.poetry.dependencies] -python = "^3.9" +python = ">=3.10,<3.13" python-dateutil = "^2.9.0.post0" requests = "^2.32.3" pytz = "^2024.2" @@ -22,6 +22,8 @@ flake8 = "^7.1.1" vcrpy = "^6.0.2" time-machine = "^2.16.0" coverage = "^7.6.3" +coveralls = "^4.0.1" +pylint = "^3.3.1" [build-system] requires = ["poetry-core"]