Skip to content

Commit 1af30af

Browse files
committed
fix(python): Fix whitespaces
Signed-off-by: Steffen Vogel <[email protected]>
1 parent 38dc435 commit 1af30af

File tree

12 files changed

+115
-75
lines changed

12 files changed

+115
-75
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ test:python:
162162
script:
163163
- cd python
164164
- pytest --verbose .
165-
- black --extend-exclude=".*(\\.pyi|_pb2.py)$" --check .
166-
- flake8 --extend-exclude="*.pyi,*_pb2.py" .
165+
- black --line-length=90 --extend-exclude=".*(\\.pyi|_pb2.py)$" --check .
166+
- flake8 --max-line-length=90 --extend-exclude="*.pyi,*_pb2.py" .
167167
- mypy .
168168
image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG}
169169
needs:

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ repos:
5050
hooks:
5151
- id: black-jupyter
5252
exclude: .*_pb2.pyi?$
53+
args:
54+
- --line-length=90
55+
56+
- repo: https://github.com/pycqa/flake8
57+
rev: "7.3.0"
58+
hooks:
59+
- id: flake8
60+
exclude: .*_pb2.pyi?$
61+
args:
62+
- --max-line-length=90
5363

5464
- repo: https://github.com/markdownlint/markdownlint
5565
rev: "v0.13.0"

clients/python/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# -*- coding: utf-8 -*-
2-
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2+
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of
3+
# Complex Power Systems, RWTH Aachen University
34
# SPDX-License-Identifier: Apache-2.0
45

56
import villas_pb2
6-
import time, socket, errno, sys, os, signal
7+
import time
8+
import socket
9+
import errno
10+
import sys
11+
import os
12+
import signal
713

814
layer = sys.argv[1] if len(sys.argv) == 2 else "udp"
915

@@ -50,6 +56,7 @@
5056

5157
# Gracefully shutdown
5258
def sighandler(signum, frame):
59+
global running
5360
running = False
5461

5562

etc/python/example.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
villas node <(python3 etc/python/example.py)
1010
1111
Author: Steffen Vogel <[email protected]>
12-
SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
12+
SPDX-FileCopyrightText: 2014-2023 Institute for Automation of
13+
Complex Power Systems, RWTH Aachen University
1314
SPDX-License-Identifier: Apache-2.0
1415
"""
1516

@@ -38,7 +39,10 @@
3839
"type": "socket",
3940
"layer": "udp",
4041
"format": "protobuf",
41-
"in": {"address": "*:12000", "signals": [{"name": "in", "type": "float"}]},
42+
"in": {
43+
"address": "*:12000",
44+
"signals": [{"name": "in", "type": "float"}],
45+
},
4246
"out": {"address": f"5.6.7.8:{port}"},
4347
}
4448

lib/nodes/example.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ class ExampleNode : public Node {
6666

6767
public:
6868
ExampleNode(const uuid_t &id = {}, const std::string &name = "")
69-
: Node(id, name), setting1(72), setting2("something"), state1(0) {}
69+
: Node(id, name), setting1(72), setting2("something"), state1(0) {}
7070

7171
/* All of the following virtual-declared functions are optional.
7272
* Have a look at node.hpp/node.cpp for the default behaviour.
7373
*/
7474

75-
virtual ~ExampleNode() { }
75+
virtual ~ExampleNode() {}
7676

7777
int prepare() override {
7878
state1 = setting1;
@@ -90,7 +90,7 @@ class ExampleNode : public Node {
9090

9191
json_error_t err;
9292
int ret = json_unpack_ex(json, &err, 0, "{ s?: i, s?: s }", "setting1",
93-
&setting1, "setting2", &setting2_str);
93+
&setting1, "setting2", &setting2_str);
9494
if (ret)
9595
throw ConfigError(json, err, "node-config-node-example");
9696

python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ignore_missing_imports = true
5454

5555
[tool.black]
5656
extend-exclude = '''.*(\.pyi|_pb2.py)$'''
57+
line-length = 90
5758

5859
[tool.setuptools.packages.find]
5960
include = ["villas.node"]

python/villas/node/formats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ def load_sample(self, sample: str) -> Sample | None:
156156
return None
157157

158158
m = re.match(
159-
r"(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?"
160-
r"(?:e[+-]?\d+)?)?(?:\((\d+)\))?(F)?",
159+
r"(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?" r"(?:e[+-]?\d+)?)?(?:\((\d+)\))?(F)?",
161160
fields[0],
162161
)
163162

python/villas/node/node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,18 @@ def load_config(self, i):
128128
def request(self, action, method="GET", **args):
129129
timeout = args.get("timeout", 1)
130130
json_data = args.get("json")
131-
131+
132132
url = f"{self.api_url}/api/{self.api_version}/{action}"
133-
133+
134134
# Prepare the request
135135
req = urllib.request.Request(url, method=method)
136-
136+
137137
# Add JSON data if provided
138138
if json_data:
139139
req.add_header("Content-Type", "application/json")
140140
data = json.dumps(json_data).encode("utf-8")
141141
req.data = data
142-
142+
143143
try:
144144
with urllib.request.urlopen(req, timeout=timeout) as response:
145145
return json.loads(response.read().decode("utf-8"))

python/villas/node/opal_orchestra_ddf.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
Author: Steffen Vogel <[email protected]>
3+
SPDX-FileCopyrightText: 2025 OPAL-RT Germany GmbH
4+
SPDX-License-Identifier: Apache-2.0
5+
""" # noqa: E501
6+
17
import argparse
28
import sys
39
import xml.etree.ElementTree as ET
@@ -14,7 +20,8 @@ def generate_ddf(node_cfg):
1420
Generate an OPAL-RT Orchestra DDF XML file from a VILLASnode configuration.
1521
1622
Args:
17-
node_cfg: Dictionary containing the node configuration from VILLASnode config
23+
node_cfg: Dictionary containing the node configuration
24+
from VILLASnode config
1825
1926
Returns:
2027
str: XML-encoded string representing the Orchestra DDF
@@ -65,16 +72,15 @@ def generate_ddf(node_cfg):
6572

