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

Update pre-commit configuration to use Ruff for linting and formatting #4015

Open
wants to merge 4 commits 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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
tox:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -28,26 +28,26 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-gha.txt
- run: tox -e ${{ matrix.toxenv }}
k8s_itests:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
DOCKER_REGISTRY: ""
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
- run: python -m pip install --upgrade pip virtualenv
- run: curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- run: python -m pip install --upgrade pip
- run: pip install coveralls tox==3.2 tox-pip-extensions==1.3.0 ephemeral-port-reserve
- run: make k8s_itests
build_debs:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -56,7 +56,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
- run: sudo apt-get update
- run: sudo apt-get install -yq devscripts
- run: make itest_${{ matrix.dist }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
tox:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand All @@ -21,21 +21,21 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
- run: python -m pip install --upgrade pip
- run: pip install -r requirements-gha.txt
- run: tox -e ${{ matrix.toxenv }}
pypi:
# lets run tests before we push anything to pypi, much like we do internally
needs: tox
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
DOCKER_REGISTRY: ""
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8
# this will create a .tar.gz with all the code (i.e., an sdist)
- run: python setup.py sdist
# and finally, upload the above sdist to public PyPI
Expand Down
40 changes: 11 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,24 @@ repos:
- id: check-json
- id: check-yaml
exclude: /template/
- id: debug-statements
- id: name-tests-test
args: [--django]
- id: requirements-txt-fixer
- id: fix-encoding-pragma
args: [--remove]
exclude: ^paasta_tools/paastaapi
- id: pretty-format-json
args: [
'--autofix',
'--indent', '4',
'--no-sort-keys',
]
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.4.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
additional_dependencies: [aspy.refactor_imports==0.5.3]
exclude: ^paasta_tools/paastaapi
- repo: https://github.com/asottile/pyupgrade
rev: v1.12.0
hooks:
- id: pyupgrade
args: [--py36-plus]
exclude: ^paasta_tools/paastaapi
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: ['--target-version', 'py38']
exclude: ^paasta_tools/paastaapi
- repo: https://github.com/PyCQA/flake8
rev: 3.7.7
hooks:
- id: flake8
args: ['--ignore', 'E231']
exclude: ^docs/source/conf.py|paasta_tools/paastaapi.*$
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.9
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/Yelp/detect-secrets
rev: 0.9.1
hooks:
Expand All @@ -58,6 +38,8 @@ repos:
exclude: .*tests/.*|.*yelp/testing/.*|\.pre-commit-config\.yaml
- repo: local
hooks:
# Could be replaced by ruff when they implement TMS020, TMS021 and TMS022
# https://github.com/astral-sh/ruff/issues/5734
- id: patch-enforce-autospec
name: mock.patch enforce autospec
description: This hook ensures all mock.patch invocations specify an autospec
Expand Down
12 changes: 6 additions & 6 deletions general_itests/steps/deployments_json_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def step_impl_then(context):
},
}
)
assert (
expected_deployments == deployments
), f"actual: {deployments}\nexpected:{expected_deployments}"
assert expected_deployments == deployments, (
f"actual: {deployments}\nexpected:{expected_deployments}"
)


@then('that deployments.json has a desired_state of "{expected_state}"')
Expand All @@ -202,9 +202,9 @@ def step_impl_then_desired_state(context, expected_state):
reverse=True,
)[0][1]
desired_state = latest["desired_state"]
assert (
desired_state == expected_state
), f"actual: {desired_state}\nexpected: {expected_state}"
assert desired_state == expected_state, (
f"actual: {desired_state}\nexpected: {expected_state}"
)


@then("the repository should be correctly tagged")
Expand Down
7 changes: 3 additions & 4 deletions general_itests/steps/validate_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def given_service(context, service_type):

