Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff #100

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 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
17 changes: 0 additions & 17 deletions .flake8

This file was deleted.

18 changes: 8 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install coverage
pip install -r requirements.txt
pip install .$(python scripts/extract_dependencies.py --exclude doc dev midi)
- name: Install and pack web ui assets
run: |
npm install
Expand Down Expand Up @@ -55,7 +54,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

flake8:
lint:
runs-on: ubuntu-latest

steps:
Expand All @@ -67,11 +66,10 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r requirements.txt
- name: Check code style with flake8
pip install .$(python scripts/extract_dependencies.py --exclude doc test)
- name: Lint code with ruff
run: |
flake8
ruff check .

mypy:
runs-on: ubuntu-latest
Expand All @@ -85,8 +83,7 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
pip install -r requirements.txt
pip install .$(python scripts/extract_dependencies.py --exclude doc dev)
- name: Check typing with MyPy
run: |
mypy
Expand All @@ -103,7 +100,8 @@ jobs:
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
mkdir _static
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want this here to avoid the warning?

WARNING: html_static_path entry '_static' does not exist

pip install .$(python scripts/extract_dependencies.py --exclude test dev)
- name: Build HTML docs with Sphinx
run: |
cd docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build
pip install build
- name: Create source and wheel dist
run: |
python -m build
Expand Down
3 changes: 2 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sphinx:

python:
install:
- requirements: requirements.txt
command: |
pip install .$(python scripts/extract_dependencies.py --exclude test dev)
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Read more about SHC's base concepts [in the documentation](https://smarthomeconn
pip3 install smarthomeconnect
```
It will be only install smarthomeconnect and the dependencies of its core features.
Additional depdencies are required for certain interface modules and can be installed via pip's/setuptool's 'extras' feature.
Additional dependencies are required for certain interface modules and can be installed via pip's/setuptool's 'extras' feature.
See [Depdencies section](#Dependencies) of this readme for a complete list.
If you install SHC from a source distribution (in contrast to a "binary" package, such as a "wheel" package from PyPI), you'll need NodeJS and npm installed on your machine, which are used to download the web UI assets during the Python package building process.

Expand Down Expand Up @@ -206,13 +206,23 @@ If you want to help with the development of *Smart Home Connect*, your Pull Requ
### Development setup

Setting up a dev environment for SHC is simple:
Clone the git repository and install the development dependencies, listed in `requirements.txt` (+ the `python-rtmidi` module if you want to run the MIDI tests).
These include all dependencies of smarthomeconnect with all extras:
Clone the git repository and install the development dependencies.
```bash
git clone https://github.com/mhthies/smarthomeconnect
cd smarthomeconnect
pip3 install -r requirements.txt
pip3 install python-rtmidi
pip3 install -e .[dev]
```
To install additional dependencies, listed in [Dependencies](#dependencies), e.g. use:
```bash
pip3 install -e .[mysql,knxdclient,midi]
```

Use the convenient script `extract_dependencies.py` to get a list of all available dependencies
or use it to install all or some of the dependencies only:
```bash
python3 scripts/extract_dependencies.py # list all dependencies
pip3 install .$(python scripts/extract_dependencies.py) # install all dependencies
pip3 install .$(python scripts/extract_dependencies.py --exclude midi test) # install all dependencies except for midi and test
```
You may want to use a virtual environment to avoid messing up your Python packages.

Expand All @@ -235,6 +245,7 @@ npx parcel web_ui_src/main.js --dist-dir shc/web/static/pack --public-url ./

Please make sure that all the unittests are passing, when submitting a Pull Request:
```bash
pip3 install -e .[test]
python3 -m unittest
```
The web tests require Firefox and `geckodriver` to be installed on your system and the frontend assets.
Expand All @@ -247,7 +258,20 @@ coverage html
# open htmlcov/index.html
```

We also enforce static type correctness with MyPy and Python codestyle rules with flake8.
To run the static type checks and codestyle checks locally, simply install MyPy and flake8 and execute the `mypy` and `flake8` commands in the shc project repository.
We also enforce static type correctness with MyPy and Python codestyle rules with ruff.
To run the static type checks and codestyle checks locally, simply install MyPy and flake8 and execute the `mypy` command in the shc project repository.

To run code linting and formating checks, using `ruff`:
```bash
ruff check . # for linting checks
ruff format --check . # for formating checks
```
All these checks are also performed by the GitHub Actions CI for Pull Requests and the master branch.

To fix errors using `ruff` use these commands:
```bash
ruff check . -- fix # for fixing linting errors
ruff format . # for fixing formating errors
```
Note that not all errors can be fixed automatically but may need your attentions.

34 changes: 0 additions & 34 deletions mypy.ini

This file was deleted.

135 changes: 134 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,136 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "smarthomeconnect"
version = "0.9.0"
description = "The Smart Home Connect home automation framework based on AsyncIO"
license = {file = "LICENSE"}
readme = "README.md"
authors = [{name = "Michael Thies", email = "mail@mhthies.de"}]
requires-python = ">=3.7"
dependencies = [
"aiohttp>=3.6,<4",
"jinja2>=2.11,<4",
"MarkupSafe>=1.1,<3",
]

