Skip to content

Commit

Permalink
Merge pull request #32 from yozik04/2.0.0
Browse files Browse the repository at this point in the history
Refactor codebase and update dependencies
  • Loading branch information
yozik04 authored Jul 28, 2024
2 parents 3c0cde9 + 0e83d23 commit b369988
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 328 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '35 10 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
35 changes: 35 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Coverage

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pytest pytest-cov pytest-asyncio
- name: Coverage
run: |
python -m pip install .
pytest tests/ --cov=nextion --cov-report=xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
62 changes: 0 additions & 62 deletions .github/workflows/python-package.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish release to PyPi

on:
release:
types: [published]

jobs:
test:
name: Test
uses: ./.github/workflows/test.yml
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Check versions match
run: |
PUBLISHING_VERSION=${{ github.event.release.tag_name }}
grep -qE '__version__ = "'$PUBLISHING_VERSION'"' nextion/__init__.py
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test and Lint

on:
workflow_call:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade flake8 tox
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test
run: tox
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__pycache__
/venv
/.idea
.tox
*.egg-info
59 changes: 59 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=lf"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
args:
- --safe
- --quiet

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: python-check-mock-methods
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nextion serial client [![Build](https://github.com/yozik04/nextion/actions/workflows/python-package.yml/badge.svg)](https://github.com/yozik04/nextion/actions/workflows/python-package.yml)
Lightweight Python 3.6+ async library to control Nextion displays.
Lightweight Python 3.8+ async library to control Nextion displays.

## Installation
### Pypi
Expand All @@ -16,34 +16,34 @@ from nextion import Nextion, EventType
class App:
def __init__(self):
self.client = Nextion('/dev/ttyS1', 9600, self.event_handler)

# Note: async event_handler can be used only in versions 1.8.0+ (versions 1.8.0+ supports both sync and async versions)
async def event_handler(self, type_, data):
if type_ == EventType.STARTUP:
print('We have booted up!')
elif type_ == EventType.TOUCH:
print('A button (id: %d) was touched on page %d' % (data.component_id, data.page_id))

logging.info('Event %s data: %s', type, str(data))

print(await self.client.get('field1.txt'))

async def run(self):
await self.client.connect()

# await client.sleep()
# await client.wakeup()

# await client.command('sendxy=0')

print(await self.client.get('sleep'))
print(await self.client.get('field1.txt'))

await self.client.set('field1.txt', "%.1f" % (random.randint(0, 1000) / 10))
await self.client.set('field2.txt', "%.1f" % (random.randint(0, 1000) / 10))

await self.client.set('field3.txt', random.randint(0, 100))

print('finished')

if __name__ == '__main__':
Expand Down Expand Up @@ -81,7 +81,7 @@ Get current set encoding (Not fetched from the device)

## Event handling

```event_handler``` method in the example above will be called on every event comming from the display.
```event_handler``` method in the example above will be called on every event coming from the display.

| EventType | Data | Data attributes |
|------------------|----------------------------|------------------------------------|
Expand All @@ -101,7 +101,7 @@ If you installed the library you should have `nextion-fw-upload` command in your
nextion-fw-upload -h
```

Otherwise use next command in the root of the project:
Otherwise use next command in the root of the project:
```bash
python -m nextion.console_scripts.upload_firmware -h
```
Expand Down
Loading

0 comments on commit b369988

Please sign in to comment.