Skip to content

Commit

Permalink
Reviewed and simplified setup, enabled I and S ruff rules (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoran Simic <zsimic@netflix.com>
  • Loading branch information
zsimic and Zoran Simic authored Mar 6, 2024
1 parent b4f1d78 commit 5ca7547
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -34,7 +34,7 @@ jobs:

strategy:
matrix:
python-version: ["3.6", "3.7"]
python-version: ["3.6", "3.7", "3.8"]

steps:
- uses: actions/checkout@v4
Expand Down
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ build-backend = "setuptools.build_meta"
[tool.ruff]
cache-dir = ".tox/.ruff_cache"
line-length = 140
src = ["src", "tests"]
src = ["src"]

[tool.ruff.lint]
ignore = ["S101"]
extend-select = [
# "A", # flake8-builtins
# "ARG", # flake8-unused-arguments
Expand All @@ -22,7 +23,7 @@ extend-select = [
"F", # pyflakes
"FLY", # flynt
"G", # flake8-logging-format
# "I", # isort
"I", # isort
"INT", # flake8-gettext
"PGH", # pygrep-hooks
"PIE", # flake8-pie
Expand All @@ -32,6 +33,7 @@ extend-select = [
"RSE", # flake8-raise
# "RET", # flake8-return
"RUF", # ruff-specific
"S", #flake8-bandit
# "SIM", # flake8-simplify
# "SLF", # flake8-self
"SLOT", # flake8-slots
Expand All @@ -49,5 +51,9 @@ order-by-type = false
[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.ruff.lint.per-file-ignores]
"src/runez/__init__.py" = ["I"]
"tests/**" = ["S"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from setuptools import setup


setup(
name="runez",
setup_requires="setupmeta",
Expand Down
2 changes: 1 addition & 1 deletion src/runez/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def predefined(cls, name):

names = cls.available_names(include_virtual=False)
n = len(names)
n = max(0, min(n - 1, int(n * random.random()))) # nosec (irrelevant for crypto)
n = max(0, min(n - 1, int(n * random.random()))) # noqa: S311 (irrelevant for crypto)
name = names[n]

if name in cls.available_names():
Expand Down
1 change: 0 additions & 1 deletion src/runez/colors/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from runez.colors import NamedColors, NamedStyles, PlainBackend, Renderable
from runez.convert import to_int


VALID_FLAVORS = {"dark", "light", "neutral"}


Expand Down
3 changes: 1 addition & 2 deletions src/runez/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from runez.file import TempFolder
from runez.logsetup import LogManager
from runez.render import Header
from runez.system import _R, CaptureOutput, DEV, Slotted, TempArgv, TrackedOutput
from runez.system import flattened, LOG, quoted, short, stringified, UNSET
from runez.system import _R, CaptureOutput, DEV, flattened, LOG, quoted, short, Slotted, stringified, TempArgv, TrackedOutput, UNSET

try:
from click import BaseCommand as _ClickCommand
Expand Down
1 change: 0 additions & 1 deletion src/runez/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from runez.convert import _float_from_text
from runez.system import _R, stringified, UNSET


DEFAULT_TIMEZONE = None
SECONDS_IN_ONE_MINUTE = 60
SECONDS_IN_ONE_HOUR = 60 * SECONDS_IN_ONE_MINUTE
Expand Down
6 changes: 3 additions & 3 deletions src/runez/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def _untar(source, destination, simplify):
if not is_subfolder(member_path, extracted_source): # pragma: no cover, don't have an exploit sample handy
raise Exception("Attempted Path Traversal in Tar File")

fh.extractall(extracted_source) # nosec B202, taken care of
fh.extractall(extracted_source) # noqa: S202, taken care of

_move_extracted(extracted_source, destination, simplify)

Expand All @@ -628,15 +628,15 @@ def _unzip(source, destination, simplify):
with TempFolder():
extracted_source = to_path(source.name)
with ZipFile(source) as fh:
fh.extractall(extracted_source) # nosec B202, not a tarfile
fh.extractall(extracted_source) # noqa: S202, not a tarfile

_move_extracted(extracted_source, destination, simplify)


def _zip(source, destination, arcname, fh=None):
"""Effective zip, behaving like tar+gzip for consistency"""
if fh is None:
from zipfile import ZipFile, ZIP_DEFLATED
from zipfile import ZIP_DEFLATED, ZipFile

source = to_path(source).absolute()
destination = to_path(destination).absolute()
Expand Down
1 change: 0 additions & 1 deletion src/runez/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from runez.system import LOG, ltattr


DEFAULT_FREQUENCY = 60


Expand Down
2 changes: 1 addition & 1 deletion src/runez/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def error_reason(self):
if msg:
return msg

except Exception: # nosec
except Exception: # noqa: S110
pass

return self.text
Expand Down
22 changes: 19 additions & 3 deletions src/runez/logsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@
from runez.convert import to_bytesize, to_int
from runez.date import local_timezone, represented_duration
from runez.file import parent_folder
from runez.system import _R, abort_if, cached_property, decode, DEV, find_caller, flattened, quoted, short, stringified, uncolored
from runez.system import LOG, py_mimic, Slotted, SYS_INFO, ThreadGlobalContext, UNSET

from runez.system import (
_R,
abort_if,
cached_property,
decode,
DEV,
find_caller,
flattened,
LOG,
py_mimic,
quoted,
short,
Slotted,
stringified,
SYS_INFO,
ThreadGlobalContext,
uncolored,
UNSET,
)

ORIGINAL_CF = logging.currentframe

Expand Down
8 changes: 4 additions & 4 deletions src/runez/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def make_executable(path, fatal=True, logger=UNSET, dryrun=UNSET):
return abort("%s does not exist, can't make it executable" % short(path), return_value=-1, fatal=fatal, logger=logger)

try:
os.chmod(path, 0o755) # nosec
os.chmod(path, 0o755) # noqa: S103
_R.hlog(logger, "Made '%s' executable" % short(path))
return 1

Expand Down Expand Up @@ -631,7 +631,7 @@ def _read_data(fd, length=1024):
def _run_popen(args, popen_args, passthrough, fatal, stdout, stderr):
"""Run subprocess.Popen(), capturing output accordingly"""
if not passthrough:
p = subprocess.Popen(args, stdout=stdout, stderr=stderr, **popen_args) # nosec
p = subprocess.Popen(args, stdout=stdout, stderr=stderr, **popen_args) # noqa: S603
if fatal is None and stdout is None and stderr is None:
return p, None, None # Don't wait on spawned process

Expand All @@ -655,7 +655,7 @@ def _run_popen(args, popen_args, passthrough, fatal, stdout, stderr):
stdout_buffer = BytesIO()
stderr_buffer = BytesIO()

with subprocess.Popen(args, stdout=stdout_w, stderr=stderr_w, **popen_args) as p: # nosec
with subprocess.Popen(args, stdout=stdout_w, stderr=stderr_w, **popen_args) as p: # noqa: S603
os.close(stdout_w)
os.close(stderr_w)
readable = [stdout_r, stderr_r]
Expand Down Expand Up @@ -703,7 +703,7 @@ def _safe_write(target, data, flush=None):
if flush is not None:
flush.flush()

except Exception: # nosec, don't consider run crashed if one of the channels we're passing through is failing
except Exception: # noqa: S110, don't consider run crashed if one of the channels we're passing through is failing
pass


Expand Down
1 change: 0 additions & 1 deletion src/runez/pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from runez.program import is_executable, run
from runez.system import _R, cached_property, flattened, joined, ltattr, resolved_path, short, UNSET


CPYTHON = "cpython"
RX_PYTHON_BASENAME = re.compile(r"^python(\d(\.\d+)?)?$")

Expand Down
4 changes: 1 addition & 3 deletions src/runez/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from runez.colors import ColorManager
from runez.convert import to_int
from runez.system import _R, AdaptedProperty, flattened, is_iterable, joined, short, Slotted, stringified
from runez.system import SYS_INFO, UNSET, wcswidth

from runez.system import _R, AdaptedProperty, flattened, is_iterable, joined, short, Slotted, stringified, SYS_INFO, UNSET, wcswidth

NAMED_BORDERS = {
"ascii": "rstgrid,t:+++=,m:+++-",
Expand Down
1 change: 0 additions & 1 deletion src/runez/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from runez.file import ensure_folder, parent_folder
from runez.system import _R, abort, is_basetype, is_iterable, LOG, resolved_path, short, stringified, UNSET


K_INDENTED_SEPARATORS = (",", ": ")
K_COMPACT_SEPARATORS = (", ", ": ")

Expand Down
1 change: 0 additions & 1 deletion src/runez/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from runez.system import py_mimic


THREAD_LOCAL = threading.local()


Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from runez.logsetup import LogManager
from runez.system import CaptureOutput, LOG, short, stringified


cli.default_main = main
GlobalHttpCalls.forbid()
runez.date.DEFAULT_TIMEZONE = runez.date.UTC
Expand Down
1 change: 0 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import runez


SAMPLES = runez.DEV.tests_path("sample")


Expand Down
1 change: 0 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import runez
from runez.http import ForbiddenHttpError, GlobalHttpCalls, MockResponse, RestClient, RestResponse, urljoin


EXAMPLE = RestClient("https://example.com")


Expand Down
1 change: 0 additions & 1 deletion tests/test_logsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from runez.conftest import WrappedHandler
from runez.logsetup import _formatted_text, formatted, LogSpec


LOG = logging.getLogger(__name__)


Expand Down
1 change: 0 additions & 1 deletion tests/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from runez.conftest import exception_raiser
from runez.program import RunAudit, RunResult


CHATTER = runez.DEV.tests_path("chatter")


Expand Down
1 change: 0 additions & 1 deletion tests/test_pyenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from runez.http import RestClient
from runez.pyenv import ArtifactInfo, PypiStd, PythonDepot, PythonSpec, Version


PYPI_CLIENT = RestClient("https://example.com/pypi")


Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{36,37,38,39,310,311,312}, coverage, docs, style
envlist = py{39,310,311,312}, coverage, docs, style
skip_missing_interpreters = true

[testenv]
Expand Down Expand Up @@ -32,9 +32,7 @@ commands = pytest --doctest-modules {posargs:}
[testenv:style]
skip_install = True
deps = ruff
flake8-import-order
commands = ruff check --diff
ruff check
commands = ruff check
ruff format --diff
python "{toxinidir}/tests/extra-validations"

Expand Down

0 comments on commit 5ca7547

Please sign in to comment.