[tool.setuptools]
packages = ["shc"]

[project.optional-dependencies]
mysql = ["aiomysql>=0.0.21,<=0.2.0"]
knx = ["knxdclient>=0.4.0,<2"]
dmx = ["pyserial-asyncio>=0.3,<0.7"]
midi = ["mido>=1.2.9,<2", "python-rtmidi>=1.4.6,<2"]
mqtt = ["aiomqtt>=2.0.0,<3"]
pulse = ["pulsectl_asyncio>=1.0.0,<2"]
telegram = ["aiogram>=3.0,<4"]
file_persistence = ["aiofile>=3.7.4,<4"]
dev = ["ruff~=0.8"]
test = [
"coverage~=7.6",
"mypy~=1.13",
"selenium>=3.141,<5",
"types-PyMySQL",
"types-MarkupSafe>=1.1,<3",
"types-Jinja2>=2.11,<3",
]
doc = [
"sphinx~=5.0",
"sphinx-rtd-theme~=2.0",
"sphinx-toolbox~=3.5",
"sphinxcontrib-httpdomain~=1.8",
]

[tool.ruff]
line-length = 120
output-format = "concise"
exclude = [
".cache",
".git",
"dist",
"docs",
"htmlcov",
"node_modules",
"venv",
"venv*",
".mypy_cache",
"test/assets",
]

[tool.ruff.lint]
# Enable checks for Pycodestyle, Pyflakes, Bugbear, Docstrings and Import sorting
select = ["E", "F", "B", "D", "I"]
ignore = [
Copy link
Contributor Author

@jo47011 jo47011 Dec 4, 2024

Choose a reason for hiding this comment

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

TBD all these errors occur, currently disabled so we could merge the current state.
As proposed we can enable and fix them one by one in step 3. Some are easy to auto-fix

"B006", # Do not use mutable data structures for argument defaults
"B007", # Loop control variable `i` not used within loop body
"B012", # `return` inside `finally` blocks cause exceptions to be silenced
"B015", # Pointless comparison. Did you mean to assign a value? Otherwise, prepend `assert` or remove it. # FIXME: enable again
"B018", # Found useless expression. Either assign it to a variable or remove it. # FIXME: enable again
"B023", # Function definition does not bind loop variable `spec`
"B024", # abstract base class, but it has no abstract methods or properties
"B027", # empty method in an abstract base class, but has no abstract decorator
"B028", # No explicit `stacklevel` keyword argument found
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
"D100", # Missing docstring in public module # FIXME: enable again
"D101", # Missing docstring in public class # FIXME: enable again
"D102", # Missing docstring in public method # FIXME: enable again
"D103", # Missing docstring in public function # FIXME: enable again
"D104", # Missing docstring in public package # FIXME: enable again
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Ignore D107 Missing docstring # FIXME: enable again???
"D200", # One-line docstring should fit on one line
"D202", # No blank lines allowed after function docstring (found 1)
"D203", # Ignore one-blank-line-before-class as Black handles this
"D204", # 1 blank line required after class docstring
"D205", # 1 blank line required between summary line and description
"D209", # Multi-line docstring closing quotes should be on a separate line
"D210", # No whitespaces allowed surrounding docstring text
"D211", # No blank lines allowed before class docstring
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
"D301", # Use `r"""` if any backslashes in a docstring
"D400", # First line should end with a period
"D401", # First line of docstring should be in imperative mood
"D402", # First line should not be the function's signature
"D404", # First word of the docstring should not be "This"
"D415", # First line should end with a period, question mark, or exclamation point
"E226", # Missing whitespace around arithmetic operator # FIXME: enable again
"E241", # Multiple spaces after comma # FIXME: enable again
"I001", # Import block is un-sorted or un-formatted # FIXME: enable again
]
preview = true

[tool.ruff.lint.per-file-ignores]
"*/__init__.py" = ["F401"]
"example/*" = ["F403", "F405"]

[tool.mypy]
files = ["shc/", "test/", "example/"]
disallow_untyped_decorators = true
warn_unreachable = true
check_untyped_defs = true
namespace_packages = false
plugins = ["shc/util/mypy_variable_plugin.py"]
exclude = "^test/assets/mypy_plugin_test"

[[tool.mypy.overrides]]
module = "mido,astropy,astropy.*,serial,serial_asyncio,paho.mqtt.*,selenium.*,pulsectl.*,pulsectl_asyncio,aiomysql,aiogram.*"
ignore_missing_imports = true

[tool.ruff.format]
# Like Black, use double quotes for strings.
# quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

[tool.isort]
profile = "black" # Use the "black" profile for import sorting consistency with Black
line_length = 120
25 changes: 0 additions & 25 deletions requirements.txt

This file was deleted.

Loading
Loading