Skip to content

Auto-format Python code with ruff format #23154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ jobs:
- run: ruff check
# TODO (cclauss): When ruff supports rule E303 without --preview, remove following line
- run: ruff check --preview --select=E303
- run: ruff format
mypy:
executor: focal
steps:
Expand Down
3 changes: 0 additions & 3 deletions .style.yapf

This file was deleted.

22 changes: 14 additions & 8 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
on the timestamps of various input files (kind of like a dumb version
of a Makefile).
"""

import argparse
import os
import shutil
Expand All @@ -21,13 +22,16 @@

actions = [
('npm packages', ['package.json'], [shutil.which('npm'), 'ci']),
('create entry points', [
'tools/maint/create_entry_points.py',
'tools/maint/run_python.bat',
'tools/maint/run_python.sh',
'tools/maint/run_python.ps1',
],
[sys.executable, 'tools/maint/create_entry_points.py']),
(
'create entry points',
[
'tools/maint/create_entry_points.py',
'tools/maint/run_python.bat',
'tools/maint/run_python.sh',
'tools/maint/run_python.ps1',
],
[sys.executable, 'tools/maint/create_entry_points.py'],
),
('git submodules', ['test/third_party/posixtestsuite/'], [shutil.which('git'), 'submodule', 'update', '--init']),
]

Expand Down Expand Up @@ -57,7 +61,9 @@ def main(args):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-v', '--verbose', action='store_true', help='verbose', default=False)
parser.add_argument('-n', '--dry-run', action='store_true', help='dry run', default=False)
parser.add_argument('-i', '--install-post-checkout', action='store_true', help='install post checkout script', default=False)
parser.add_argument(
'-i', '--install-post-checkout', action='store_true', help='install post checkout script', default=False
)
args = parser.parse_args()

if args.install_post_checkout:
Expand Down
5 changes: 3 additions & 2 deletions docs/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ pre-processor. See [`.clang-format`][clang-format] for more details.
### Python Code

We generally follow the pep8 standard with the major exception that we use 2
spaces for indentation. `ruff` is run on all PRs to ensure that Python code
conforms to this style. See [`pyproject.toml`][pyproject.toml] for more details.
spaces for indentation. `ruff check` and `ruff format` are run on all PRs to
ensure that Python code conforms to this style. See
[`pyproject.toml`][pyproject.toml] for more details.

#### Static Type Checking

Expand Down
4 changes: 1 addition & 3 deletions em-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@


def main():
if len(sys.argv) != 2 or \
not re.match(r"^[\w\W_][\w\W_\d]*$", sys.argv[1]) or \
not hasattr(config, sys.argv[1]):
if len(sys.argv) != 2 or not re.match(r"^[\w\W_][\w\W_\d]*$", sys.argv[1]) or not hasattr(config, sys.argv[1]):
print('Usage: em-config VAR_NAME', file=sys.stderr)
sys.exit(1)

Expand Down
3 changes: 1 addition & 2 deletions emar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

"""Wrapper script around `llvm-ar`.
"""
"""Wrapper script around `llvm-ar`."""

import sys
from tools import shared
Expand Down
210 changes: 111 additions & 99 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,95 +30,95 @@

# Minimal subset of targets used by CI systems to build enough to be useful
MINIMAL_TASKS = [
'libcompiler_rt',
'libcompiler_rt-wasm-sjlj',
'libcompiler_rt-ww',
'libc',
'libc-debug',
'libc-ww-debug',
'libc_optz',
'libc_optz-debug',
'libc++abi',
'libc++abi-except',
'libc++abi-noexcept',
'libc++abi-debug',
'libc++abi-debug-except',
'libc++abi-debug-noexcept',
'libc++abi-debug-ww-noexcept',
'libc++',
'libc++-except',
'libc++-noexcept',
'libc++-ww-noexcept',
'libal',
'libdlmalloc',
'libdlmalloc-tracing',
'libdlmalloc-debug',
'libdlmalloc-ww',
'libembind',
'libembind-rtti',
'libemmalloc',
'libemmalloc-debug',
'libemmalloc-memvalidate',
'libemmalloc-verbose',
'libemmalloc-memvalidate-verbose',
'libmimalloc',
'libmimalloc-mt',
'libGL',
'libGL-getprocaddr',
'libGL-emu-getprocaddr',
'libGL-emu-webgl2-ofb-getprocaddr',
'libGL-webgl2-ofb-getprocaddr',
'libGL-ww-getprocaddr',
'libhtml5',
'libsockets',
'libsockets-ww',
'libstubs',
'libstubs-debug',
'libstandalonewasm-nocatch',
'crt1',
'crt1_proxy_main',
'crtbegin',
'libunwind-except',
'libnoexit',
'sqlite3',
'sqlite3-mt',
'libwebgpu',
'libwebgpu_cpp',
'libcompiler_rt',
'libcompiler_rt-wasm-sjlj',
'libcompiler_rt-ww',
'libc',
'libc-debug',
'libc-ww-debug',
'libc_optz',
'libc_optz-debug',
'libc++abi',
'libc++abi-except',
'libc++abi-noexcept',
'libc++abi-debug',
'libc++abi-debug-except',
'libc++abi-debug-noexcept',
'libc++abi-debug-ww-noexcept',
'libc++',
'libc++-except',
'libc++-noexcept',
'libc++-ww-noexcept',
'libal',
'libdlmalloc',
'libdlmalloc-tracing',
'libdlmalloc-debug',
'libdlmalloc-ww',
'libembind',
'libembind-rtti',
'libemmalloc',
'libemmalloc-debug',
'libemmalloc-memvalidate',
'libemmalloc-verbose',
'libemmalloc-memvalidate-verbose',
'libmimalloc',
'libmimalloc-mt',
'libGL',
'libGL-getprocaddr',
'libGL-emu-getprocaddr',
'libGL-emu-webgl2-ofb-getprocaddr',
'libGL-webgl2-ofb-getprocaddr',
'libGL-ww-getprocaddr',
'libhtml5',
'libsockets',
'libsockets-ww',
'libstubs',
'libstubs-debug',
'libstandalonewasm-nocatch',
'crt1',
'crt1_proxy_main',
'crtbegin',
'libunwind-except',
'libnoexit',
'sqlite3',
'sqlite3-mt',
'libwebgpu',
'libwebgpu_cpp',
]

# Additional tasks on top of MINIMAL_TASKS that are necessary for PIC testing on
# CI (which has slightly more tests than other modes that want to use MINIMAL)
MINIMAL_PIC_TASKS = MINIMAL_TASKS + [
'libcompiler_rt-mt',
'libc-mt',
'libc-mt-debug',
'libc_optz-mt',
'libc_optz-mt-debug',
'libc++abi-mt',
'libc++abi-mt-noexcept',
'libc++abi-debug-mt',
'libc++abi-debug-mt-noexcept',
'libc++-mt',
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libGL-emu',
'libGL-emu-webgl2-getprocaddr',
'libGL-mt-getprocaddr',
'libGL-mt-emu',
'libGL-mt-emu-webgl2-getprocaddr',
'libGL-mt-emu-webgl2-ofb-getprocaddr',
'libsockets_proxy',
'libsockets-mt',
'crtbegin',
'libsanitizer_common_rt',
'libubsan_rt',
'libwasm_workers-debug-stub',
'libfetch',
'libfetch-mt',
'libwasmfs',
'libwasmfs-debug',
'libwasmfs_no_fs',
'giflib',
'libcompiler_rt-mt',
'libc-mt',
'libc-mt-debug',
'libc_optz-mt',
'libc_optz-mt-debug',
'libc++abi-mt',
'libc++abi-mt-noexcept',
'libc++abi-debug-mt',
'libc++abi-debug-mt-noexcept',
'libc++-mt',
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libGL-emu',
'libGL-emu-webgl2-getprocaddr',
'libGL-mt-getprocaddr',
'libGL-mt-emu',
'libGL-mt-emu-webgl2-getprocaddr',
'libGL-mt-emu-webgl2-ofb-getprocaddr',
'libsockets_proxy',
'libsockets-mt',
'crtbegin',
'libsanitizer_common_rt',
'libubsan_rt',
'libwasm_workers-debug-stub',
'libfetch',
'libfetch-mt',
'libwasmfs',
'libwasmfs-debug',
'libwasmfs_no_fs',
'giflib',
]

PORTS = sorted(list(ports.ports_by_name.keys()) + list(ports.port_variants.keys()))
Expand Down Expand Up @@ -186,19 +186,17 @@ def handle_port_error(target, message):
def main():
all_build_start_time = time.time()

parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=get_help())
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, epilog=get_help()
)
parser.add_argument('--lto', action='store_const', const='full', help='build bitcode object for LTO')
parser.add_argument('--lto=thin', dest='lto', action='store_const', const='thin', help='build bitcode object for ThinLTO')
parser.add_argument('--pic', action='store_true',
help='build relocatable objects for suitable for dynamic linking')
parser.add_argument('--force', action='store_true',
help='force rebuild of target (by removing it first)')
parser.add_argument('--verbose', action='store_true',
help='show build commands')
parser.add_argument('--wasm64', action='store_true',
help='use wasm64 architecture')
parser.add_argument(
'--lto=thin', dest='lto', action='store_const', const='thin', help='build bitcode object for ThinLTO'
)
parser.add_argument('--pic', action='store_true', help='build relocatable objects for suitable for dynamic linking')
parser.add_argument('--force', action='store_true', help='force rebuild of target (by removing it first)')
parser.add_argument('--verbose', action='store_true', help='show build commands')
parser.add_argument('--wasm64', action='store_true', help='use wasm64 architecture')
parser.add_argument('operation', choices=['build', 'clear', 'rebuild'])
parser.add_argument('targets', nargs='*', help='see below')
args = parser.parse_args()
Expand Down Expand Up @@ -239,7 +237,7 @@ def main():

# process tasks
auto_tasks = False
task_targets = dict.fromkeys(args.targets) # use dict to keep targets order
task_targets = dict.fromkeys(args.targets) # use dict to keep targets order

# substitute
predefined_tasks = {
Expand Down Expand Up @@ -314,14 +312,28 @@ def main():
return 1

time_taken = time.time() - start_time
logger.info('...success. Took %s(%.2fs)' % (('%02d:%02d mins ' % (time_taken // 60, time_taken % 60) if time_taken >= 60 else ''), time_taken))
logger.info(
'...success. Took %s(%.2fs)'
% (('%02d:%02d mins ' % (time_taken // 60, time_taken % 60) if time_taken >= 60 else ''), time_taken)
)

if USE_NINJA and args.operation != 'clear':
system_libs.build_deferred()

if len(tasks) > 1 or USE_NINJA:
all_build_time_taken = time.time() - all_build_start_time
logger.info('Built %d targets in %s(%.2fs)' % (len(tasks), ('%02d:%02d mins ' % (all_build_time_taken // 60, all_build_time_taken % 60) if all_build_time_taken >= 60 else ''), all_build_time_taken))
logger.info(
'Built %d targets in %s(%.2fs)'
% (
len(tasks),
(
'%02d:%02d mins ' % (all_build_time_taken // 60, all_build_time_taken % 60)
if all_build_time_taken >= 60
else ''
),
all_build_time_taken,
)
)

return 0

Expand Down
Loading
Loading