Skip to content

Commit e1fd3a6

Browse files
authored
Add "ruff check" to GH actions, clean up the imports (#2627)
1 parent cc2dca1 commit e1fd3a6

File tree

195 files changed

+957
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+957
-755
lines changed

.github/workflows/ruff.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Ruff Python Linting and Formatting
2+
on:
3+
push:
4+
branches-ignore: [ devc ]
5+
paths:
6+
- '**.py'
7+
- 'ruff.toml'
8+
- '.github/workflows/ruff.yml'
9+
10+
pull_request:
11+
paths:
12+
- '**.py'
13+
- 'ruff.toml'
14+
- '.github/workflows/ruff.yml'
15+
16+
jobs:
17+
ruff:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.x'
26+
27+
- name: Install ruff
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install ruff
31+
32+
- name: Run ruff linter
33+
run: |
34+
ruff check --output-format=github .
35+
36+
#- name: Run ruff formatter (check only)
37+
# run: |
38+
# ruff format --check --diff .

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
---
22
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.8.4
5+
hooks:
6+
- id: ruff
7+
name: ruff check
8+
description: This runs ruff check. If errors occur use ruff check --fix.
9+
entry: ruff
10+
args: [ check ]
11+
language: python
12+
types: [python]
13+
314
- repo: local
415
hooks:
516
- id: yamllint

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#
1313
import os
1414
import sys
15+
1516
# sys.path.insert(0, os.path.abspath('.'))
16-
import recommonmark
1717
from recommonmark.transform import AutoStructify
1818

1919
# -- Project information -----------------------------------------------------
@@ -77,7 +77,6 @@
7777
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
7878

7979
if not on_rtd: # only import and set the theme if we're building docs locally
80-
import sphinx_rtd_theme
8180

8281
html_theme = "sphinx_rtd_theme"
8382
## html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

netlab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import sys
77
try:
88
import netsim
99
import netsim.cli
10-
except:
10+
except Exception as ex:
1111
print("Cannot import netsim Python module, netlab installation is broken")
12+
print(ex)
1213
sys.exit(1)
1314

1415
netsim.cli.lab_commands(__file__)

netsim/api/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from box import Box
77

8-
from ..data.validate import must_be_list
9-
from ..utils import log,strings
10-
from ..data import append_to_list,global_vars
8+
from ..data import append_to_list, global_vars
9+
from ..data.types import must_be_list
10+
from ..utils import log, strings
1111

1212
'''
1313
get_config_name: get the name of configuration to be added to node.config attribute

netsim/augment/__init__.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
# Import the whole augmentation tree
22

3-
from . import devices
4-
from . import nodes
5-
from . import groups
6-
from . import links
7-
from . import plugin
8-
from . import topology
9-
from . import config
10-
from . import components
11-
from . import tools
12-
from . import validate
13-
from . import main
3+
from . import components, config, devices, groups, links, main, nodes, plugin, tools, topology, validate

netsim/augment/addressing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@
4848
* _p2p_ and _p2p_subnet_ defaults are used to create _p2p_ pool
4949
'''
5050

51+
import ipaddress
5152
import sys
52-
import typing
5353
import types
54+
import typing
5455

55-
import ipaddress
5656
import netaddr
5757
from box import Box
5858

5959
# Related modules
60-
from ..data import get_empty_box,get_box,null_to_string,global_vars
60+
from ..data import get_box, get_empty_box, global_vars, null_to_string
6161
from ..data.validate import validate_attributes
62-
from ..utils import log,strings
62+
from ..utils import log, strings
63+
6364

6465
def normalize_prefix(pfx: typing.Union[str,Box]) -> Box:
6566

netsim/augment/components.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
* Expands included components into groups, nodes and links
66
'''
77

8-
import typing
9-
import re
108

119
from box import Box
1210

13-
from ..utils import log
1411
from .. import data
15-
from . import nodes,links
16-
from ..data.types import must_be_dict,must_be_list,must_be_string,must_be_id
1712
from ..data import global_vars
13+
from ..data.types import must_be_dict, must_be_id, must_be_string
14+
from ..utils import log
15+
from . import links, nodes
1816

1917
'''
2018
Validate topology components:

netsim/augment/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#
44

55
import typing
6-
from box import Box,BoxList
7-
from ..utils import log,files as _files
6+
7+
from box import Box, BoxList
8+
9+
from ..utils import files as _files
10+
from ..utils import log
811

912
"""
1013
Augment module attributes

netsim/augment/devices.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from box import Box
99

1010
from .. import data
11-
from ..utils import log,strings
11+
from ..utils import log, strings
1212

1313
"""
1414
Get generic device attribute:
@@ -103,7 +103,6 @@ def check_optional_features(
103103
category: typing.Optional[typing.Union[typing.Type[Warning],typing.Type[Exception]]] = None,
104104
features: typing.Optional[Box] = None) -> FC_MODE:
105105

106-
error = False
107106
module = attribute.split('.')[0]
108107
if features is None: # Fetch the initial device features (we'll set the value in recursive calls)
109108
d_features = get_device_features(node,topology.defaults)

0 commit comments

Comments
 (0)