Skip to content

Commit

Permalink
black, isort, pre-commit, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ldotlopez committed Nov 15, 2023
1 parent 571375f commit 8aa0ba1
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 32 deletions.
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: end-of-file-fixer
# exclude: '\.json$'
- id: trailing-whitespace
args: ['--markdown-linebreak-ext=md']
- id: check-json
- id: pretty-format-json
args: ['--autofix', '--no-sort-keys']
- id: check-toml
# - id: check-yaml
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
hooks:
- id: pyupgrade
args: ['--py39']

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ['--profile', 'black']

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ name = "pypi"
aiohttp = "<4.0,>=3.8"

[dev-packages]
black = "*"
build = "*"
ipdb = "*"
ipython = "*"
build = "*"
isort = "*"
mypy = "*"
pre-commit = "*"
twine = "*"

[requires]
Expand Down
16 changes: 16 additions & 0 deletions ideenergy.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,21 @@
}
],
"settings": {
"python_interpreter": "${project_path}/.venv/bin/python",

"sublack.black_command": "${project_path}/.venv/bin/black",
"sublack.black_on_save": true,

"isort.sort_on_save": true,

"SublimeLinter.linters.flake8.executable": "${project_path}/.venv/bin/flake8",
"SublimeLinter.linters.flake8.disable": true,

"SublimeLinter.linters.mypy.executable": "${project_path}/.venv/bin/mypy",
"SublimeLinter.linters.mypy.disable": false,
// "SublimeLinter.linters.mypy.args": ["--ignore-missing-imports"],

"SublimeLinter.linters.pycodestyle.executable": "${project_path}/.venv/bin/pycodestyle",
"SublimeLinter.linters.pycodestyle.disable": true,
}
}
6 changes: 2 additions & 4 deletions ideenergy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand All @@ -25,10 +23,10 @@
Client,
ClientError,
CommandError,
get_session,
InvalidContractError,
InvalidData,
RequestFailedError,
get_session,
)


Expand All @@ -38,7 +36,7 @@ def get_credentials(parsedargs=None, credentials=None, environ_prefix="IDEENERGY

credentials = credentials or getattr(parsedargs, "credentials", None)
if credentials:
with open(credentials, mode="r", encoding="utf-8") as fh:
with open(credentials, encoding="utf-8") as fh:
d = json.loads(fh.read())
return d["username"], d["password"]

Expand Down
3 changes: 1 addition & 2 deletions ideenergy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand All @@ -18,6 +16,7 @@
# USA.

import asyncio

from .cli import main

if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion ideenergy/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
Expand Down
17 changes: 8 additions & 9 deletions ideenergy/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand All @@ -26,6 +24,7 @@
from typing import Any, Dict, List, Optional, Union

import aiohttp

from . import parsers

_BASE_URL = "https://www.i-de.es/consumidores/rest"
Expand Down Expand Up @@ -74,7 +73,7 @@ class Measure:
accumulate: int
instant: float

def asdict(self) -> Dict[str, Union[int, float]]:
def asdict(self) -> dict[str, Union[int, float]]:
return dataclasses.asdict(self)


Expand Down Expand Up @@ -140,7 +139,7 @@ def auto_renew_user_session(self) -> bool:

async def request_json(
self, method: str, url: str, encoding: str = "utf-8", **kwargs
) -> Dict[Any, Any]:
) -> dict[Any, Any]:
buff = await self.request_bytes(method, url, **kwargs)
data = json.loads(buff.decode(encoding))
return data
Expand Down Expand Up @@ -211,7 +210,7 @@ async def is_icp_ready(self) -> bool:
return ret

@auth_required
async def get_contract_details(self) -> Dict[str, Any]:
async def get_contract_details(self) -> dict[str, Any]:
"""
{
"ape1Titular": "xxxxxx ",
Expand Down Expand Up @@ -279,7 +278,7 @@ async def get_contract_details(self) -> Dict[str, Any]:
return data

@auth_required
async def get_contracts(self) -> List[Dict[str, Any]]:
async def get_contracts(self) -> list[dict[str, Any]]:
"""
{
'success': true,
Expand Down Expand Up @@ -351,22 +350,22 @@ async def get_measure(self) -> Measure:

async def get_historical_consumption(
self, start: datetime, end: datetime
) -> Dict[str, Any]:
) -> dict[str, Any]:
return await self._get_historical_generic_data(
_CONSUMPTION_PERIOD_ENDPOINT, start, end
)

async def get_historical_generation(
self, start: datetime, end: datetime
) -> Dict[str, Any]:
) -> dict[str, Any]:
return await self._get_historical_generic_data(
_GENERATION_PERIOD_ENDPOINT, start, end
)

@auth_required
async def _get_historical_generic_data(
self, url_template: str, start: datetime, end: datetime
) -> Dict[Any, Any]:
) -> dict[Any, Any]:
start = min([start, end])
end = max([start, end])
url = url_template.format(start=start, end=end)
Expand Down
2 changes: 0 additions & 2 deletions ideenergy/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand Down
12 changes: 5 additions & 7 deletions ideenergy/parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand All @@ -18,13 +16,13 @@
# USA.


import itertools
import datetime
import itertools
from typing import Dict


def parser_generic_historical_data(data, base_dt: datetime.datetime) -> Dict:
def _normalize_historical_item(idx: int, item: Dict | None) -> Dict | None:
def parser_generic_historical_data(data, base_dt: datetime.datetime) -> dict:
def _normalize_historical_item(idx: int, item: dict | None) -> dict | None:
if item is None:
return None

Expand Down Expand Up @@ -53,8 +51,8 @@ def _normalize_historical_item(idx: int, item: Dict | None) -> Dict | None:
}


def parse_historical_power_demand_data(data) -> Dict:
def _normalize_power_spike_item(item: Dict):
def parse_historical_power_demand_data(data) -> dict:
def _normalize_power_spike_item(item: dict):
return {
"dt": datetime.datetime.strptime(item["name"], "%d/%m/%Y %H:%M"),
"value": item["y"],
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[metadata]
name = ideenergy
version = 1.0.0
version = 1.0.2
author = Luis López
author_email = [email protected]
description = Interface to i-de.es energy data
Expand Down
6 changes: 2 additions & 4 deletions tests/generate-fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
Expand All @@ -20,11 +19,10 @@


import asyncio
from ideenergy import client
from ideenergy import get_credentials, get_session

from datetime import datetime, timedelta

from ideenergy import client, get_credentials, get_session


async def main():
u, p = get_credentials(credentials="credentials.json")
Expand Down
1 change: 0 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (C) 2021-2022 Luis López <[email protected]>
#
Expand Down

0 comments on commit 8aa0ba1

Please sign in to comment.