Skip to content

Commit d4d737e

Browse files
committed
[qa] Format code with latest version of qa-format tool
1 parent 0f77be2 commit d4d737e

Some content is hidden

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

47 files changed

+2693
-2717
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ updates:
1212
commit-message:
1313
prefix: "[deps] "
1414
- package-ecosystem: "github-actions" # Check for GitHub Actions updates
15-
directory: "/"
15+
directory: "/"
1616
schedule:
1717
interval: "monthly" # Check for updates weekly
1818
commit-message:

.github/workflows/ci.yml

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
- gsoc23
1212

1313
jobs:
14-
1514
build:
1615
name: Python==${{ matrix.python-version }}
1716
runs-on: ubuntu-22.04
@@ -26,42 +25,42 @@ jobs:
2625
- "3.13"
2726

2827
steps:
29-
- uses: actions/checkout@v4
30-
with:
31-
ref: ${{ github.event.pull_request.head.sha }}
28+
- uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.event.pull_request.head.sha }}
3231

33-
- name: Set up Python ${{ matrix.python-version }}
34-
uses: actions/setup-python@v5
35-
with:
36-
python-version: ${{ matrix.python-version }}
37-
cache: 'pip'
38-
cache-dependency-path: |
39-
**/requirements*.txt
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
cache: "pip"
37+
cache-dependency-path: |
38+
**/requirements*.txt
4039
41-
- name: Install Dependencies
42-
id: deps
43-
run: |
44-
pip install -U pip wheel setuptools
45-
pip install -U -r requirements-test.txt
46-
pip install -U -e .
40+
- name: Install Dependencies
41+
id: deps
42+
run: |
43+
pip install -U pip wheel setuptools
44+
pip install -U -r requirements-test.txt
45+
pip install -U -e .
4746
48-
- name: QA checks
49-
run: ./run-qa-checks
47+
- name: QA checks
48+
run: ./run-qa-checks
5049

51-
- name: Tests
52-
if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
53-
run: |
54-
coverage run runtests.py
55-
coverage xml
50+
- name: Tests
51+
if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
52+
run: |
53+
coverage run runtests.py
54+
coverage xml
5655
57-
- name: Upload Coverage
58-
if: ${{ success() }}
59-
uses: coverallsapp/github-action@v2
60-
with:
61-
parallel: true
62-
format: cobertura
63-
flag-name: python-${{ matrix.env.env }}
64-
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
- name: Upload Coverage
57+
if: ${{ success() }}
58+
uses: coverallsapp/github-action@v2
59+
with:
60+
parallel: true
61+
format: cobertura
62+
flag-name: python-${{ matrix.env.env }}
63+
github-token: ${{ secrets.GITHUB_TOKEN }}
6564

6665
coveralls:
6766
needs: build

.github/workflows/pypi.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ jobs:
1717
permissions:
1818
id-token: write
1919
steps:
20-
- uses: actions/checkout@v4
21-
- name: Set up Python
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: '3.10'
25-
- name: Install dependencies
26-
run: |
27-
pip install -U pip
28-
pip install build
29-
- name: Build package
30-
run: python -m build
31-
- name: Publish package distributions to PyPI
32-
uses: pypa/[email protected]
20+
- uses: actions/checkout@v4
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.10"
25+
- name: Install dependencies
26+
run: |
27+
pip install -U pip
28+
pip install build
29+
- name: Build package
30+
run: python -m build
31+
- name: Publish package distributions to PyPI
32+
uses: pypa/[email protected]

README.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ HTTPS example with self-signed SSL certificate using ``verify=False``:
309309
310310
from netdiff import NetJsonParser
311311
312-
OlsrParser(
313-
url="https://myserver.mydomain.com/topology.json", verify=False
314-
)
312+
OlsrParser(url="https://myserver.mydomain.com/topology.json", verify=False)
315313
316314
NetJSON output
317315
--------------