@when("we run paasta validate")
def run_paasta_validate(context):
validate_cmd = (
"paasta validate "
"--yelpsoa-config-root %s "
"--service %s " % (context.soa_dir, context.service)
validate_cmd = "paasta validate --yelpsoa-config-root %s --service %s " % (
context.soa_dir,
context.service,
)
context.return_code, context.output = _run(command=validate_cmd)

Expand Down
1 change: 1 addition & 0 deletions k8s_itests/scripts/containerd_registry_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import toml


containerdcfg_file_path = sys.argv[1]
containerdcfg = toml.load(containerdcfg_file_path)
dockercfg = json.load(open("/nail/etc/docker-registry-ro"))
Expand Down
1 change: 1 addition & 0 deletions k8s_itests/test_autoscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from k8s_itests.utils import cmd
from k8s_itests.utils import init_all


terminate_on_exit = []


Expand Down
2 changes: 2 additions & 0 deletions paasta_tools/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
Responds to paasta service and instance requests.
"""

import argparse
import contextlib
import logging
Expand All @@ -36,6 +37,7 @@
from paasta_tools.api.tweens import request_logger
from paasta_tools.utils import load_system_paasta_config


try:
import clog
except ImportError:
Expand Down
7 changes: 4 additions & 3 deletions paasta_tools/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
Client interface for the Paasta rest api.
"""

import logging
from dataclasses import dataclass
from typing import Optional
Expand Down Expand Up @@ -61,9 +62,9 @@ def get_paasta_oapi_client_by_url(

client = paastaapi.ApiClient(configuration=config)
# PAASTA-18005: Adds default timeout to paastaapi client
client.rest_client.pool_manager.connection_pool_kw[
"timeout"
] = load_system_paasta_config().get_api_client_timeout()
client.rest_client.pool_manager.connection_pool_kw["timeout"] = (
load_system_paasta_config().get_api_client_timeout()
)
# SEC-19555: support auth in PaaSTA APIs
if auth_token:
client.set_default_header("Authorization", f"Bearer {auth_token}")
Expand Down
2 changes: 2 additions & 0 deletions paasta_tools/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""
Settings of the paasta-api server.
"""

import os
from typing import Optional

Expand All @@ -22,6 +23,7 @@
from paasta_tools.utils import DEFAULT_SOA_DIR
from paasta_tools.utils import SystemPaastaConfig


soa_dir: str = os.environ.get("PAASTA_API_SOA_DIR", DEFAULT_SOA_DIR)

# The following `type: ignore` mypy hints are there because variables below de
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/tweens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from pyramid.request import Request
from pyramid.response import Response


Handler = Callable[[Request], Response]
2 changes: 2 additions & 0 deletions paasta_tools/api/tweens/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"""
Creates a tween that cprofiles requests
"""

import pyramid
import pytz

from paasta_tools.api import settings as api_settings


try:
# hackily patch pytz, since yelp_lib (used by yelp_profiling) type checks
# using an older version of pytz where tzinfo didn't exist yet. this needs to
Expand Down
2 changes: 2 additions & 0 deletions paasta_tools/api/tweens/request_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""
Creates a tween that logs information about requests.
"""

import json
import traceback
from datetime import datetime
Expand All @@ -23,6 +24,7 @@

from paasta_tools.api import settings


try:
import clog
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA service list (instances) etc.
"""

from pyramid.response import Response
from pyramid.view import view_config

Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA API error handling.
"""

import logging

from pyramid.response import Response
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/flink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA flink service list jobs, overview and config.
"""

from pyramid.view import view_config

from paasta_tools.api.views.exception import ApiFailure
Expand Down
2 changes: 2 additions & 0 deletions paasta_tools/api/views/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA service instance status/start/stop etc.
"""

import asyncio
import logging
import re
Expand Down Expand Up @@ -43,6 +44,7 @@
from paasta_tools.utils import TimeoutError
from paasta_tools.utils import validate_service_instance


log = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/pause_autoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA service list (instances) etc.
"""

import time

from kazoo.exceptions import NoNodeError
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA resource utilization, etc.
"""

from a_sync import block
from pyramid.response import Response
from pyramid.view import view_config
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA service list (instances) etc.
"""

from pyramid.view import view_config

from paasta_tools.api import settings
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/api/views/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
PaaSTA service list (instances) etc.
"""

from pyramid.view import view_config

from paasta_tools import __version__
Expand Down
1 change: 1 addition & 0 deletions paasta_tools/apply_external_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from subprocess import run
from traceback import print_exc


APPLIED_DIRECTORY = ".applied"


Expand Down
1 change: 1 addition & 0 deletions paasta_tools/autoscaling/autoscaling_service_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from paasta_tools.long_running_service_tools import ZK_PAUSE_AUTOSCALE_PATH
from paasta_tools.utils import ZookeeperPool


ServiceAutoscalingInfo = namedtuple(
"ServiceAutoscalingInfo",
[
Expand Down
Loading