Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[flake8]
ignore =
# line too long
E501,

# insecure use of "random" module, prefer "random.SystemRandom",
DUO102,

# Standard pseudo-random generators are not suitable for security/cryptographic purposes
S311

exclude =
# No need to traverse our git directory
.git,
# There's no value in checking cache directories
__pycache__,
# The conf file is mostly autogenerated, ignore it
docs/source/conf.py,
# This contains our built documentation
build,
# This contains builds of flake8 that we don't want to check
dist,
# This folder is for local debugging
.venv
55 changes: 55 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions .github/workflows/code-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
env:
SRC_FOLDER: openhardwaremonitor
SRC_FOLDER: pyopenhardwaremonitor
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
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: "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
5 changes: 4 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
name: Upload Python Package

on:
push:
tags:
- v**
release:
types: [created]
types: [published]

permissions:
contents: read
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
22 changes: 22 additions & 0 deletions .github/workflows/sourcery-for-codebase.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
23 changes: 23 additions & 0 deletions .github/workflows/sourcery-for-pr.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These are supported funding model platforms

---
github: lazytarget
custom: "https://paypal.me/peteraslund"
custom: "https://paypal.me/peteraslund"
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ Python3 library for getting data from [Open Hardware Monitor](https://openhardwa
## Install

```
pip3 install pyOpenHardwareMonitor
pip3 install pyopenhardwaremonitor
```

## Example
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Mention the new example file.

Consider adding a sentence like "A more detailed example can be found in example.py" to the README to point readers to the new example file.

Suggested change
## Example
## Example
A more detailed example can be found in `example.py`


```
import asyncio
import json
from openhardwaremonitor import OpenHardwareMonitor
from pyopenhardwaremonitor.api import OpenHardwareMonitorAPI

async def main():
ohm = OpenHardwareMonitor('192.168.1.114', 8085)
ohm = OpenHardwareMonitorAPI('192.168.1.114', 8085)
data = await ohm.get_data()
json.dumps(data)
await ohm._api.close()
print(json.dumps(data))
await ohm.close()

if __name__ == '__main__':
asyncio.run(main())

```

For a more detailed example, see `example.py`
42 changes: 42 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import asyncio
import json
from pyopenhardwaremonitor.api import OpenHardwareMonitorAPI


async def main(host=None, port=8085):
"""Main example on using pyOpenHardwareMonitor"""
host = host or get_current_ip()
print("Running against: ", host, port)

# Example when using `async with` syntax
async with OpenHardwareMonitorAPI(host, port) as api:
data = await api.get_data()
j = json.dumps(data)
print(j)
return j

# Example with explicit method calls
# api = OpenHardwareMonitorAPI(host, port)
# data = await api.get_data()
# await api.close()
# j = json.dumps(data)
# print(j)
# return j


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 running on Windows
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

# Run main with async
asyncio.run(main())
14 changes: 0 additions & 14 deletions main.py

This file was deleted.

3 changes: 0 additions & 3 deletions openhardwaremonitor/const.py

This file was deleted.

11 changes: 0 additions & 11 deletions openhardwaremonitor/openhardwaremonitor.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""Library to handle connection with a Open Hardware Monitor remote server"""

from .openhardwaremonitor import OpenHardwareMonitor
Loading
Loading