netdiff/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConversionException(NetdiffException):
1515
"""
1616

1717
def __init__(self, *args, **kwargs):
18-
self.data = kwargs.pop('data')
18+
self.data = kwargs.pop("data")
1919

2020

2121
class ParserError(NetdiffException):

netdiff/info.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
VERSION = (1, 2, 0, 'alpha')
1+
VERSION = (1, 2, 0, "alpha")
22
__version__ = VERSION
33

44

55
def get_version():
6-
version = '%s.%s' % (VERSION[0], VERSION[1])
6+
version = "%s.%s" % (VERSION[0], VERSION[1])
77
if VERSION[2]:
8-
version = '%s.%s' % (version, VERSION[2])
9-
if VERSION[3:] == ('alpha', 0):
10-
version = '%s pre-alpha' % version
8+
version = "%s.%s" % (version, VERSION[2])
9+
if VERSION[3:] == ("alpha", 0):
10+
version = "%s pre-alpha" % version
1111
else:
12-
if VERSION[3] != 'final':
12+
if VERSION[3] != "final":
1313
try:
1414
rev = VERSION[4]
1515
except IndexError:
1616
rev = 0
17-
version = '%s%s%s' % (version, VERSION[3][0:1], rev)
17+
version = "%s%s%s" % (version, VERSION[3][0:1], rev)
1818
return version

netdiff/parsers/base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def __init__(
6666
data = self._get_file(file)
6767
elif data is None and url is None and file is None:
6868
raise ValueError(
69-
'no topology data supplied, on of the following arguments'
70-
'must be supplied: data, url or file'
69+
"no topology data supplied, on of the following arguments"
70+
"must be supplied: data, url or file"
7171
)
7272
self.original_data = self.to_python(data)
7373
# avoid throwing NotImplementedError in tests
@@ -76,9 +76,9 @@ def __init__(
7676

7777
def _get_url(self, url):
7878
url = urlparse.urlparse(url)
79-
if url.scheme in ['http', 'https']:
79+
if url.scheme in ["http", "https"]:
8080
return self._get_http(url)
81-
if url.scheme == 'telnet':
81+
if url.scheme == "telnet":
8282
return self._get_telnet(url)
8383

8484
def __sub__(self, other):
@@ -102,7 +102,7 @@ def to_python(self, data):
102102
return json.loads(data)
103103
except ValueError:
104104
pass
105-
raise ConversionException('Could not recognize format', data=data)
105+
raise ConversionException("Could not recognize format", data=data)
106106

107107
def _get_file(self, path):
108108
try:
@@ -118,7 +118,7 @@ def _get_http(self, url):
118118
except Exception as e:
119119
raise TopologyRetrievalError(e)
120120
if response.status_code != 200:
121-
msg = 'Expecting HTTP 200 ok, got {0}'.format(response.status_code)
121+
msg = "Expecting HTTP 200 ok, got {0}".format(response.status_code)
122122
raise TopologyRetrievalError(msg)
123123
return response.content.decode()
124124

@@ -127,8 +127,8 @@ def _get_telnet(self, url):
127127
tn = telnetlib.Telnet(url.hostname, url.port, timeout=self.timeout)
128128
except Exception as e:
129129
raise TopologyRetrievalError(e)
130-
tn.write(("\r\n").encode('ascii'))
131-
data = tn.read_all().decode('ascii')
130+
tn.write(("\r\n").encode("ascii"))
131+
data = tn.read_all().decode("ascii")
132132
tn.close()
133133
return data
134134

netdiff/parsers/batman.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class BatmanParser(BaseParser):
66
"""batman-adv parser"""
77

8-
protocol = 'batman-adv'
9-
version = '2015.0'
10-
metric = 'TQ'
8+
protocol = "batman-adv"
9+
version = "2015.0"
10+
metric = "TQ"
1111

1212
# the default expected format
13-
_format = 'alfred_vis'
13+
_format = "alfred_vis"
1414

1515
def to_python(self, data):
1616
"""
@@ -25,20 +25,20 @@ def _txtinfo_to_python(self, data):
2525
"""
2626
Converts txtinfo format to python
2727
"""
28-
self._format = 'txtinfo'
28+
self._format = "txtinfo"
2929
# find interesting section
30-
lines = data.split('\n')
30+
lines = data.split("\n")
3131
try:
32-
start = lines.index('Table: Topology') + 2
32+
start = lines.index("Table: Topology") + 2
3333
except ValueError:
34-
raise ParserError('Unrecognized format')
34+
raise ParserError("Unrecognized format")
3535
topology_lines = [line for line in lines[start:] if line]
3636
# convert to python list
3737
parsed_lines = []
3838
for line in topology_lines:
39-
values = line.split(' ')
39+
values = line.split(" ")
4040
parsed_lines.append(
41-
{'source': values[0], 'target': values[1], 'cost': float(values[4])}
41+
{"source": values[0], "target": values[1], "cost": float(values[4])}
4242
)
4343
return parsed_lines
4444

