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

Fix ruff linting errors #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
129 changes: 129 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "lf"
docstring-code-format = false
exclude = []

[tool.ruff]
line-length = 88
target-version = "py310"

# Exclude a variety of commonly ignored directories.
exclude = [
"whitelist.py", # for vulture
".direnv",
".eggs",
".git",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"venv",
]

[tool.ruff.lint]
select = [
# "ANN", # flake8-annotationsq
"F", # Pyflakes
"E", # pycodestyle Error
"W", # pycodestyle Warning
# "C90", # mccabe: C901: {name} is too complex ({complexity})
"I", # isort: unsorted-imports, missing-required-import
# "D", # pydocstyle
"B", # flake8-bugbear
# "UP", # pyupgrade
# "YTT", # flake8-2020
"ASYNC1", # flake8-trio
"BLE", # flake8-blind-except
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
# "CPY", # flake8-copyright --preview
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"DJ", # flake8-django
# "EXE", # flake8-executable
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
# "T20", # flake8-print
# "PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"INT", # flake8-gettext
# "ARG", # flake8-unused-arguments
# "PTH", # flake8-use-pathlib
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PL", # Pylint
# "TRY", # tryceratops, they all sound BS
# "FLY", # flynt
"NPY", # NumPy-specific rules
"AIR", # Airflow
# "PERF", # Perflint
"FURB", # refurb --preview
"LOG", # flake8-logging
"RUF", # Ruff-specific rules
]
ignore = [
"PLR6301", # Method `...` could be a function, class method, or static method
"LOG015", # `debug()` call on root logger
"COM812", # Trailing comma missing
"SLF", # Private member accessed
"DTZ005", # The use of `datetime.datetime.now()` without `tz` argument is not allowed
"PLR0913", # Too many arguments in function definition
"PLR0914", # Too many local variables
"PLR0915", # Too many statements
"PLR0917", # Too many positional arguments
"FURB101", # `open` and `read` should be replaced by `Path(rootConfJsonFile).read_text()`
"FURB103", # `open` and `write` should be replaced by `Path(...
"PLR2004", # Magic value used in comparison, consider replacing `...` with a constant variable
"RUF005", # Consider `[*_list, x]` instead of concatenation
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`, why?
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
"D205", # 1 blank line required between summary line and description
"D211", # (Do not enable) no-blank-line-before-class
"D212", # multi-line-summary-first-line, conflicts with D213:multi-line-summary-second-line
"D401", # First line of docstring should be in imperative mood
"D417", # Missing argument descriptions in the docstring
"E402", # Module level import not at top of file
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Use a single with statement with multiple contexts...
"SIM115", # Use context handler for opening files
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
unfixable = []


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

mccabe.max-complexity = 13 # Unlike Flake8, default to a complexity level of 10.

6 changes: 3 additions & 3 deletions s_tui/about_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""Displays the About message menu """

from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function

import urwid
from s_tui.sturwid.ui_elements import ViListBox

from s_tui.helper_functions import __version__
from s_tui.sturwid.ui_elements import ViListBox

ABOUT_MESSAGE = """
s-tui is a monitoring tool for your CPU's temperature, frequency, utilization \
Expand Down
5 changes: 3 additions & 2 deletions s_tui/help_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"""A class display the help message menu
"""

from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function

import urwid

from s_tui.sturwid.ui_elements import ViListBox

HELP_MESSAGE = """
Expand Down
25 changes: 11 additions & 14 deletions s_tui/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
""" Helper functions module with common useful functions """


import os
import csv
import json
import logging
import os
import platform
import subprocess
import re
import csv
import subprocess
import sys
import json
import time

from collections import OrderedDict

__version__ = "1.1.6"
Expand All @@ -52,25 +51,23 @@ def get_processor_name():
all_info = cpuinfo.readlines()
for line in all_info:
if b"model name" in line:
return re.sub(b".*model name.*:", b"", line, 1)
return re.sub(rb".*model name.*:", b"", line, count=1)
elif platform.system() == "FreeBSD":
cmd = ["sysctl", "-n", "hw.model"]
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
str_value = process.stdout.read()
return str_value
return process.stdout.read()
elif platform.system() == "Darwin":
cmd = ["sysctl", "-n", "machdep.cpu.brand_string"]
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
str_value = process.stdout.read()
return str_value
return process.stdout.read()

return platform.processor()

Expand All @@ -92,14 +89,14 @@ def output_to_csv(sources, csv_writeable_file):
"""Print statistics to csv file"""
file_exists = os.path.isfile(csv_writeable_file)

with open(csv_writeable_file, "a") as csvfile:
with open(csv_writeable_file, "a", encoding="utf-8") as csvfile:
csv_dict = OrderedDict()
csv_dict.update({"Time": time.strftime("%Y-%m-%d_%H:%M:%S")})
summaries = [val for key, val in sources.items()]
for summarie in summaries:
update_dict = dict()
for prob, val in summarie.source.get_sensors_summary().items():
prob = summarie.source.get_source_name() + ":" + prob
update_dict = {}
for prob_, val in summarie.source.get_sensors_summary().items():
prob = summarie.source.get_source_name() + ":" + prob_
update_dict[prob] = val
csv_dict.update(update_dict)

Expand Down
Loading