Skip to content

Commit

Permalink
Add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikos committed Dec 13, 2023
1 parent 5f3e3f9 commit 492cfbc
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 49 deletions.
49 changes: 25 additions & 24 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# https://github.com/actions/starter-workflows/blob/main/ci/python-package.yml
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
Expand All @@ -6,9 +7,9 @@ name: Python package

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
workflow_dispatch:

jobs:
Expand All @@ -21,25 +22,25 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install flake8 pytest ruff
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --show-source --statistics
- name: Lint with ruff
run: |
ruff .
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install flake8 pytest ruff
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --show-source --statistics
- name: Lint with ruff
run: |
ruff .
- name: Test with pytest
run: |
pytest
32 changes: 16 additions & 16 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
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
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
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
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
7 changes: 7 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Default state for all rules
default: true

MD013: false # Disable line-length checking
MD033:
allowed_elements: [img] # Allow embedded image tags as there is no way to resize images in native markdown
65 changes: 65 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
exclude: '_pb2.py|_pb2_grpc.py'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: forbid-submodules
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.13.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.12.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: [--fix]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.33.0
hooks:
- id: yamllint
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.38.0
hooks:
- id: markdownlint
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell

ci:
autoupdate_schedule: monthly
9 changes: 9 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
extends: default

rules:
line-length:
level: warning
allow-non-breakable-inline-mappings: true
truthy:
check-keys: false
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with TextAssistant(credentials) as assistant:
## Limitations/Known issues

If you see the issued commands in [My Google Activity](https://myactivity.google.com/myactivity) the library is working fine. If the commands don't have the expected outcome, don't open an issue in this repository. You should instead report the issue directly to Google [here](https://github.com/googlesamples/assistant-sdk-python/issues). Examples of known Google Assistant API issues:

- Broadcast commands don't work unless speakers and device that runs this library are in the same network and IPv6 is disabled in the router
- Most queries for media controls don't work
- not working: e.g. play music on kitchen speaker, stop kitchen speaker
Expand Down Expand Up @@ -52,15 +53,14 @@ python -m pip install .
python -m pip install grpcio-tools
python -m grpc_tools.protoc -Isrc --python_out=src --grpc_python_out=src src/google/assistant/embedded/v1alpha2/embedded_assistant.proto

# Run formatter
python -m pip install isort black
isort .
black .
# Run pre-commit
python -m pip install pre-commit
pre-commit install
pre-commit run --all-files

# Run lint
python -m pip install flake8 ruff
flake8 .
ruff .
# Alternative: run formatter, lint
python -m pip install isort black flake8 ruff
isort . ; black . ; flake8 . ; ruff . --fix

# Run tests
python -m pip install pytest
Expand Down
2 changes: 1 addition & 1 deletion demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _main(
verbose,
grpc_deadline,
*args,
**kwargs
**kwargs,
):
system_browser = browser_helpers.system_browser
# Setup logging.
Expand Down

0 comments on commit 492cfbc

Please sign in to comment.