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

Change: Replace pylint with ruff #1051

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
5 changes: 3 additions & 2 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- "3.11"
uses: greenbone/workflows/.github/workflows/lint-python.yml@main
with:
linter: ruff
lint-packages: gvmtools tests
python-version: ${{ matrix.python-version }}

Expand All @@ -39,9 +40,9 @@ jobs:
run: poetry run pip install -r scripts/requirements.txt
- name: Check with black
run: poetry run black --check scripts/*.gmp.py
- name: Run pylint
- name: Lint scripts
run: |
poetry run pylint --rcfile=scripts/.pylintrc --disable=R --ignore=requirements.txt scripts/*.py
poetry run ruff --config scripts/ruff.toml scripts/*.py

test:
name: Unit tests
Expand Down
2 changes: 1 addition & 1 deletion gvmtools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
gvm-cli socket --gmp-username foo --gmp-password foo myfile.xml

The protocol specifications for GMP and OSP are available at:
https://docs.greenbone.net/index.html#api_documentation"""
https://docs.greenbone.net/index.html#api_documentation""" # noqa: E501


def _load_infile(filename=None):
Expand Down
2 changes: 1 addition & 1 deletion gvmtools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def defaults(self):
return self._defaults

def get(self, section, name):
if not section in self._config:
if section not in self._config:
return None

return self._config[section].get(name)
709 changes: 254 additions & 455 deletions poetry.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
homepage = "https://github.com/greenbone/gvm-tools/"
repository = "https://github.com/greenbone/gvm-tools/"
documentation = "https://greenbone.github.io/gvm-tools/"
classifiers=[
classifiers = [
# Full list: https://pypi.org/pypi?%3Aaction=list_classifiers
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
Expand Down Expand Up @@ -42,7 +42,7 @@ python-gvm = ">=23.4.2"

[tool.poetry.dev-dependencies]
autohooks = ">=22.8.0"
autohooks-plugin-pylint = ">=22.8.1"
autohooks-plugin-ruff = ">=23.6.1"
autohooks-plugin-black = ">=22.8.1"
autohooks-plugin-isort = ">=22.8.0"
pontos = ">=22.8.1"
Expand Down Expand Up @@ -75,7 +75,11 @@ line_length = 80

[tool.autohooks]
mode = "poetry"
pre-commit = ['autohooks.plugins.black', 'autohooks.plugins.pylint', 'autohooks.plugins.isort']
pre-commit = [
'autohooks.plugins.black',
'autohooks.plugins.ruff',
'autohooks.plugins.isort',
]

[tool.pontos.version]
version-module-file = "gvmtools/__version__.py"
4 changes: 2 additions & 2 deletions scripts/certbund-report.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def main(gmp: Gmp, args: Namespace) -> None:
_info(f"processing {len(hosts)}/{len(hostdatas)} hosts")
for hostdata in hostdatas:
asset = hostdata.find("asset").attrib["asset_id"]
if not asset in hosts:
if asset not in hosts:
continue
details: Dict[str, Optional[str]] = {}
details["ip"] = _get_text(hostdata.find("ip"))
Expand Down Expand Up @@ -295,7 +295,7 @@ def main(gmp: Gmp, args: Namespace) -> None:
# warn below
continue
for cbi in cbs.findall("info"):
if not "id" in cbi.attrib:
if "id" not in cbi.attrib:
# we have both <info id="CB-K14/1304"> (which we want)
# and, for some reason, <info start="1" max="10"/>
continue
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-gmp.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def delete_entry_with_ip(self, ip):
self.cursor.execute("DELETE FROM Report WHERE host=?", (ip,))
self.con_db.isolation_level = None
self.cursor.execute("VACUUM")
self.con_db.isolation_level = "" # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # pylint: disable=line-too-long
self.con_db.isolation_level = "" # see: https://github.com/CxAalto/gtfspy/commit/8d05c3c94a6d4ca3ed675d88af93def7d5053bfe # pylint: disable=line-too-long # noqa: E501
# Save the changes
self.con_db.commit()

Expand Down
4 changes: 3 additions & 1 deletion scripts/combine-reports.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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/>.

# ruff: noqa: E501

import sys
import time
from argparse import Namespace
Expand Down Expand Up @@ -43,7 +45,7 @@ def check_args(args: Namespace) -> None:
n. <report_n_uuid> --uuid of report to be combined

Example for starting up the routine:
$ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname \
$ gvm-script --gmp-username=namessh --gmp-password=pass ssh --hostname=hostname \
scripts/combine-reports.gmp.py \
"d15a337c-56f3-4208-a462-afeb79eb03b7" \
"303fa0a6-aa9b-43c4-bac0-66ae0b2d1698" 'first_task'
Expand Down
13 changes: 7 additions & 6 deletions scripts/generate-random-reports.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"""

LOREM_IPSUM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
Expand Down Expand Up @@ -340,7 +340,7 @@ def generate_host_elem(
return host_elem


def generate_reports(task, n_reports, with_gauss, **kwargs):
def generate_reports(task, n_reports, n_results, with_gauss, **kwargs):
reports = []

if with_gauss:
Expand All @@ -350,7 +350,7 @@ def generate_reports(task, n_reports, with_gauss, **kwargs):

for _ in range(n_reports):
if with_gauss:
n_results = abs(int(gauss(n_results, 2)))
abs(int(gauss(n_results, 2)))

report_elem = generate_report_elem(task, **kwargs)
report_elem = e.tostring(report_elem)
Expand Down Expand Up @@ -388,8 +388,9 @@ def main(gmp: Gmp, args: Namespace) -> None:
epilog=textwrap.dedent(
"""
Example:
$ gvm-script --gmp-username name --gmp-password pass
ssh --hostname <gsm> scripts/gen-random-reports.gmp.py -T 5 -r 4 -R 3 --hosts 10
$ gvm-script --gmp-username name --gmp-password pass \
ssh --hostname <gsm> scripts/gen-random-reports.gmp.py \
-T 5 -r 4 -R 3 --hosts 10
"""
),
)
Expand Down
1 change: 1 addition & 0 deletions scripts/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builtins = ["gmp", "args"]
3 changes: 2 additions & 1 deletion scripts/send-delta-emails.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def check_args(args: Namespace) -> None:
reports via email for selected tasks.

Example for starting up the routine:
$ gvm-script --gmp-username name --gmp-password pass ssh --hostname <gsm> scripts/send-delta-emails.gmp.py
$ gvm-script --gmp-username name --gmp-password pass ssh \
--hostname <gsm> scripts/send-delta-emails.gmp.py

The routine follows this procedure:

Expand Down
2 changes: 1 addition & 1 deletion scripts/ssv_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

import re
import sys
from typing import IO, AnyStr, List, Optional, Pattern, TextIO, Union
from typing import IO, AnyStr, List, Optional, TextIO

Check warning on line 57 in scripts/ssv_csv.py

View check run for this annotation

Codecov / codecov/patch

scripts/ssv_csv.py#L57

Added line #L57 was not covered by tests


class CSVShapeError(Exception):
Expand Down
5 changes: 3 additions & 2 deletions scripts/start-multiple-alerts-scan.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def check_args(args):

1. <sender_email> -- E-Mail of the sender
2. <receiver_email> -- E-Mail of the receiver

Example:
$ gvm-script --gmp-username name --gmp-password pass \
ssh --hostname <gsm> scripts/start-multiple-alert-scan.gmp.py <sender_email> <receiver_email>
ssh --hostname <gsm> scripts/start-multiple-alert-scan.gmp.py \
<sender_email> <receiver_email>
"""
if len_args != 2:
print(message)
Expand Down
3 changes: 2 additions & 1 deletion scripts/sync-hosts.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def check_args(args):
This script reads host data from a csv file and sync it with the gsm.
It needs one parameters after the script name.

1. <csv_file> - should contain a table of IP-addresses with an optional a comment
1. <csv_file> - should contain a table of IP-addresses with an
optional a comment

Example:
$ gvm-script --gmp-username name --gmp-password pass \
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
from typing import Union
from unittest.mock import MagicMock, create_autospec, patch
from unittest.mock import MagicMock, create_autospec

from gvm.protocols.latest import Gmp
from lxml import etree
Expand Down