Skip to content

Commit f031500

Browse files
authored
[style] Add autopep8 to restyled.yaml (project-chip#8943)
* [style] Add check for python format * Run Restyle
1 parent 080ae57 commit f031500

File tree

89 files changed

+3224
-2715
lines changed

Some content is hidden

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

89 files changed

+3224
-2715
lines changed

.restyled.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ exclude:
6565
- "third_party/bluez/repo/**/*"
6666
- "third_party/cirque/repo/**/*"
6767
- "third_party/nanopb/repo/**/*"
68+
- "src/controller/python/chip/clusters/CHIPClusters.py" # generated file
6869

6970

7071
changed_paths:
@@ -198,3 +199,13 @@ restylers:
198199
include:
199200
- "**/*.sh"
200201
- "**/*.bash"
202+
- name: autopep8
203+
image: 'restyled/restyler-autopep8:v1.5.7'
204+
command:
205+
- autopep8
206+
- '--in-place'
207+
arguments: []
208+
include:
209+
- '**/*.py'
210+
interpreters:
211+
- python

build/chip/java/jar_runner.py

+50-50
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,69 @@
2828

2929

3030
def IsExecutable(path):
31-
"""Returns whether file at |path| exists and is executable.
31+
"""Returns whether file at |path| exists and is executable.
3232
33-
Args:
34-
path: absolute or relative path to test.
33+
Args:
34+
path: absolute or relative path to test.
3535
36-
Returns:
37-
True if the file at |path| exists, False otherwise.
38-
"""
39-
return os.path.isfile(path) and os.access(path, os.X_OK)
36+
Returns:
37+
True if the file at |path| exists, False otherwise.
38+
"""
39+
return os.path.isfile(path) and os.access(path, os.X_OK)
4040

4141

4242
def FindCommand(command):
43-
"""Looks up for |command| in PATH.
44-
45-
Args:
46-
command: name of the command to lookup, if command is a relative or
47-
absolute path (i.e. contains some path separator) then only that
48-
path will be tested.
49-
50-
Returns:
51-
Full path to command or None if the command was not found.
52-
53-
On Windows, this respects the PATHEXT environment variable when the
54-
command name does not have an extension.
55-
"""
56-
fpath, _ = os.path.split(command)
57-
if fpath:
58-
if IsExecutable(command):
59-
return command
60-
61-
if sys.platform == 'win32':
62-
# On Windows, if the command does not have an extension, cmd.exe will
63-
# try all extensions from PATHEXT when resolving the full path.
64-
command, ext = os.path.splitext(command)
65-
if not ext:
66-
exts = os.environ['PATHEXT'].split(os.path.pathsep)
43+
"""Looks up for |command| in PATH.
44+
45+
Args:
46+
command: name of the command to lookup, if command is a relative or
47+
absolute path (i.e. contains some path separator) then only that
48+
path will be tested.
49+
50+
Returns:
51+
Full path to command or None if the command was not found.
52+
53+
On Windows, this respects the PATHEXT environment variable when the
54+
command name does not have an extension.
55+
"""
56+
fpath, _ = os.path.split(command)
57+
if fpath:
58+
if IsExecutable(command):
59+
return command
60+
61+
if sys.platform == 'win32':
62+
# On Windows, if the command does not have an extension, cmd.exe will
63+
# try all extensions from PATHEXT when resolving the full path.
64+
command, ext = os.path.splitext(command)
65+
if not ext:
66+
exts = os.environ['PATHEXT'].split(os.path.pathsep)
67+
else:
68+
exts = [ext]
6769
else:
68-
exts = [ext]
69-
else:
70-
exts = ['']
70+
exts = ['']
7171

72-
for path in os.environ['PATH'].split(os.path.pathsep):
73-
for ext in exts:
74-
path = os.path.join(path, command) + ext
75-
if IsExecutable(path):
76-
return path
72+
for path in os.environ['PATH'].split(os.path.pathsep):
73+
for ext in exts:
74+
path = os.path.join(path, command) + ext
75+
if IsExecutable(path):
76+
return path
7777

78-
return None
78+
return None
7979

8080

8181
def main():
82-
java_path = FindCommand('jar')
83-
if not java_path:
84-
sys.stderr.write('jar: command not found\n')
85-
sys.exit(EXIT_FAILURE)
82+
java_path = FindCommand('jar')
83+
if not java_path:
84+
sys.stderr.write('jar: command not found\n')
85+
sys.exit(EXIT_FAILURE)
8686

87-
args = sys.argv[1:]
88-
if len(args) < 1:
89-
sys.stderr.write('usage: %s [jar_args]...\n' % sys.argv[0])
90-
sys.exit(EXIT_FAILURE)
87+
args = sys.argv[1:]
88+
if len(args) < 1:
89+
sys.stderr.write('usage: %s [jar_args]...\n' % sys.argv[0])
90+
sys.exit(EXIT_FAILURE)
9191

92-
return subprocess.check_call([java_path] + args)
92+
return subprocess.check_call([java_path] + args)
9393

9494

9595
if __name__ == '__main__':
96-
sys.exit(main())
96+
sys.exit(main())

build/chip/java/javac_runner.py

+76-76
Original file line numberDiff line numberDiff line change
@@ -28,93 +28,93 @@
2828

2929

3030
def IsExecutable(path):
31-
"""Returns whether file at |path| exists and is executable.
31+
"""Returns whether file at |path| exists and is executable.
3232
33-
Args:
34-
path: absolute or relative path to test.
33+
Args:
34+
path: absolute or relative path to test.
3535
36-
Returns:
37-
True if the file at |path| exists, False otherwise.
38-
"""
39-
return os.path.isfile(path) and os.access(path, os.X_OK)
36+
Returns:
37+
True if the file at |path| exists, False otherwise.
38+
"""
39+
return os.path.isfile(path) and os.access(path, os.X_OK)
4040

4141

4242
def FindCommand(command):
43-
"""Looks up for |command| in PATH.
44-
45-
Args:
46-
command: name of the command to lookup, if command is a relative or absolute
47-
path (i.e. contains some path separator) then only that path will be
48-
tested.
49-
50-
Returns:
51-
Full path to command or None if the command was not found.
52-
53-
On Windows, this respects the PATHEXT environment variable when the
54-
command name does not have an extension.
55-
"""
56-
fpath, _ = os.path.split(command)
57-
if fpath:
58-
if IsExecutable(command):
59-
return command
60-
61-
if sys.platform == 'win32':
62-
# On Windows, if the command does not have an extension, cmd.exe will
63-
# try all extensions from PATHEXT when resolving the full path.
64-
command, ext = os.path.splitext(command)
65-
if not ext:
66-
exts = os.environ['PATHEXT'].split(os.path.pathsep)
43+
"""Looks up for |command| in PATH.
44+
45+
Args:
46+
command: name of the command to lookup, if command is a relative or absolute
47+
path (i.e. contains some path separator) then only that path will be
48+
tested.
49+
50+
Returns:
51+
Full path to command or None if the command was not found.
52+
53+
On Windows, this respects the PATHEXT environment variable when the
54+
command name does not have an extension.
55+
"""
56+
fpath, _ = os.path.split(command)
57+
if fpath:
58+
if IsExecutable(command):
59+
return command
60+
61+
if sys.platform == 'win32':
62+
# On Windows, if the command does not have an extension, cmd.exe will
63+
# try all extensions from PATHEXT when resolving the full path.
64+
command, ext = os.path.splitext(command)
65+
if not ext:
66+
exts = os.environ['PATHEXT'].split(os.path.pathsep)
67+
else:
68+
exts = [ext]
6769
else:
68-
exts = [ext]
69-
else:
70-
exts = ['']
70+
exts = ['']
7171

72-
for path in os.environ['PATH'].split(os.path.pathsep):
73-
for ext in exts:
74-
path = os.path.join(path, command) + ext
75-
if IsExecutable(path):
76-
return path
72+
for path in os.environ['PATH'].split(os.path.pathsep):
73+
for ext in exts:
74+
path = os.path.join(path, command) + ext
75+
if IsExecutable(path):
76+
return path
7777

78-
return None
78+
return None
7979

8080

8181
def main():
82-
java_path = FindCommand('javac')
83-
if not java_path:
84-
sys.stderr.write('javac: command not found\n')
85-
sys.exit(EXIT_FAILURE)
86-
87-
parser = argparse.ArgumentParser('Javac runner')
88-
parser.add_argument(
89-
'--classdir',
90-
dest='classdir',
91-
required=True,
92-
help='Directory that will contain class files')
93-
parser.add_argument(
94-
'--outfile',
95-
dest='outfile',
96-
required=True,
97-
help='Output file containing a list of classes')
98-
parser.add_argument(
99-
'rest', metavar='JAVAC_ARGS', nargs='*', help='Argumets to pass to javac')
100-
101-
args = parser.parse_args()
102-
if not os.path.isdir(args.classdir):
103-
os.makedirs(args.classdir)
104-
retcode = subprocess.check_call([java_path] + args.rest)
105-
if retcode != EXIT_SUCCESS:
106-
return retcode
107-
108-
with open(args.outfile, 'wt') as f:
109-
prefixlen = len(args.classdir) + 1
110-
for root, dirnames, filenames in os.walk(args.classdir):
111-
for filename in filenames:
112-
if filename.endswith('.class'):
113-
f.write(os.path.join(root[prefixlen:], filename))
114-
f.write('\n')
115-
116-
return EXIT_SUCCESS
82+
java_path = FindCommand('javac')
83+
if not java_path:
84+
sys.stderr.write('javac: command not found\n')
85+
sys.exit(EXIT_FAILURE)
86+
87+
parser = argparse.ArgumentParser('Javac runner')
88+
parser.add_argument(
89+
'--classdir',
90+
dest='classdir',
91+
required=True,
92+
help='Directory that will contain class files')
93+
parser.add_argument(
94+
'--outfile',
95+
dest='outfile',
96+
required=True,
97+
help='Output file containing a list of classes')
98+
parser.add_argument(
99+
'rest', metavar='JAVAC_ARGS', nargs='*', help='Argumets to pass to javac')
100+
101+
args = parser.parse_args()
102+
if not os.path.isdir(args.classdir):
103+
os.makedirs(args.classdir)
104+
retcode = subprocess.check_call([java_path] + args.rest)
105+
if retcode != EXIT_SUCCESS:
106+
return retcode
107+
108+
with open(args.outfile, 'wt') as f:
109+
prefixlen = len(args.classdir) + 1
110+
for root, dirnames, filenames in os.walk(args.classdir):
111+
for filename in filenames:
112+
if filename.endswith('.class'):
113+
f.write(os.path.join(root[prefixlen:], filename))
114+
f.write('\n')
115+
116+
return EXIT_SUCCESS
117117

118118

119119
if __name__ == '__main__':
120-
sys.exit(main())
120+
sys.exit(main())

build/chip/linux/gen_gdbus_wrapper.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def main(argv):
2828

2929
parser.add_argument(
3030
"--output_c",
31-
help=
32-
"The source file to generate containing the GDBus proxy implementation"
31+
help="The source file to generate containing the GDBus proxy implementation"
3332
)
3433

3534
parser.add_argument(
@@ -65,7 +64,8 @@ def main(argv):
6564
gdbus_args = ["gdbus-codegen", "--body", "--output", options.output_c
6665
] + extra_args + [options.input_file]
6766
subprocess.check_call(gdbus_args)
68-
sed_args = ["sed", "-i", "s/config\.h/BuildConfig.h/g", options.output_c]
67+
sed_args = ["sed", "-i",
68+
"s/config\.h/BuildConfig.h/g", options.output_c]
6969
subprocess.check_call(sed_args)
7070

7171
if options.output_h:

0 commit comments

Comments
 (0)