Skip to content

Commit

Permalink
Merge pull request #3240 from c-po/spring-cleaning
Browse files Browse the repository at this point in the history
T6199: spring cleaning - drop unused Python imports
  • Loading branch information
c-po authored Apr 3, 2024
2 parents fe09b76 + 74198e6 commit d4b53a3
Show file tree
Hide file tree
Showing 141 changed files with 226 additions and 936 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/unused-imports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pylint

on: [push]

jobs:
build:
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: |
make unused-imports
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ endif
sonar:
sonar-scanner -X -Dsonar.login=${SONAR_TOKEN}

.PHONY: docs
.ONESHELL:
docs:
sphinx-apidoc -o sphinx/source/ python/
cd sphinx/
PYTHONPATH=../python make html
.PHONY: unused-imports
unused-imports:
git ls-files *.py | xargs pylint | grep W0611

deb:
dpkg-buildpackage -uc -us -tc -b
Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Build-Depends:
python3-jinja2,
python3-psutil,
python3-setuptools,
python3-sphinx,
quilt,
whois
Standards-Version: 3.9.6
Expand Down
7 changes: 1 addition & 6 deletions python/vyos/accel_ppp.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,14 +13,9 @@
#
# 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 sys

import vyos.opmode
from vyos.utils.process import rc_cmd


def get_server_statistics(accel_statistics, pattern, sep=':') -> dict:
import re

Expand Down
4 changes: 1 addition & 3 deletions python/vyos/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017, 2019-2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2017-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 Down Expand Up @@ -60,12 +60,10 @@
while functions prefixed "effective" return values from the running config.
In operational mode, all functions return values from the running config.
"""

import re
import json
from copy import deepcopy
from typing import Union

import vyos.configtree
Expand Down
17 changes: 11 additions & 6 deletions python/vyos/config_mgmt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2023-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 @@ -19,18 +19,23 @@
import gzip
import logging

from typing import Optional, Tuple, Union
from typing import Optional
from typing import Tuple
from filecmp import cmp
from datetime import datetime
from textwrap import dedent, indent
from textwrap import dedent
from pathlib import Path
from tabulate import tabulate
from shutil import copy, chown
from urllib.parse import urlsplit, urlunsplit
from urllib.parse import urlsplit
from urllib.parse import urlunsplit

from vyos.config import Config
from vyos.configtree import ConfigTree, ConfigTreeError, show_diff
from vyos.load_config import load, LoadConfigError
from vyos.configtree import ConfigTree
from vyos.configtree import ConfigTreeError
from vyos.configtree import show_diff
from vyos.load_config import load
from vyos.load_config import LoadConfigError
from vyos.defaults import directories
from vyos.version import get_full_version_data
from vyos.utils.io import ask_yes_no
Expand Down
4 changes: 1 addition & 3 deletions python/vyos/configdict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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 Down Expand Up @@ -203,8 +203,6 @@ def is_member(conf, interface, intftype=None):
empty -> Interface is not a member
key -> Interface is a member of this interface
"""
from vyos.ifconfig import Section

ret_val = {}
intftypes = ['bonding', 'bridge']

Expand Down
6 changes: 3 additions & 3 deletions python/vyos/configdiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 VyOS maintainers and contributors <[email protected]>
# Copyright 2020-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,12 +13,12 @@
# 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 enum import IntFlag, auto
from enum import IntFlag
from enum import auto

from vyos.config import Config
from vyos.configtree import DiffTree
from vyos.configdict import dict_merge
from vyos.configdict import list_diff
from vyos.utils.dict import get_sub_dict
from vyos.utils.dict import mangle_dict_keys
from vyos.utils.dict import dict_search_args
Expand Down
7 changes: 2 additions & 5 deletions python/vyos/configverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

from vyos import ConfigError
from vyos.utils.dict import dict_search
from vyos.utils.dict import dict_search_recursive

# pattern re-used in ipsec migration script
dynamic_interface_pattern = r'(ppp|pppoe|sstpc|l2tp|ipoe)[0-9]+'

Expand Down Expand Up @@ -246,7 +244,6 @@ def verify_interface_exists(ifname, warning_only=False):
if the interface is defined on the CLI, if it's not found we try if
it exists at the OS level.
"""
import os
from vyos.base import Warning
from vyos.configquery import ConfigTreeQuery
from vyos.utils.dict import dict_search_recursive
Expand Down Expand Up @@ -275,7 +272,7 @@ def verify_source_interface(config):
required by e.g. peth/MACvlan, MACsec ...
"""
import re
from netifaces import interfaces
from vyos.utils.network import interface_exists

ifname = config['ifname']
if 'source_interface' not in config:
Expand All @@ -287,7 +284,7 @@ def verify_source_interface(config):
if tmp.match(src_ifname):
raise ConfigError(f'Can not source "{ifname}" from dynamic interface "{src_ifname}"!')

if src_ifname not in interfaces():
if not interface_exists(src_ifname):
raise ConfigError(f'Specified source-interface {src_ifname} does not exist')

if 'source_interface_is_bridge_member' in config:
Expand Down
1 change: 0 additions & 1 deletion python/vyos/ethtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# 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 os
import re

from json import loads
Expand Down
3 changes: 1 addition & 2 deletions python/vyos/firewall.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2021-2023 VyOS maintainers and contributors
# Copyright (C) 2021-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 Down Expand Up @@ -30,7 +30,6 @@
from vyos.template import render
from vyos.utils.dict import dict_search_args
from vyos.utils.dict import dict_search_recursive
from vyos.utils.process import call
from vyos.utils.process import cmd
from vyos.utils.process import run

