Skip to content

Commit

Permalink
chore(anta): Use Ruff and remove black and flake8 (#476)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: Matthieu Tâche <tache.matthieu@gmail.com>
Co-authored-by: Carl Baillargeon <carl.baillargeon@arista.com>
  • Loading branch information
gmuloc authored Mar 14, 2024
1 parent 0b35520 commit 735b043
Show file tree
Hide file tree
Showing 147 changed files with 4,728 additions and 3,840 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"vscode": {
"settings": {},
"extensions": [
"ms-python.black-formatter",
"ms-python.isort",
"formulahendry.github-actions",
"matangover.mypy",
"ms-python.mypy-type-checker",
Expand Down
22 changes: 9 additions & 13 deletions .github/generate_release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
"""
generate_release.py
"""generate_release.py.
This script is used to generate the release.yml file as per
https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
Expand All @@ -20,18 +19,15 @@
"fix": "Bug Fixes",
"cut": "Cut",
"doc": "Documentation",
# "CI": "CI",
"bump": "Bump",
# "test": "Test",
"revert": "Revert",
"refactor": "Refactoring",
}


class SafeDumper(yaml.SafeDumper):
"""
Make yamllint happy
https://github.com/yaml/pyyaml/issues/234#issuecomment-765894586
"""Make yamllint happy
https://github.com/yaml/pyyaml/issues/234#issuecomment-765894586.
"""

# pylint: disable=R0901,W0613,W1113
Expand Down Expand Up @@ -60,7 +56,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Breaking Changes",
"labels": breaking_labels,
}
},
)

# Add new features
Expand All @@ -71,7 +67,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "New features and enhancements",
"labels": feat_labels,
}
},
)

# Add fixes
Expand All @@ -82,7 +78,7 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Fixed issues",
"labels": fixes_labels,
}
},
)

# Add Documentation
Expand All @@ -93,23 +89,23 @@ def increase_indent(self, flow=False, *args, **kwargs):
{
"title": "Documentation",
"labels": doc_labels,
}
},
)

# Add the catch all
categories_list.append(
{
"title": "Other Changes",
"labels": ["*"],
}
},
)
with open(r"release.yml", "w", encoding="utf-8") as release_file:
yaml.dump(
{
"changelog": {
"exclude": {"labels": exclude_list},
"categories": categories_list,
}
},
},
release_file,
Dumper=SafeDumper,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
config_file: .yamllint.yml
file_or_dir: .
lint-python:
name: Run isort, black, flake8 and pylint
name: Check the code style
runs-on: ubuntu-20.04
needs: file-changes
if: needs.file-changes.outputs.code == 'true'
Expand All @@ -97,7 +97,7 @@ jobs:
- name: "Run tox linting environment"
run: tox -e lint
type-python:
name: Run mypy
name: Check typing
runs-on: ubuntu-20.04
needs: file-changes
if: needs.file-changes.outputs.code == 'true'
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
.flake8

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
36 changes: 9 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,33 @@ repos:
- --comment-style
- '<!--| ~| -->'

- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
- id: isort
name: Check for changes when running isort on all python files

- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
name: Check for changes when running Black on all python files

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
name: Check for PEP8 error on Python files
args:
- --config=/dev/null
- --max-line-length=165
- id: ruff
name: Run Ruff linter
args: [ --fix ]
- id: ruff-format
name: Run Ruff formatter

- repo: local # as per https://pylint.pycqa.org/en/latest/user_guide/installation/pre-commit-integration.html
hooks:
- id: pylint
entry: pylint
language: python
name: Check for Linting error on Python files
name: Check code style with pylint
description: This hook runs pylint.
types: [python]
args:
- -rn # Only display messages
- -sn # Don't display the score
- --rcfile=pylintrc # Link to config file

# Prepare to turn on ruff
# - repo: https://github.com/astral-sh/ruff-pre-commit
# # Ruff version.
# rev: v0.0.280
# hooks:
# - id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
name: Check typing with mypy
args:
- --config-file=pyproject.toml
additional_dependencies:
Expand Down
18 changes: 4 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"black-formatter.importStrategy": "fromEnvironment",
"ruff.enable": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"pylint.importStrategy": "fromEnvironment",
"pylint.args": [
"--rcfile=pylintrc"
],
"flake8.importStrategy": "fromEnvironment",
"flake8.args": [
"--config=/dev/null",
"--max-line-length=165"
],
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.args": [
"--config-file=pyproject.toml"
Expand All @@ -17,14 +11,10 @@
"refactor": "Warning"
},
"pylint.args": [
"--load-plugins pylint_pydantic",
"--load-plugins", "pylint_pydantic",
"--rcfile=pylintrc"
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"isort.importStrategy": "fromEnvironment",
"isort.check": true,
}
1 change: 1 addition & 0 deletions anta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Arista Network Test Automation (ANTA) Framework."""

import importlib.metadata
import os

Expand Down
16 changes: 7 additions & 9 deletions anta/aioeapi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Patch for aioeapi waiting for https://github.com/jeremyschulman/aio-eapi/pull/13"""
"""Patch for aioeapi waiting for https://github.com/jeremyschulman/aio-eapi/pull/13."""
from __future__ import annotations

from typing import Any, AnyStr
Expand All @@ -12,8 +12,7 @@


class EapiCommandError(RuntimeError):
"""
Exception class for EAPI command errors
"""Exception class for EAPI command errors.
Attributes
----------
Expand All @@ -25,8 +24,8 @@ class EapiCommandError(RuntimeError):
"""

# pylint: disable=too-many-arguments
def __init__(self, failed: str, errors: list[str], errmsg: str, passed: list[str | dict[str, Any]], not_exec: list[dict[str, Any]]):
"""Initializer for the EapiCommandError exception"""
def __init__(self, failed: str, errors: list[str], errmsg: str, passed: list[str | dict[str, Any]], not_exec: list[dict[str, Any]]) -> None:
"""Initializer for the EapiCommandError exception."""
self.failed = failed
self.errmsg = errmsg
self.errors = errors
Expand All @@ -35,16 +34,15 @@ def __init__(self, failed: str, errors: list[str], errmsg: str, passed: list[str
super().__init__()

def __str__(self) -> str:
"""returns the error message associated with the exception"""
"""Returns the error message associated with the exception."""
return self.errmsg


aioeapi.EapiCommandError = EapiCommandError


async def jsonrpc_exec(self, jsonrpc: dict) -> list[dict | AnyStr]: # type: ignore
"""
Execute the JSON-RPC dictionary object.
"""Execute the JSON-RPC dictionary object.
Parameters
----------
Expand Down Expand Up @@ -101,7 +99,7 @@ async def jsonrpc_exec(self, jsonrpc: dict) -> list[dict | AnyStr]: # type: ign
failed=commands[err_at]["cmd"],
errors=cmd_data[err_at]["errors"],
errmsg=err_msg,
not_exec=commands[err_at + 1 :], # noqa: E203
not_exec=commands[err_at + 1 :],
)


Expand Down
Loading

0 comments on commit 735b043

Please sign in to comment.