Skip to content

Commit

Permalink
Merge pull request #3246 from c-po/spring-cleaning-2
Browse files Browse the repository at this point in the history
T6199: drop unused Python imports from graphql source
  • Loading branch information
c-po authored Apr 4, 2024
2 parents eedc83e + faa1535 commit 3099c96
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 56 deletions.
39 changes: 15 additions & 24 deletions .github/workflows/unused-imports.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
name: Check for unused imports using Pylint
on:
pull_request_target:
types: [opened, reopened, ready_for_review, locked]
on: push
# pull_request_target:
# types: [opened, reopened, ready_for_review, locked]

jobs:
build:
Check-Unused-Imports:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
tmp=$(git ls-files *.py | xargs pylint | grep W0611 | wc -l)
if [[ $tmp -gt 0 ]]; then
echo "Found $tmp occurrence of unused Python import statements!"
exit 1
fi
exit 0
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: make unused-imports
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SHIM_DIR := src/shim
LIBS := -lzmq
CFLAGS :=
BUILD_ARCH := $(shell dpkg-architecture -q DEB_BUILD_ARCH)

J2LINT := $(shell command -v j2lint 2> /dev/null)
PYLINT_FILES := $(shell git ls-files *.py)

config_xml_src = $(wildcard interface-definitions/*.xml.in)
config_xml_obj = $(config_xml_src:.xml.in=.xml)
Expand Down Expand Up @@ -114,7 +114,7 @@ sonar:

.PHONY: unused-imports
unused-imports:
git ls-files *.py | xargs pylint | grep W0611
@pylint --disable=all --enable=W0611 $(PYLINT_FILES)

deb:
dpkg-buildpackage -uc -us -tc -b
Expand Down
4 changes: 0 additions & 4 deletions src/services/api/graphql/generate/composite_function.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# typing information for composite functions: those that invoke several
# elementary requests, and return the result as a single dict
import typing

def system_status():
pass

queries = {'system_status': system_status}

mutations = {}

8 changes: 4 additions & 4 deletions src/services/api/graphql/graphql/auth_token_mutation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2022-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,10 +13,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.

import jwt
import datetime
from typing import Any, Dict
from ariadne import ObjectType, UnionType
from typing import Any
from typing import Dict
from ariadne import ObjectType
from graphql import GraphQLResolveInfo

from .. libs.token_auth import generate_token
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/graphql/graphql/directives.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 VyOS maintainers and contributors <[email protected]>
# Copyright 2021-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -13,7 +13,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.

from ariadne import SchemaDirectiveVisitor, ObjectType
from ariadne import SchemaDirectiveVisitor
from . queries import *
from . mutations import *

Expand Down
8 changes: 5 additions & 3 deletions src/services/api/graphql/graphql/mutations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2021-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -14,11 +14,13 @@
# along with this library. If not, see <http://www.gnu.org/licenses/>.

from importlib import import_module
from typing import Any, Dict, Optional
from ariadne import ObjectType, convert_camel_case_to_snake
from graphql import GraphQLResolveInfo
from makefun import with_signature

# used below by func_sig
from typing import Any, Dict, Optional # pylint: disable=W0611
from graphql import GraphQLResolveInfo # pylint: disable=W0611

from .. import state
from .. libs import key_auth
from api.graphql.session.session import Session
Expand Down
8 changes: 5 additions & 3 deletions src/services/api/graphql/graphql/queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2021-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -14,11 +14,13 @@
# along with this library. If not, see <http://www.gnu.org/licenses/>.

from importlib import import_module
from typing import Any, Dict, Optional
from ariadne import ObjectType, convert_camel_case_to_snake
from graphql import GraphQLResolveInfo
from makefun import with_signature

# used below by func_sig
from typing import Any, Dict, Optional # pylint: disable=W0611
from graphql import GraphQLResolveInfo # pylint: disable=W0611

from .. import state
from .. libs import key_auth
from api.graphql.session.session import Session
Expand Down
6 changes: 4 additions & 2 deletions src/services/api/graphql/libs/op_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2022-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -16,7 +16,9 @@
import os
import re
import typing
from typing import Union, Tuple, Optional

from typing import Union
from typing import Optional
from humps import decamelize

from vyos.defaults import directories
Expand Down
11 changes: 1 addition & 10 deletions src/services/api/graphql/session/composite/system_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2022 VyOS maintainers and contributors
# Copyright (C) 2022-2024 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
Expand All @@ -13,15 +13,6 @@
#
# 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 os
import sys
import json
import importlib.util

from vyos.defaults import directories

from api.graphql.libs.op_mode import load_op_mode_as_module

Expand Down
3 changes: 1 addition & 2 deletions src/services/api/graphql/session/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2021-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,7 +21,6 @@
from vyos.config import Config
from vyos.configtree import ConfigTree
from vyos.defaults import directories
from vyos.template import render
from vyos.opmode import Error as OpModeError

from api.graphql.libs.op_mode import load_op_mode_as_module, split_compound_op_mode_name
Expand Down

0 comments on commit 3099c96

Please sign in to comment.