From c656fa6e381a645349f289da28c3b4e3341ac84f Mon Sep 17 00:00:00 2001 From: Gustavo Carneiro Date: Sat, 23 Mar 2024 16:20:26 +0000 Subject: [PATCH] switch from black/flake8 to ruff --- .github/workflows/tox.yml | 4 ++-- pyproject.toml | 6 +++++- tox.ini | 15 ++++++++++----- yacron/config.py | 4 +--- yacron/cron.py | 22 +++++++++++----------- yacron/job.py | 7 +++---- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 875688a..5687917 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -1,14 +1,14 @@ name: tox on: [push, pull_request] jobs: - tox-flake8: + tox-lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - run: pip install --upgrade pip - run: pip install tox - - run: tox -e flake8 + - run: tox -e lint tox-mypy: runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 911a0cb..2aee63a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,10 @@ [tool.black] line-length = 79 -target_version = ['py37'] +target_version = ['py310'] + +[tool.ruff] +target-version = "py310" +line-length = 79 [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/tox.ini b/tox.ini index 72a85ca..05786ed 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py310, py311, py312, flake8, mypy +envlist = py310, py311, py312, lint, mypy [travis] python = @@ -7,10 +7,15 @@ python = 3.11: py311 3.12: py312 -[testenv:flake8] -basepython=python3 -deps=flake8 -commands=flake8 --max-line-length=88 yacron tests + +[testenv:lint] +description = lint source code +deps = + ruff +commands = + ruff check yacron + ruff format --check yacron + [testenv:mypy] basepython=python3 diff --git a/yacron/config.py b/yacron/config.py index 1806133..8e035e8 100644 --- a/yacron/config.py +++ b/yacron/config.py @@ -287,9 +287,7 @@ def __init__(self, config: dict) -> None: self.schedule_unparsed = config.pop("schedule") if isinstance(self.schedule_unparsed, str): if self.schedule_unparsed in {"@reboot"}: - self.schedule = ( - self.schedule_unparsed - ) # type: Union[CronTab, str] + self.schedule = self.schedule_unparsed # type: Union[CronTab, str] else: self.schedule = CronTab(self.schedule_unparsed) elif isinstance(self.schedule_unparsed, dict): diff --git a/yacron/cron.py b/yacron/cron.py index 458c6ab..59cf259 100644 --- a/yacron/cron.py +++ b/yacron/cron.py @@ -1,24 +1,26 @@ -import logging.config import asyncio import asyncio.subprocess import datetime import logging +import logging.config from collections import OrderedDict, defaultdict from typing import Any, Awaitable, Dict, List, Optional, Union # noqa from urllib.parse import urlparse + from aiohttp import web +from crontab import CronTab # noqa + import yacron.version from yacron.config import ( - JobConfig, - parse_config, ConfigError, - parse_config_string, + JobConfig, + JobDefaults, WebConfig, YacronConfig, - JobDefaults, + parse_config, + parse_config_string, ) -from yacron.job import RunningJob, JobRetryState -from crontab import CronTab # noqa +from yacron.job import JobRetryState, RunningJob logger = logging.getLogger("yacron") WAKEUP_INTERVAL = datetime.timedelta(minutes=1) @@ -77,9 +79,7 @@ def __init__( self.cron_jobs = OrderedDict() # type: Dict[str, JobConfig] # list of cron jobs already running # name -> list of RunningJob - self.running_jobs = defaultdict( - list - ) # type: Dict[str, List[RunningJob]] + self.running_jobs = defaultdict(list) # type: Dict[str, List[RunningJob]] self.config_arg = config_arg if config_arg is not None: self.update_config() @@ -212,7 +212,7 @@ async def _web_get_status(self, request: web.Request) -> web.Response: status = "scheduled ({})".format( ( jobstat["scheduled_in"] - if type(jobstat["scheduled_in"]) is str + if isinstance(jobstat["scheduled_in"], str) else naturaltime( jobstat["scheduled_in"], future=True ) diff --git a/yacron/job.py b/yacron/job.py index e23ff15..06972fc 100644 --- a/yacron/job.py +++ b/yacron/job.py @@ -2,19 +2,18 @@ import asyncio.subprocess import logging import os +import subprocess import sys import time from datetime import datetime, timezone from email.message import EmailMessage from socket import gethostname from typing import Any, Dict, List, Optional, Tuple -import subprocess - -import sentry_sdk -import sentry_sdk.utils import aiosmtplib import jinja2 +import sentry_sdk +import sentry_sdk.utils from yacron.config import JobConfig from yacron.statsd import StatsdJobMetricWriter