Skip to content

Commit d2cdcfa

Browse files
committed
Code formatting.
This is a huge commit containing following changes: - Code formatting with Black. This includes changing quote styles from single quotes to double quotes. - Linting with Ruff and fixing found issues. - Import sorting and cleanup with Ruff. - Reorganization of multiline imports with isort. Imports that are part of public APIs are excluded. - Manual inspection of all changes. Includes refactoring to make formatting better and some usages of `# fmt: skip`. - Converting string formatting to use f-strings consistently. - Configuration for Black, Ruff and isort in `pyproject.toml`. - Invoke task `invoke format` for running the whole formatting process. This formatting is done only for `src`, `atest` and `utest` directories, but the task allows formatting also other files.
1 parent eb3fb3c commit d2cdcfa

File tree

658 files changed

+34583
-25013
lines changed

Some content is hidden

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

658 files changed

+34583
-25013
lines changed

atest/genrunner.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
Usage: {tool} testdata/path/data.robot [robot/path/runner.robot]
66
"""
77

8-
from os.path import abspath, basename, dirname, exists, join
98
import os
10-
import sys
119
import re
10+
import sys
11+
from os.path import abspath, basename, dirname, exists, join
1212

13-
if len(sys.argv) not in [2, 3] or not all(a.endswith('.robot') for a in sys.argv[1:]):
13+
if len(sys.argv) not in [2, 3] or not all(a.endswith(".robot") for a in sys.argv[1:]):
1414
sys.exit(__doc__.format(tool=basename(sys.argv[0])))
1515

16-
SEPARATOR = re.compile(r'\s{2,}|\t')
16+
SEPARATOR = re.compile(r"\s{2,}|\t")
1717
INPATH = abspath(sys.argv[1])
18-
if join('atest', 'testdata') not in INPATH:
18+
if join("atest", "testdata") not in INPATH:
1919
sys.exit("Input not under 'atest/testdata'.")
2020
if len(sys.argv) == 2:
21-
OUTPATH = INPATH.replace(join('atest', 'testdata'), join('atest', 'robot'))
21+
OUTPATH = INPATH.replace(join("atest", "testdata"), join("atest", "robot"))
2222
else:
2323
OUTPATH = sys.argv[2]
2424

@@ -42,39 +42,45 @@ def __init__(self, name, tags=None):
4242
line = line.rstrip()
4343
if not line:
4444
continue
45-
elif line.startswith('*'):
46-
name = SEPARATOR.split(line)[0].replace('*', '').replace(' ', '').upper()
47-
parsing_tests = name in ('TESTCASE', 'TESTCASES', 'TASK', 'TASKS')
48-
parsing_settings = name in ('SETTING', 'SETTINGS')
49-
elif parsing_tests and not SEPARATOR.match(line) and line[0] != '#':
50-
TESTS.append(TestCase(line.split(' ')[0]))
51-
elif parsing_tests and line.strip().startswith('[Tags]'):
52-
TESTS[-1].tags = line.split('[Tags]', 1)[1].split()
53-
elif parsing_settings and line.startswith(('Force Tags', 'Default Tags', 'Test Tags')):
54-
name, value = line.split(' ', 1)
55-
SETTINGS.append((name, value.strip()))
56-
57-
58-
with open(OUTPATH, 'w') as output:
59-
path = INPATH.split(join('atest', 'testdata'))[1][1:].replace(os.sep, '/')
60-
output.write('''\
45+
elif line.startswith("*"):
46+
name = SEPARATOR.split(line)[0].replace("*", "").replace(" ", "").upper()
47+
parsing_tests = name in ("TESTCASES", "TASKS")
48+
parsing_settings = name == "SETTINGS"
49+
elif parsing_tests and not SEPARATOR.match(line) and line[0] != "#":
50+
TESTS.append(TestCase(SEPARATOR.split(line)[0]))
51+
elif parsing_tests and line.strip().startswith("[Tags]"):
52+
TESTS[-1].tags = line.split("[Tags]", 1)[1].split()
53+
elif parsing_settings and line.startswith("Test Tags"):
54+
name, *values = SEPARATOR.split(line)
55+
SETTINGS.append((name, values))
56+
57+
58+
with open(OUTPATH, "w") as output:
59+
path = INPATH.split(join("atest", "testdata"))[1][1:].replace(os.sep, "/")
60+
output.write(
61+
f"""\
6162
*** Settings ***
62-
Suite Setup Run Tests ${EMPTY} %s
63-
''' % path)
64-
for name, value in SETTINGS:
65-
output.write('%s%s\n' % (name.ljust(18), value))
66-
output.write('''\
63+
Suite Setup Run Tests ${{EMPTY}} {path}
64+
"""
65+
)
66+
for name, values in SETTINGS:
67+
values = " ".join(values)
68+
output.write(f"{name:18}{values}\n")
69+
output.write(
70+
"""\
6771
Resource atest_resource.robot
6872
6973
*** Test Cases ***
70-
''')
74+
"""
75+
)
7176
for test in TESTS:
72-
output.write(test.name + '\n')
77+
output.write(test.name + "\n")
7378
if test.tags:
74-
output.write(' [Tags] %s\n' % ' '.join(test.tags))
75-
output.write(' Check Test Case ${TESTNAME}\n')
79+
tags = " ".join(test.tags)
80+
output.write(f" [Tags] {tags}\n")
81+
output.write(" Check Test Case ${TESTNAME}\n")
7682
if test is not TESTS[-1]:
77-
output.write('\n')
83+
output.write("\n")
7884

7985

8086
print(OUTPATH)

atest/interpreter.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import sys
55
from pathlib import Path
66

7-
8-
ROBOT_DIR = Path(__file__).parent.parent / 'src/robot'
7+
ROBOT_DIR = Path(__file__).parent.parent / "src/robot"
98

109

1110
def get_variables(path, name=None, version=None):
12-
return {'INTERPRETER': Interpreter(path, name, version)}
11+
return {"INTERPRETER": Interpreter(path, name, version)}
1312

1413

1514
class Interpreter:
@@ -21,93 +20,97 @@ def __init__(self, path, name=None, version=None):
2120
name, version = self._get_name_and_version()
2221
self.name = name
2322
self.version = version
24-
self.version_info = tuple(int(item) for item in version.split('.'))
23+
self.version_info = tuple(int(item) for item in version.split("."))
2524

2625
def _get_interpreter(self, path):
27-
path = path.replace('/', os.sep)
26+
path = path.replace("/", os.sep)
2827
return [path] if os.path.exists(path) else path.split()
2928

3029
def _get_name_and_version(self):
3130
try:
32-
output = subprocess.check_output(self.interpreter + ['-V'],
33-
stderr=subprocess.STDOUT,
34-
encoding='UTF-8')
31+
output = subprocess.check_output(
32+
self.interpreter + ["-V"],
33+
stderr=subprocess.STDOUT,
34+
encoding="UTF-8",
35+
)
3536
except (subprocess.CalledProcessError, FileNotFoundError) as err:
36-
raise ValueError(f'Failed to get interpreter version: {err}')
37+
raise ValueError(f"Failed to get interpreter version: {err}")
3738
name, version = output.split()[:2]
38-
name = name if 'PyPy' not in output else 'PyPy'
39-
version = re.match(r'\d+\.\d+\.\d+', version).group()
39+
name = name if "PyPy" not in output else "PyPy"
40+
version = re.match(r"\d+\.\d+\.\d+", version).group()
4041
return name, version
4142

4243
@property
4344
def os(self):
44-
for condition, name in [(self.is_linux, 'Linux'),
45-
(self.is_osx, 'OS X'),
46-
(self.is_windows, 'Windows')]:
45+
for condition, name in [
46+
(self.is_linux, "Linux"),
47+
(self.is_osx, "OS X"),
48+
(self.is_windows, "Windows"),
49+
]:
4750
if condition:
4851
return name
4952
return sys.platform
5053

5154
@property
5255
def output_name(self):
53-
return f'{self.name}-{self.version}-{self.os}'.replace(' ', '')
56+
return f"{self.name}-{self.version}-{self.os}".replace(" ", "")
5457

5558
@property
5659
def excludes(self):
5760
if self.is_pypy:
58-
yield 'no-pypy'
59-
yield 'require-lxml'
61+
yield "no-pypy"
62+
yield "require-lxml"
6063
for require in [(3, 9), (3, 10), (3, 14)]:
6164
if self.version_info < require:
62-
yield 'require-py%d.%d' % require
65+
yield "require-py%d.%d" % require
6366
if self.is_windows:
64-
yield 'no-windows'
67+
yield "no-windows"
6568
if not self.is_windows:
66-
yield 'require-windows'
69+
yield "require-windows"
6770
if self.is_osx:
68-
yield 'no-osx'
71+
yield "no-osx"
6972
if not self.is_linux:
70-
yield 'require-linux'
73+
yield "require-linux"
7174

7275
@property
7376
def is_python(self):
74-
return self.name == 'Python'
77+
return self.name == "Python"
7578

7679
@property
7780
def is_pypy(self):
78-
return self.name == 'PyPy'
81+
return self.name == "PyPy"
7982

8083
@property
8184
def is_linux(self):
82-
return 'linux' in sys.platform
85+
return "linux" in sys.platform
8386

8487
@property
8588
def is_osx(self):
86-
return sys.platform == 'darwin'
89+
return sys.platform == "darwin"
8790

8891
@property
8992
def is_windows(self):
90-
return os.name == 'nt'
93+
return os.name == "nt"
9194

9295
@property
9396
def runner(self):
94-
return self.interpreter + [str(ROBOT_DIR / 'run.py')]
97+
return self.interpreter + [str(ROBOT_DIR / "run.py")]
9598

9699
@property
97100
def rebot(self):
98-
return self.interpreter + [str(ROBOT_DIR / 'rebot.py')]
101+
return self.interpreter + [str(ROBOT_DIR / "rebot.py")]
99102

100103
@property
101104
def libdoc(self):
102-
return self.interpreter + [str(ROBOT_DIR / 'libdoc.py')]
105+
return self.interpreter + [str(ROBOT_DIR / "libdoc.py")]
103106

104107
@property
105108
def testdoc(self):
106-
return self.interpreter + [str(ROBOT_DIR / 'testdoc.py')]
109+
return self.interpreter + [str(ROBOT_DIR / "testdoc.py")]
107110

108111
@property
109112
def underline(self):
110-
return '-' * len(str(self))
113+
return "-" * len(str(self))
111114

112115
def __str__(self):
113-
return f'{self.name} {self.version} on {self.os}'
116+
return f"{self.name} {self.version} on {self.os}"

0 commit comments

Comments
 (0)