Expand Down
3 changes: 1 addition & 2 deletions python/vyos/frr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 VyOS maintainers and contributors <[email protected]>
# Copyright 2020-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 Down Expand Up @@ -69,7 +69,6 @@
import re

from vyos import ConfigError
from vyos.utils.permission import chown
from vyos.utils.process import cmd
from vyos.utils.process import popen
from vyos.utils.process import STDOUT
Expand Down
3 changes: 1 addition & 2 deletions python/vyos/ifconfig/bond.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2022 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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,6 @@
import os

from vyos.ifconfig.interface import Interface
from vyos.utils.process import cmd
from vyos.utils.dict import dict_search
from vyos.utils.assertion import assert_list
from vyos.utils.assertion import assert_positive
Expand Down
7 changes: 3 additions & 4 deletions python/vyos/ifconfig/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
# 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 netifaces import interfaces

from vyos.ifconfig.interface import Interface
from vyos.utils.assertion import assert_boolean
from vyos.utils.assertion import assert_list
from vyos.utils.assertion import assert_positive
from vyos.utils.dict import dict_search
from vyos.utils.network import interface_exists
from vyos.configdict import get_vlan_ids
from vyos.configdict import list_diff

Expand Down Expand Up @@ -314,7 +313,7 @@ def update(self, config):
# remove interface from bridge
tmp = dict_search('member.interface_remove', config)
for member in (tmp or []):
if member in interfaces():
if interface_exists(member):
self.del_port(member)

# enable/disable VLAN Filter
Expand Down Expand Up @@ -345,7 +344,7 @@ def update(self, config):
for interface, interface_config in tmp.items():
# if interface does yet not exist bail out early and
# add it later
if interface not in interfaces():
if not interface_exists(interface):
continue

# Bridge lower "physical" interface
Expand Down
1 change: 0 additions & 1 deletion python/vyos/ifconfig/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from vyos.template import render
from vyos.utils.network import mac2eui64
from vyos.utils.dict import dict_search
from vyos.utils.file import read_file
from vyos.utils.network import get_interface_config
from vyos.utils.network import get_interface_namespace
from vyos.utils.network import is_netns_interface
Expand Down
4 changes: 1 addition & 3 deletions python/vyos/ifconfig/vrrp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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 @@ -18,7 +18,6 @@
import signal

from time import time
from time import sleep
from tabulate import tabulate

from vyos.configquery import ConfigTreeQuery
Expand Down Expand Up @@ -155,4 +154,3 @@ def format(cls, data):
# add to the active list disabled instances
groups.extend(cls.disabled())
return(tabulate(groups, headers))

5 changes: 1 addition & 4 deletions python/vyos/ifconfig/vxlan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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,9 +13,6 @@
# 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 json import loads

from vyos import ConfigError
from vyos.configdict import list_diff
from vyos.ifconfig import Interface
from vyos.utils.assertion import assert_list
Expand Down
3 changes: 1 addition & 2 deletions python/vyos/ifconfig/wireguard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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 @@ -25,7 +25,6 @@
from vyos.ifconfig import Interface
from vyos.ifconfig import Operational
from vyos.template import is_ipv6
from vyos.base import Warning

class WireGuardOperational(Operational):
def _dump(self):
Expand Down
38 changes: 18 additions & 20 deletions python/vyos/iflag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 VyOS maintainers and contributors <[email protected]>
# Copyright 2019-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,26 +13,24 @@
# 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 enum import Enum, unique, IntEnum

from enum import IntEnum

class IFlag(IntEnum):
""" net/if.h interface flags """

IFF_UP = 0x1 #: Interface up/down status
IFF_BROADCAST = 0x2 #: Broadcast address valid
IFF_DEBUG = 0x4, #: Debugging
IFF_LOOPBACK = 0x8 #: Is loopback network
IFF_POINTOPOINT = 0x10 #: Is point-to-point link
IFF_NOTRAILERS = 0x20 #: Avoid use of trailers
IFF_RUNNING = 0x40 #: Resources allocated
IFF_NOARP = 0x80 #: No address resolution protocol
IFF_PROMISC = 0x100 #: Promiscuous mode
IFF_ALLMULTI = 0x200 #: Receive all multicast
IFF_MASTER = 0x400 #: Load balancer master
IFF_SLAVE = 0x800 #: Load balancer slave
IFF_MULTICAST = 0x1000 #: Supports multicast
IFF_PORTSEL = 0x2000 #: Media type adjustable
IFF_AUTOMEDIA = 0x4000 #: Automatic media type enabled
IFF_DYNAMIC = 0x8000 #: Is a dial-up device with dynamic address

IFF_UP = 0x1 #: Interface up/down status
IFF_BROADCAST = 0x2 #: Broadcast address valid
IFF_DEBUG = 0x4, #: Debugging
IFF_LOOPBACK = 0x8 #: Is loopback network
IFF_POINTOPOINT = 0x10 #: Is point-to-point link
IFF_NOTRAILERS = 0x20 #: Avoid use of trailers
IFF_RUNNING = 0x40 #: Resources allocated
IFF_NOARP = 0x80 #: No address resolution protocol
IFF_PROMISC = 0x100 #: Promiscuous mode
IFF_ALLMULTI = 0x200 #: Receive all multicast
IFF_MASTER = 0x400 #: Load balancer master
IFF_SLAVE = 0x800 #: Load balancer slave
IFF_MULTICAST = 0x1000 #: Supports multicast
IFF_PORTSEL = 0x2000 #: Media type adjustable
IFF_AUTOMEDIA = 0x4000 #: Automatic media type enabled
IFF_DYNAMIC = 0x8000 #: Is a dial-up device with dynamic address
Loading

0 comments on commit d4b53a3

Please sign in to comment.