Skip to content

Commit

Permalink
Chore/lining ruff (#772)
Browse files Browse the repository at this point in the history
* chore: add ruff and precommit configs
* chore: fix typing issues in TinySA class
  • Loading branch information
redrathnure authored Jan 27, 2025
1 parent 428ecb0 commit e0da70f
Show file tree
Hide file tree
Showing 106 changed files with 5,547 additions and 5,518 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Default for all text files
* text=auto whitespace=trailing-space,tab-in-indent,tabwidth=2
*.py text=auto whitespace=trailing-space,tab-in-indent,tabwidth=4

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
# 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.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# 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
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python3 -m venv venv
.\venv\Scripts\activate
python3 -m pip install uv
uv sync
uv sync
- name: Build binary
run: |
.\venv\Scripts\activate
Expand Down
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exclude: (.vscode|.tox|ui)
default_language_version:
python: python3.11

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml
- id: name-tests-test
exclude: '/fixtures/'
args: [--pytest-test-first]
- id: pretty-format-json
args: [--autofix]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ debinstall: deb
.PHONY: debuninstall
debuninstall:
sudo apt purge nanovnasaver

1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,3 @@ below:
.. image:: https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif
:target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=T8KTGVDQF5K6E&item_name=NanoVNASaver+Development&currency_code=EUR&source=url
:alt: Paypal

1 change: 0 additions & 1 deletion docs/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ Covenant](https://www.contributor-covenant.org), version 1.4, available at

For answers to common questions about this code of conduct, see
<https://www.contributor-covenant.org/faq>

8 changes: 5 additions & 3 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ Prerequerements:
Following commands to prepare local env and run application or run tests:

* `uv sync` - prepare virtual environment and install prod and dev dependencies
* `uv run ui-compile` - compile Qt resources. Should be executed before first `uv run NanoVNASaver` run
* `uv run NanoVNASaver` - run local instance
* `uv run task test` - run unit tests in current venv
* `uv run task test-cov` - run unit tests in current venv and display test coverage report
* `uv run task test-full` - run unit tests for all avialable python versions
* `uv run task clean` - remove temporally artifacts (dist, build, *.pyc etc)

* `uv run task lint` - check sources and try to fix issues

## Development Routines

A few usefull commands:
Expand All @@ -28,7 +30,7 @@ A few usefull commands:

## UI Development

UI layout of Widget, Dialogs and Window stored in `*.ui` files and may be edited by QT Designer. Please use `uv run pyside6-designer` or `uv run task ui-designer` to launch QT Designer. Please note
UI layout of Widget, Dialogs and Window stored in `*.ui` files and may be edited by QT Designer. Please use `uv run pyside6-designer` or `uv run task ui-designer` to launch QT Designer. Please note

* UI layout should be creatd and stored via UI files
* fields name should follow python_snake_style_naming scheme
Expand Down Expand Up @@ -94,4 +96,4 @@ Execute `uv run task build-pkg-macos` to get `dist/NanoVNASaver.app*.exe` file.
Please configure pypi credentials, create git tag and execute `uv publish` command. Please refer [UV :: publish](https://docs.astral.sh/uv/guides/publish/) for more details.

🚧 TODO: describe git tag creation and next version selection
🚧 TODO: build and publish platform specific artefacts: deb, native bin, flatpack packages
🚧 TODO: build and publish platform specific artefacts: deb, native bin, flatpack packages
2 changes: 1 addition & 1 deletion docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ or
3. Open the completed app

open ./dist/NanoVNASaver/NanoVNASaver.app
or double-click on NanoVNASaver.app in finder.
or double-click on NanoVNASaver.app in finder.

## MacPorts

Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@
project = "nanovna-saver"
copyright = "2023, Holger Mueller"


# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# version: The short X.Y version.
# release: The full version, including alpha/beta/rc tags.
# If you dont need the separation provided between version and release,
# If you don't need the separation provided between version and release,
# just set them both to the same value.
try:
from NanoVNASaver import __version__ as version
Expand Down
41 changes: 29 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ dependencies=[
[dependency-groups]
dev = [
# Static Code Analysis tools
"black~=24.10",
"flake8~=7.1",
"pylint~=3.3",
"ruff~=0.9",
"pre-commit~=4.1",
"mypy~=1.14",

# Testing
"pytest~=8.3",
"pytest-cov~=6.0",
"tox~=4.23",
"tox-uv~=1.17",
"tox-uv~=1.17",

# Build helpers
"setuptools-scm>=8",
Expand Down Expand Up @@ -98,6 +98,11 @@ version_scheme = 'no-guess-dev'
test = "pytest ."
test-cov = "pytest --cov=src ."
test-full = "tox"
# TODO enable task lint-mypy when related issues are solved
#lint = "task lint-format || task lint-mypy"
lint = "task lint-format"
lint-format = "pre-commit run --all-files || pre-commit run --all-files"
lint-mypy = "mypy --non-interactive --install-types ."

clean = "python -m tools.project_clean"

Expand All @@ -116,31 +121,43 @@ pythonpath = [
'.', 'src',
]

[tool.black]
line-length = 80

[tool.ruff]
line-length = 80
line-length = 120
target-version = 'py311'
fix = true
show-fixes = true
unsafe-fixes = false
# TODO use https://docs.astral.sh/ruff/configuration/#config-file-discovery for test and UI generated files
extend-exclude = ["ui/*.py"]


[tool.ruff.lint]
# https://docs.astral.sh/ruff/rules
select = [
'E', 'W', # pycodestyle (E(rror), W(arning))
'F', # Pyflakes
'B', # flake8-bugbear
'I', # isort
'N', # pep8-naming
'PL', # pylint
'C90', # mccabe
'RUF100', # unused suppresions
'C', # mccabe
'RUF', # Ruff
]
ignore = [
'N802',
'N806',
'N999',
'PLR2004',
'N802',
'N806',
'N813',
# TODO fix module naming
'N999',
# TODO fix classes naming
'N801',
# TODO review related code
'C901',
'PLR0915',
'PLR0911',
'PLR0912'
]

[tool.ruff.lint.mccabe]
Expand Down
4 changes: 2 additions & 2 deletions src/NanoVNASaver/Analysis/AntennaAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from PySide6 import QtWidgets

from NanoVNASaver.Analysis.VSWRAnalysis import VSWRAnalysis
from .VSWRAnalysis import VSWRAnalysis

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -102,7 +102,7 @@ def runAnalysis(self) -> None:
new_end = new_end + 5 * self.bandwith
if (
all((new_start <= self.min_freq, new_end >= self.max_freq))
and self.vswr_limit_value < 10 # noqa: PLR2004
and self.vswr_limit_value < 10
):
self.vswr_limit_value += 2
self.input_vswr_limit.setValue(self.vswr_limit_value)
Expand Down
26 changes: 13 additions & 13 deletions src/NanoVNASaver/Analysis/BandPassAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import logging
import math

from PySide6 import QtWidgets
from PySide6 import QtWidgets as QtW

import NanoVNASaver.AnalyticTools as At
from NanoVNASaver.Analysis.Base import CUTOFF_VALS, MIN_CUTOFF_DAMPING, Analysis
from NanoVNASaver.Formatting import format_frequency
from .. import AnalyticTools as At
from ..Formatting import format_frequency
from .Base import CUTOFF_VALS, MIN_CUTOFF_DAMPING, Analysis

logger = logging.getLogger(__name__)

Expand All @@ -42,37 +42,37 @@ def __init__(self, app) -> None:
"span_6.0dB",
"q_factor",
):
self.label[label] = QtWidgets.QLabel()
self.label[label] = QtW.QLabel()
for attn in CUTOFF_VALS:
self.label[f"{attn:.1f}dB_l"] = QtWidgets.QLabel()
self.label[f"{attn:.1f}dB_r"] = QtWidgets.QLabel()
self.label[f"{attn:.1f}dB_l"] = QtW.QLabel()
self.label[f"{attn:.1f}dB_r"] = QtW.QLabel()

layout = self.layout
layout.addRow(self.label["titel"])
layout.addRow(
QtWidgets.QLabel(
QtW.QLabel(
f"Please place {self.app.markers[0].name}"
f" in the filter passband."
)
)
layout.addRow("Result:", self.label["result"])
layout.addRow(QtWidgets.QLabel(""))
layout.addRow(QtW.QLabel(""))

layout.addRow("Center frequency:", self.label["freq_center"])
layout.addRow("Bandwidth (-3 dB):", self.label["span_3.0dB"])
layout.addRow("Quality factor:", self.label["q_factor"])
layout.addRow("Bandwidth (-6 dB):", self.label["span_6.0dB"])
layout.addRow(QtWidgets.QLabel(""))
layout.addRow(QtW.QLabel(""))

layout.addRow(QtWidgets.QLabel("Lower side:"))
layout.addRow(QtW.QLabel("Lower side:"))
layout.addRow("Cutoff frequency:", self.label["3.0dB_l"])
layout.addRow("-6 dB point:", self.label["6.0dB_l"])
layout.addRow("-60 dB point:", self.label["60.0dB_l"])
layout.addRow("Roll-off:", self.label["octave_l"])
layout.addRow("Roll-off:", self.label["decade_l"])
layout.addRow(QtWidgets.QLabel(""))
layout.addRow(QtW.QLabel(""))

layout.addRow(QtWidgets.QLabel("Upper side:"))
layout.addRow(QtW.QLabel("Upper side:"))
layout.addRow("Cutoff frequency:", self.label["3.0dB_r"])
layout.addRow("-6 dB point:", self.label["6.0dB_r"])
layout.addRow("-60 dB point:", self.label["60.0dB_r"])
Expand Down
6 changes: 3 additions & 3 deletions src/NanoVNASaver/Analysis/BandStopAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging

import NanoVNASaver.AnalyticTools as At
from NanoVNASaver.Analysis.BandPassAnalysis import BandPassAnalysis
from NanoVNASaver.Analysis.Base import CUTOFF_VALS
from .. import AnalyticTools as At
from .BandPassAnalysis import BandPassAnalysis
from .Base import CUTOFF_VALS

logger = logging.getLogger(__name__)

Expand Down
7 changes: 2 additions & 5 deletions src/NanoVNASaver/Analysis/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
from typing import TYPE_CHECKING

from PySide6 import QtWidgets

if TYPE_CHECKING:
from NanoVNASaver.NanoVNASaver import NanoVNASaver as NanoVNA

from NanoVNASaver import NanoVNASaver

logger = logging.getLogger(__name__)

Expand All @@ -38,7 +35,7 @@ def __init__(self):


class Analysis:
def __init__(self, app: "NanoVNA") -> None:
def __init__(self, app: NanoVNASaver) -> None:
self.app = app
self.label: dict[str, QtWidgets.QLabel] = {
"titel": QtWidgets.QLabel(),
Expand Down
12 changes: 6 additions & 6 deletions src/NanoVNASaver/Analysis/EFHWAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

from PySide6 import QtWidgets

import NanoVNASaver.AnalyticTools as At
from NanoVNASaver.Analysis.ResonanceAnalysis import (
ResonanceAnalysis,
format_resistence_neg,
)
from NanoVNASaver.Formatting import (
from .. import AnalyticTools as At
from ..Formatting import (
format_complex_imp,
format_frequency,
format_frequency_short,
)
from .ResonanceAnalysis import (
ResonanceAnalysis,
format_resistence_neg,
)

logger = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions src/NanoVNASaver/Analysis/HighPassAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

from PySide6 import QtWidgets

import NanoVNASaver.AnalyticTools as At
from NanoVNASaver.Analysis.Base import CUTOFF_VALS, MIN_CUTOFF_DAMPING, Analysis
from NanoVNASaver.Formatting import format_frequency
from .. import AnalyticTools as At
from ..Formatting import format_frequency
from .Base import CUTOFF_VALS, MIN_CUTOFF_DAMPING, Analysis

logger = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions src/NanoVNASaver/Analysis/LowPassAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging

import NanoVNASaver.AnalyticTools as At
from NanoVNASaver.Analysis.Base import CUTOFF_VALS
from NanoVNASaver.Analysis.HighPassAnalysis import HighPassAnalysis
from .. import AnalyticTools as At
from .Base import CUTOFF_VALS
from .HighPassAnalysis import HighPassAnalysis

logger = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit e0da70f

Please sign in to comment.