Skip to content

Commit

Permalink
Merge pull request #920 from greenbone/replace-pylint-with-ruff
Browse files Browse the repository at this point in the history
Change: Replace pylint with ruff and fix linting errors
  • Loading branch information
a-h-abdelsalam authored Aug 23, 2024
2 parents edb6236 + a1b78df commit 1b6904c
Show file tree
Hide file tree
Showing 31 changed files with 107 additions and 540 deletions.
473 changes: 0 additions & 473 deletions .pylintrc

This file was deleted.

2 changes: 1 addition & 1 deletion pheme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .version import __version__
from .version import __version__ # noqa: F401
10 changes: 4 additions & 6 deletions pheme/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
import logging
from typing import Callable, Tuple, Union

from rest_framework.authentication import BaseAuthentication
from rest_framework import exceptions
from rest_framework.request import HttpRequest

import requests
from requests.models import Response
import xmltodict
from requests.models import Response
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication
from rest_framework.request import HttpRequest

from pheme import settings


logger: logging.Logger = logging.getLogger(__name__)

# pylint falsely identifies Union as unsubscriptable-object in python 3.9
Expand Down
2 changes: 1 addition & 1 deletion pheme/datalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib
import base64
import urllib


def as_datalink(data: bytes, file_format: str) -> str:
Expand Down
15 changes: 8 additions & 7 deletions pheme/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import mimetypes
import json
import logging
from typing import Dict, Callable
import mimetypes
from pathlib import Path
import json
from typing import Callable, Dict

import rest_framework
from django.core.files.uploadedfile import UploadedFile
from rest_framework.decorators import (
api_view,
authentication_classes,
parser_classes,
renderer_classes,
authentication_classes,
)
from rest_framework.request import HttpRequest
from rest_framework.response import Response
from pheme.datalink import as_datalink
from pheme import settings
import pheme.authentication

import pheme.authentication
from pheme import settings
from pheme.datalink import as_datalink

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pheme/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
reliable for our usecase.
"""
from rest_framework.parsers import BaseParser
import xmltodict
from rest_framework.parsers import BaseParser


class XMLFormParser(BaseParser):
Expand Down
7 changes: 4 additions & 3 deletions pheme/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from typing import List, Dict, Generator, Union
from io import StringIO
from csv import DictWriter
from rest_framework.renderers import BaseRenderer
from io import StringIO
from typing import Dict, Generator, List, Union

import xmltodict
from rest_framework.renderers import BaseRenderer


class CSVRenderer(BaseRenderer):
Expand Down
4 changes: 2 additions & 2 deletions pheme/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import secrets
import os
import secrets
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
__configured_base = os.environ.get("PHEME_BASE_PATH")
Expand Down
2 changes: 1 addition & 1 deletion pheme/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from uuid import uuid4
from typing import Dict
from uuid import uuid4

from django.core.cache import cache

Expand Down
1 change: 1 addition & 0 deletions pheme/templatetags/charts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Dict

from django import template

_severity_class_colors = {
Expand Down
11 changes: 6 additions & 5 deletions pheme/templatetags/charts/h_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

import itertools
from typing import Dict
from PIL import ImageFont

from django.utils.safestring import SafeText
from PIL import ImageFont

from pheme.templatetags.charts import (
register,
_severity_class_colors,
build_legend,
calculate_legend_start_height,
register,
)


__ORIENTATION_LINE_TEMPLATE = """
<rect x="{x}" y="0" height="{height}" width="1" style="fill: #000000;"></rect>
"""
Expand Down Expand Up @@ -138,7 +139,7 @@ def h_bar_chart(
font = ImageFont.truetype(font_file_name, font_size)
# add 87.5 + 10 for legend
max_hostname_len = (
max(
max( # noqa: PLW3301
max(font.getlength(k) for k in data.keys()),
font.getlength(x_title),
)
Expand All @@ -148,7 +149,7 @@ def h_bar_chart(
except OSError:
# multiply by 1.25 for kerning and add 87.5 for legend
max_hostname_len = (
max(max(len(k) for k in data.keys()), len(x_title))
max(max(len(k) for k in data.keys()), len(x_title)) # noqa: PLW3301
* font_size
* 1.25
+ 87.5
Expand Down
6 changes: 4 additions & 2 deletions pheme/templatetags/charts/pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import math
from typing import Dict

from django.utils.safestring import SafeText

from pheme.templatetags.charts import (
calculate_legend_start_height,
register,
_severity_class_colors,
build_legend,
calculate_legend_start_height,
register,
)

__PIE_CHART_TEMPLATE = """
Expand Down
2 changes: 1 addition & 1 deletion pheme/templatetags/charts/treemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