6673
def add_connection(parent_elem, conn_cfg):
6774
"""
68-
Add a connection element to the parent XML element based on connection configuration.
75+
Add a connection element to the parent XML element based
76+
on connection configuration.
6977
7078
Args:
7179
parent_elem: ET.Element to add the connection to
7280
conn_cfg: Dictionary containing connection configuration
7381
"""
7482
conn_type = conn_cfg.get("type", "local")
7583

76-
conn_attrs = {}
77-
7884
if conn_type == "local":
7985
conn_elem = ET.SubElement(
8086
parent_elem,
@@ -118,7 +124,8 @@ def add_signals_to_set(parent_elem, signals, is_publish=True):
118124
Args:
119125
parent_elem: ET.Element to add signals to
120126
signals: List of signal configurations
121-
is_publish: Boolean indicating if this is for PUBLISH (True) or SUBSCRIBE (False)
127+
is_publish: Boolean indicating if this is for
128+
PUBLISH (True) or SUBSCRIBE (False)
122129
"""
123130
# Group signals by their orchestra names and build nested structure
124131
signal_tree = {}
@@ -155,11 +162,11 @@ def add_signals_to_set(parent_elem, signals, is_publish=True):
155162
else:
156163
if orchestra_type != signal["type"]:
157164
raise RuntimeError(
158-
f"Conflicting definitions for signal '{orchestra_name}'"
165+
"Conflicting definitions for signal " + f"'{orchestra_name}'"
159166
)
160167

161168
index = orchestra_index
162-
if index == None:
169+
if index is None:
163170
index = signal["length"]
164171

165172
if index >= signal["length"]:
@@ -210,7 +217,10 @@ def build_xml_from_tree(parent_elem, tree, is_publish):
210217
else:
211218
default_text = str(default_val)
212219
else:
213-
default_text = "0" if signal["type"] != "boolean" else "no"
220+
if signal["type"] == "boolean":
221+
default_text = "no"
222+
else:
223+
default_text = "0"
214224
ET.SubElement(item, "default").text = default_text
215225
elif children:
216226
# This is a bus without direct signals

python/villas/node/villas_pb2.py

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)