Skip to content

Commit

Permalink
[style] Add autopep8 to restyled.yaml (#8943)
Browse files Browse the repository at this point in the history
* [style] Add check for python format

* Run Restyle
  • Loading branch information
erjiaqing authored and pull[bot] committed Aug 27, 2021
1 parent e4b9744 commit 1273361
Show file tree
Hide file tree
Showing 89 changed files with 3,224 additions and 2,715 deletions.
11 changes: 11 additions & 0 deletions .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exclude:
- "third_party/bluez/repo/**/*"
- "third_party/cirque/repo/**/*"
- "third_party/nanopb/repo/**/*"
- "src/controller/python/chip/clusters/CHIPClusters.py" # generated file


changed_paths:
Expand Down Expand Up @@ -198,3 +199,13 @@ restylers:
include:
- "**/*.sh"
- "**/*.bash"
- name: autopep8
image: 'restyled/restyler-autopep8:v1.5.7'
command:
- autopep8
- '--in-place'
arguments: []
include:
- '**/*.py'
interpreters:
- python
100 changes: 50 additions & 50 deletions build/chip/java/jar_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,69 @@


def IsExecutable(path):
"""Returns whether file at |path| exists and is executable.
"""Returns whether file at |path| exists and is executable.
Args:
path: absolute or relative path to test.
Args:
path: absolute or relative path to test.
Returns:
True if the file at |path| exists, False otherwise.
"""
return os.path.isfile(path) and os.access(path, os.X_OK)
Returns:
True if the file at |path| exists, False otherwise.
"""
return os.path.isfile(path) and os.access(path, os.X_OK)


def FindCommand(command):
"""Looks up for |command| in PATH.
Args:
command: name of the command to lookup, if command is a relative or
absolute path (i.e. contains some path separator) then only that
path will be tested.
Returns:
Full path to command or None if the command was not found.
On Windows, this respects the PATHEXT environment variable when the
command name does not have an extension.
"""
fpath, _ = os.path.split(command)
if fpath:
if IsExecutable(command):
return command

if sys.platform == 'win32':
# On Windows, if the command does not have an extension, cmd.exe will
# try all extensions from PATHEXT when resolving the full path.
command, ext = os.path.splitext(command)
if not ext:
exts = os.environ['PATHEXT'].split(os.path.pathsep)
"""Looks up for |command| in PATH.
Args:
command: name of the command to lookup, if command is a relative or
absolute path (i.e. contains some path separator) then only that
path will be tested.
Returns:
Full path to command or None if the command was not found.
On Windows, this respects the PATHEXT environment variable when the
command name does not have an extension.
"""
fpath, _ = os.path.split(command)
if fpath:
if IsExecutable(command):
return command

if sys.platform == 'win32':
# On Windows, if the command does not have an extension, cmd.exe will
# try all extensions from PATHEXT when resolving the full path.
command, ext = os.path.splitext(command)
if not ext:
exts = os.environ['PATHEXT'].split(os.path.pathsep)
else:
exts = [ext]
else:
exts = [ext]
else:
exts = ['']
exts = ['']

for path in os.environ['PATH'].split(os.path.pathsep):
for ext in exts:
path = os.path.join(path, command) + ext
if IsExecutable(path):
return path
for path in os.environ['PATH'].split(os.path.pathsep):
for ext in exts:
path = os.path.join(path, command) + ext
if IsExecutable(path):
return path

return None
return None


def main():
java_path = FindCommand('jar')
if not java_path:
sys.stderr.write('jar: command not found\n')
sys.exit(EXIT_FAILURE)
java_path = FindCommand('jar')
if not java_path:
sys.stderr.write('jar: command not found\n')
sys.exit(EXIT_FAILURE)

args = sys.argv[1:]
if len(args) < 1:
sys.stderr.write('usage: %s [jar_args]...\n' % sys.argv[0])
sys.exit(EXIT_FAILURE)
args = sys.argv[1:]
if len(args) < 1:
sys.stderr.write('usage: %s [jar_args]...\n' % sys.argv[0])
sys.exit(EXIT_FAILURE)

return subprocess.check_call([java_path] + args)
return subprocess.check_call([java_path] + args)


if __name__ == '__main__':
sys.exit(main())
sys.exit(main())
152 changes: 76 additions & 76 deletions build/chip/java/javac_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,93 +28,93 @@


def IsExecutable(path):
"""Returns whether file at |path| exists and is executable.
"""Returns whether file at |path| exists and is executable.
Args:
path: absolute or relative path to test.
Args:
path: absolute or relative path to test.
Returns:
True if the file at |path| exists, False otherwise.
"""
return os.path.isfile(path) and os.access(path, os.X_OK)
Returns:
True if the file at |path| exists, False otherwise.
"""
return os.path.isfile(path) and os.access(path, os.X_OK)


def FindCommand(command):
"""Looks up for |command| in PATH.
Args:
command: name of the command to lookup, if command is a relative or absolute
path (i.e. contains some path separator) then only that path will be
tested.
Returns:
Full path to command or None if the command was not found.
On Windows, this respects the PATHEXT environment variable when the
command name does not have an extension.
"""
fpath, _ = os.path.split(command)
if fpath:
if IsExecutable(command):
return command

if sys.platform == 'win32':
# On Windows, if the command does not have an extension, cmd.exe will
# try all extensions from PATHEXT when resolving the full path.
command, ext = os.path.splitext(command)
if not ext:
exts = os.environ['PATHEXT'].split(os.path.pathsep)
"""Looks up for |command| in PATH.
Args:
command: name of the command to lookup, if command is a relative or absolute
path (i.e. contains some path separator) then only that path will be
tested.
Returns:
Full path to command or None if the command was not found.
On Windows, this respects the PATHEXT environment variable when the
command name does not have an extension.
"""
fpath, _ = os.path.split(command)
if fpath:
if IsExecutable(command):
return command

if sys.platform == 'win32':
# On Windows, if the command does not have an extension, cmd.exe will
# try all extensions from PATHEXT when resolving the full path.
command, ext = os.path.splitext(command)
if not ext:
exts = os.environ['PATHEXT'].split(os.path.pathsep)
else:
exts = [ext]
else:
exts = [ext]
else:
exts = ['']
exts = ['']

for path in os.environ['PATH'].split(os.path.pathsep):
for ext in exts:
path = os.path.join(path, command) + ext
if IsExecutable(path):
return path
for path in os.environ['PATH'].split(os.path.pathsep):
for ext in exts:
path = os.path.join(path, command) + ext
if IsExecutable(path):
return path

return None
return None


def main():
java_path = FindCommand('javac')
if not java_path:
sys.stderr.write('javac: command not found\n')
sys.exit(EXIT_FAILURE)

parser = argparse.ArgumentParser('Javac runner')
parser.add_argument(
'--classdir',
dest='classdir',
required=True,
help='Directory that will contain class files')
parser.add_argument(
'--outfile',
dest='outfile',
required=True,
help='Output file containing a list of classes')
parser.add_argument(
'rest', metavar='JAVAC_ARGS', nargs='*', help='Argumets to pass to javac')

args = parser.parse_args()
if not os.path.isdir(args.classdir):
os.makedirs(args.classdir)
retcode = subprocess.check_call([java_path] + args.rest)
if retcode != EXIT_SUCCESS:
return retcode

with open(args.outfile, 'wt') as f:
prefixlen = len(args.classdir) + 1
for root, dirnames, filenames in os.walk(args.classdir):
for filename in filenames:
if filename.endswith('.class'):
f.write(os.path.join(root[prefixlen:], filename))
f.write('\n')

return EXIT_SUCCESS
java_path = FindCommand('javac')
if not java_path:
sys.stderr.write('javac: command not found\n')
sys.exit(EXIT_FAILURE)

parser = argparse.ArgumentParser('Javac runner')
parser.add_argument(
'--classdir',
dest='classdir',
required=True,
help='Directory that will contain class files')
parser.add_argument(
'--outfile',
dest='outfile',
required=True,
help='Output file containing a list of classes')
parser.add_argument(
'rest', metavar='JAVAC_ARGS', nargs='*', help='Argumets to pass to javac')

args = parser.parse_args()
if not os.path.isdir(args.classdir):
os.makedirs(args.classdir)
retcode = subprocess.check_call([java_path] + args.rest)
if retcode != EXIT_SUCCESS:
return retcode

with open(args.outfile, 'wt') as f:
prefixlen = len(args.classdir) + 1
for root, dirnames, filenames in os.walk(args.classdir):
for filename in filenames:
if filename.endswith('.class'):
f.write(os.path.join(root[prefixlen:], filename))
f.write('\n')

return EXIT_SUCCESS


if __name__ == '__main__':
sys.exit(main())
sys.exit(main())
6 changes: 3 additions & 3 deletions build/chip/linux/gen_gdbus_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def main(argv):

parser.add_argument(
"--output_c",
help=
"The source file to generate containing the GDBus proxy implementation"
help="The source file to generate containing the GDBus proxy implementation"
)

parser.add_argument(
Expand Down Expand Up @@ -65,7 +64,8 @@ def main(argv):
gdbus_args = ["gdbus-codegen", "--body", "--output", options.output_c
] + extra_args + [options.input_file]
subprocess.check_call(gdbus_args)
sed_args = ["sed", "-i", "s/config\.h/BuildConfig.h/g", options.output_c]
sed_args = ["sed", "-i",
"s/config\.h/BuildConfig.h/g", options.output_c]
subprocess.check_call(sed_args)

if options.output_h:
Expand Down
Loading

0 comments on commit 1273361

Please sign in to comment.