@@ -59,9 +59,9 @@ def _get_aggregated_node_list(self, data):
5959
"""
6060
node_list = []
6161
for node in data:
62-
local_addresses = [node['primary']]
63-
if 'secondary' in node:
64-
local_addresses += node['secondary']
62+
local_addresses = [node["primary"]]
63+
if "secondary" in node:
64+
local_addresses += node["secondary"]
6565
node_list.append(local_addresses)
6666
return node_list
6767

@@ -72,7 +72,7 @@ def parse(self, data):
7272
* alfred_vis
7373
* txtinfo
7474
"""
75-
method = getattr(self, '_parse_{0}'.format(self._format))
75+
method = getattr(self, "_parse_{0}".format(self._format))
7676
return method(data)
7777

7878
def _parse_alfred_vis(self, data):
@@ -83,26 +83,26 @@ def _parse_alfred_vis(self, data):
8383
"""
8484
# initialize graph and list of aggregated nodes
8585
graph = self._init_graph()
86-
if 'source_version' in data:
87-
self.version = data['source_version']
88-
if 'vis' not in data:
86+
if "source_version" in data:
87+
self.version = data["source_version"]
88+
if "vis" not in data:
8989
raise ParserError('Parse error, "vis" key not found')
90-
node_list = self._get_aggregated_node_list(data['vis'])
90+
node_list = self._get_aggregated_node_list(data["vis"])
9191

9292
# loop over topology section and create networkx graph
9393
for node in data["vis"]:
9494
for neigh in node["neighbors"]:
9595
graph.add_node(
96-
node['primary'],
96+
node["primary"],
9797
**{
98-
'local_addresses': node.get('secondary', []),
99-
'clients': node.get('clients', []),
98+
"local_addresses": node.get("secondary", []),
99+
"clients": node.get("clients", []),
100100
}
101101
)
102-
primary_neigh = self._get_primary_address(neigh['neighbor'], node_list)
102+
primary_neigh = self._get_primary_address(neigh["neighbor"], node_list)
103103
# networkx automatically ignores duplicated edges
104104
graph.add_edge(
105-
node['primary'], primary_neigh, weight=float(neigh['metric'])
105+
node["primary"], primary_neigh, weight=float(neigh["metric"])
106106
)
107107
return graph
108108

@@ -113,5 +113,5 @@ def _parse_txtinfo(self, data):
113113
"""
114114
graph = self._init_graph()
115115
for link in data:
116-
graph.add_edge(link['source'], link['target'], weight=link['cost'])
116+
graph.add_edge(link["source"], link["target"], weight=link["cost"])
117117
return graph

netdiff/parsers/bmx6.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
class Bmx6Parser(BaseParser):
66
"""Bmx6_b6m parser"""
77

8-
protocol = 'BMX6_b6m'
9-
version = '0'
10-
metric = 'none'
8+
protocol = "BMX6_b6m"
9+
version = "0"
10+
metric = "none"
1111

1212
def parse(self, data):
1313
"""
@@ -22,13 +22,13 @@ def parse(self, data):
2222
# loop over topology section and create networkx graph
2323
# this data structure does not contain cost information, so we set it as 1
2424
for node in data:
25-
for link in node['links']:
26-
cost = (link['txRate'] + link['rxRate']) / 2.0
25+
for link in node["links"]:
26+
cost = (link["txRate"] + link["rxRate"]) / 2.0
2727
graph.add_edge(
28-
node['name'],
29-
link['name'],
28+
node["name"],
29+
link["name"],
3030
weight=cost,
31-
tx_rate=link['txRate'],
32-
rx_rate=link['rxRate'],
31+
tx_rate=link["txRate"],
32+
rx_rate=link["rxRate"],
3333
)
3434
return graph

netdiff/parsers/cnml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
class CnmlParser(BaseParser):
1515
"""CNML 0.1 parser"""
1616

17-
protocol = 'static'
17+
protocol = "static"
1818
version = None
1919
metric = None
2020

2121
def to_python(self, data):
2222
if isinstance(data, str):
2323
up = urlparse.urlparse(data)
2424
# if it looks like a file path
25-
if os.path.isfile(data) or up.scheme in ['http', 'https']:
25+
if os.path.isfile(data) or up.scheme in ["http", "https"]:
2626
return libcnml.CNMLParser(data)
2727
else:
28-
raise ParserError('Could not decode CNML data')
28+
raise ParserError("Could not decode CNML data")
2929
elif isinstance(data, libcnml.CNMLParser):
3030
return data
3131
else:
32-
raise ParserError('Could not find valid data to parse')
32+
raise ParserError("Could not find valid data to parse")
3333

3434
def parse(self, data):
3535
"""

0 commit comments

Comments
 (0)