diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..bb272cb --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,55 @@ +--- +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +change-template: '- #$NUMBER $TITLE' +sort-direction: ascending +exclude-contributors: + - 'github-actions[bot]' + - 'github-actions' + - 'renovate[bot]' + - 'renovate' + - 'pre-commit-ci' + - 'pre-commit-ci[bot]' + - 'crowdin-bot' +exclude-labels: + - 'skip-changelog' + - 'dependencies' +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +autolabeler: + - label: 'ci/cd' + files: + - '/.github/**/*' + - label: 'documentation' + files: + - '*.md' + - '/docs/*' + branch: + - '/docs{0,1}\/.+/' + - label: 'bug' + branch: + - '/fix\/.+/' + title: + - '/fix/i' + - label: 'enhancement' + branch: + - '/feature\/.+/' + body: + - '/JIRA-[0-9]{1,4}/' +commitish: refs/heads/main +template: | + ## 🚀 Changes + + $CHANGES + + ## ❤️ Contributors + $CONTRIBUTORS diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..9e1259a --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,37 @@ +--- +name: "Lint" + +on: + # push: + pull_request: + # schedule: + # - cron: "0 0 * * *" + +jobs: + lint: + name: Lint + runs-on: "ubuntu-latest" + steps: + - name: "Checkout the repository" + uses: actions/checkout@v4 + + - name: "Set up Python" + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: "Install requirements" + run: python3 -m pip install -r requirements.txt + + - name: "Install linters" + run: python3 -m pip install ruff yamllint + + - name: "ruff check ." + run: python3 -m ruff check . + + # - name: yaml-lint + # uses: ibiqlik/action-yamllint@v3 + # with: + # # file_or_dir: myfolder/*values*.yaml + # config_file: .yamllint.yaml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index ba520d3..ac5500d 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,7 +13,7 @@ on: tags: - v** release: - types: [created] + types: [published] permissions: contents: read diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..703b511 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,35 @@ +--- +name: Release Drafter + +on: + push: + branches: [main, master] + pull_request: + types: [opened, reopened, synchronize] + workflow_dispatch: + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + # write permission is required to create a github release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write + name: Update release draft + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create Release + uses: release-drafter/release-drafter@v6 + with: + disable-releaser: github.ref != 'refs/heads/main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/sourcery-for-codebase.yaml b/.github/workflows/sourcery-for-codebase.yaml new file mode 100644 index 0000000..df65e3a --- /dev/null +++ b/.github/workflows/sourcery-for-codebase.yaml @@ -0,0 +1,22 @@ +--- +name: Sourcery (for Codebase) + +on: + push: + branches: [main, master] + workflow_dispatch: + +jobs: + review-codebase-with-sourcery: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + # https://github.com/sourcery-ai/action + - uses: sourcery-ai/action@v1 + with: + token: ${{ secrets.SOURCERY_TOKEN }} diff --git a/.github/workflows/sourcery-for-pr.yaml b/.github/workflows/sourcery-for-pr.yaml new file mode 100644 index 0000000..3b2c69b --- /dev/null +++ b/.github/workflows/sourcery-for-pr.yaml @@ -0,0 +1,23 @@ +--- +name: Sourcery (for PR) + +on: + pull_request: + +jobs: + review-pr-with-sourcery: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + + # https://github.com/sourcery-ai/action + - uses: sourcery-ai/action@v1 + with: + token: ${{ secrets.SOURCERY_TOKEN }} + diff_ref: ${{ github.event.pull_request.base.sha }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3797bfe --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +--- +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.7 + hooks: + - id: ruff + args: + - --fix + - id: ruff-format + files: ^((pyopenhardwaremonitor|tests)/.+)?[^/]+\.(py|pyi)$ + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.35.1 + hooks: + - id: yamllint + language: python + types: [file, yaml] + files: ^((pyopenhardwaremonitor|tests)/.+)?[^/]+\.(yaml|yml)$ + + - repo: https://github.com/sourcery-ai/sourcery + rev: v1.34.0 + hooks: + - id: sourcery + # The best way to use Sourcery in a pre-commit hook: + # * review only changed lines: + # * omit the summary + args: [--diff=git diff HEAD, --no-summary] + stages: [pre-push] diff --git a/.sourcery.yaml b/.sourcery.yaml new file mode 100644 index 0000000..aa91b23 --- /dev/null +++ b/.sourcery.yaml @@ -0,0 +1,86 @@ +# 🪄 This is your project's Sourcery configuration file. + +# You can use it to get Sourcery working in the way you want, such as +# ignoring specific refactorings, skipping directories in your project, +# or writing custom rules. + +# 📚 For a complete reference to this file, see the documentation at +# https://docs.sourcery.ai/Configuration/Project-Settings/ + +# This file was auto-generated by Sourcery on 2025-02-25 at 16:44. +# EDIT: With some manual edits made to adhere to yamllint. +--- +version: '1' # The schema version of this config file + +ignore: # A list of paths or files which Sourcery will ignore. + - .git + - env + - .env + - .tox + - node_modules + - vendor + - venv + - .venv + - ~/.pyenv + - ~/.rye + - ~/.vscode + - .vscode + - ~/.cache + - ~/.config + - ~/.local + +rule_settings: + enable: + - default + disable: [] # A list of rule IDs Sourcery will never suggest. + rule_types: + - refactoring + - suggestion + - comment + + # A string specifying the lowest Python version your project supports. + # Sourcery will not suggest refactorings requiring a higher Python version. + python_version: '3.11' + +# rules: # A list of custom rules Sourcery will include in its analysis. +# - id: no-print-statements +# description: Do not use print statements in the test directory. +# pattern: print(...) +# language: python +# replacement: +# condition: +# explanation: +# paths: +# include: +# - test +# exclude: +# - conftest.py +# tests: [] +# tags: [] + +# rule_tags: {} # Additional rule tags. + +# metrics: +# quality_threshold: 25.0 + +# github: +# labels: [] +# ignore_labels: +# - sourcery-ignore +# request_review: author +# sourcery_branch: sourcery/{base_branch} + +# clone_detection: +# min_lines: 3 +# min_duplicates: 2 +# identical_clones_only: false + +# proxy: +# url: +# ssl_certs_file: +# no_ssl_verify: false + +# coding_assistant: +# project_description: '' +# enabled: true +# recipe_prompts: {} diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..7214609 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,5 @@ +--- +extends: default +rules: + truthy: + check-keys: false diff --git a/FUNDING.yml b/FUNDING.yml index ebba2a5..05a574c 100644 --- a/FUNDING.yml +++ b/FUNDING.yml @@ -1,4 +1,4 @@ # These are supported funding model platforms - +--- github: lazytarget -custom: "https://paypal.me/peteraslund" \ No newline at end of file +custom: "https://paypal.me/peteraslund" diff --git a/example.py b/example.py index 1b24798..9d35629 100644 --- a/example.py +++ b/example.py @@ -28,12 +28,13 @@ async def main(host=None, port=8085): def get_current_ip() -> str: """Gets the local IP-address of this machine""" import socket + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) return str(s.getsockname()[0]) -if __name__ == '__main__': +if __name__ == "__main__": # if running on Windows asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) diff --git a/pyopenhardwaremonitor/api.py b/pyopenhardwaremonitor/api.py index 58288be..2afbf2f 100644 --- a/pyopenhardwaremonitor/api.py +++ b/pyopenhardwaremonitor/api.py @@ -12,7 +12,6 @@ class OpenHardwareMonitorAPI: - DEFAULT_TIMEOUT = 10 def __init__( @@ -23,7 +22,7 @@ def __init__( session=None, timeout=DEFAULT_TIMEOUT, retry_count=3, - retry_delay=None + retry_delay=None, ): self._timeout = timeout self._close_session = False @@ -35,7 +34,9 @@ def __init__( self._close_session = True self._retry_count = retry_count - self._retry_delay = retry_delay or (lambda attempt: 3**attempt + random.uniform(0, 3)) + self._retry_delay = retry_delay or ( + lambda attempt: 3**attempt + random.uniform(0, 3) + ) self.API_URL = URL(f"http://{host}:{port}/") @@ -76,11 +77,16 @@ async def raw_request( # pylint: disable=too-many-arguments delay = self._retry_delay(attempt) _LOGGER.info("Request limit exceeded, retrying in %s second", delay) await asyncio.sleep(delay) - return await self.raw_request(uri, params, data, method, attempt=attempt + 1) + return await self.raw_request( + uri, params, data, method, attempt=attempt + 1 + ) raise OpenHardwareMonitorError("Request limit exceeded") content = None - if "Content-Type" in response.headers and "application/json" in response.headers["Content-Type"]: + if ( + "Content-Type" in response.headers + and "application/json" in response.headers["Content-Type"] + ): content = await response.json() else: content = await response.read() diff --git a/setup.py b/setup.py index ab3a81c..8f9817c 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,6 @@ "Programming Language :: Python :: 3", "Topic :: Home Automation", "Topic :: Software Development :: Libraries :: Python Modules", - "License :: OSI Approved :: MIT License" + "License :: OSI Approved :: MIT License", ], )