from pheme.templatetags.charts import (
_severity_class_colors,
register,
build_legend,
calculate_legend_start_height,
register,
)

__ELEMENT_TEMPLATE = """
Expand Down
4 changes: 2 additions & 2 deletions pheme/templatetags/dynamic_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
as a dependency upfront.
"""

from django.utils.safestring import mark_safe, SafeString
from django import template
from pheme.parameter import load_params
from django.utils.safestring import SafeString, mark_safe

from pheme.parameter import load_params

register = template.Library()

Expand Down
4 changes: 2 additions & 2 deletions pheme/templatetags/readable_timeformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
2001-07-22T09:15:37Z -> Sun, Jul 22, 2001 09 AM UTC
"""
from datetime import datetime
from django.utils.safestring import SafeText, SafeString
from django import template

from django import template
from django.utils.safestring import SafeString, SafeText

register = template.Library()

Expand Down
2 changes: 1 addition & 1 deletion pheme/transformation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import scanreport
from . import scanreport # noqa: F401
2 changes: 1 addition & 1 deletion pheme/transformation/scanreport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import gvmd, renderer
from . import gvmd, renderer # noqa: F401
2 changes: 0 additions & 2 deletions pheme/transformation/scanreport/gvmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
"""
import logging
import time

from typing import Dict, List, Optional


from pheme.transformation.scanreport.model import (
# Equipment,
Overview,
Expand Down
12 changes: 6 additions & 6 deletions pheme/transformation/scanreport/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from typing import Dict

from base64 import b64encode
from typing import Dict

from django.core.cache import cache
from django.template import Template, Context
from django.template import Context, Template
from rest_framework import renderers
from rest_framework.request import Request
from weasyprint import CSS, HTML
from pheme.settings import DEBUG
from pheme.parameter import load_params

from pheme.authentication import get_username_role
from pheme.errors import TemplateNotFoundError
from pheme.parameter import load_params
from pheme.settings import DEBUG

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -150,7 +150,7 @@ def _replace_inline_svg_with_img_tags(
def enforce_limit(
data: Dict, parameter: Dict, format_type: str = "pdf"
) -> Dict:
if not "results" in data:
if "results" not in data:
return data

limits = parameter.get("limits", {}).get(format_type, {})
Expand Down
3 changes: 2 additions & 1 deletion pheme/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"""

from django.urls import path

import pheme.parameter
import pheme.version
import pheme.views
import pheme.parameter

urlpatterns = [
path(
Expand Down
2 changes: 1 addition & 1 deletion pheme/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .__version__ import __version__
from .__version__ import __version__ # noqa: F401
8 changes: 4 additions & 4 deletions pheme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import dataclasses

import rest_framework.renderers
from rest_framework.decorators import api_view, parser_classes, renderer_classes
from rest_framework.response import Response
from rest_framework.request import Request

from rest_framework.response import Response

from pheme.parser.xml import XMLFormParser, XMLParser
from pheme.renderer import CSVRenderer, MarkDownTableRenderer, XMLRenderer
from pheme.storage import load, store
from pheme.transformation import scanreport
from pheme.storage import store, load
from pheme.renderer import MarkDownTableRenderer, XMLRenderer, CSVRenderer
from pheme.transformation.scanreport import model
from pheme.version import __version__

Expand Down
43 changes: 35 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1b6904c

Please sign in to comment.