Skip to content

Commit b71edfa

Browse files
committed
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat all the python files in the LLVM repository. Reformatting is done with `black`. See more information here: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Reviewed By: jhenderson, JDevlieghere, MatzeB Differential Revision: https://reviews.llvm.org/D150545
1 parent 7beb2ca commit b71edfa

File tree

262 files changed

+17956
-14089
lines changed

Some content is hidden

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

262 files changed

+17956
-14089
lines changed

llvm/bindings/python/llvm/bit_reader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from .common import LLVMObject
32
from .common import c_object_p
43
from .common import get_library
@@ -10,21 +9,25 @@
109
from ctypes import byref
1110
from ctypes import c_char_p
1211
from ctypes import cast
13-
__all__ = ['parse_bitcode']
12+
13+
__all__ = ["parse_bitcode"]
1414
lib = get_library()
1515

16+
1617
def parse_bitcode(mem_buffer):
1718
"""Input is .core.MemoryBuffer"""
1819
module = c_object_p()
1920
result = lib.LLVMParseBitcode2(mem_buffer, byref(module))
2021
if result:
21-
raise RuntimeError('LLVM Error')
22+
raise RuntimeError("LLVM Error")
2223
m = Module(module)
2324
m.take_ownership(mem_buffer)
2425
return m
2526

27+
2628
def register_library(library):
2729
library.LLVMParseBitcode2.argtypes = [MemoryBuffer, POINTER(c_object_p)]
2830
library.LLVMParseBitcode2.restype = bool
2931

32+
3033
register_library(lib)

llvm/bindings/python/llvm/common.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#===- common.py - Python LLVM Bindings -----------------------*- python -*--===#
1+
# ===- common.py - Python LLVM Bindings -----------------------*- python -*--===#
22
#
33
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
7-
#===------------------------------------------------------------------------===#
7+
# ===------------------------------------------------------------------------===#
88

99
from ctypes import POINTER
1010
from ctypes import c_void_p
@@ -15,20 +15,22 @@
1515

1616
# LLVM_VERSION: sync with PACKAGE_VERSION in CMakeLists.txt
1717
# but leave out the 'svn' suffix.
18-
LLVM_VERSION = '10.0.0'
18+
LLVM_VERSION = "10.0.0"
1919

2020
__all__ = [
21-
'c_object_p',
22-
'get_library',
21+
"c_object_p",
22+
"get_library",
2323
]
2424

2525
c_object_p = POINTER(c_void_p)
2626

27+
2728
class LLVMObject(object):
2829
"""Base class for objects that are backed by an LLVM data structure.
2930
3031
This class should never be instantiated outside of this package.
3132
"""
33+
3234
def __init__(self, ptr, ownable=True, disposer=None):
3335
assert isinstance(ptr, c_object_p)
3436

@@ -61,24 +63,26 @@ def from_param(self):
6163
return self._as_parameter_
6264

6365
def __del__(self):
64-
if not hasattr(self, '_self_owned') or not hasattr(self, '_disposer'):
66+
if not hasattr(self, "_self_owned") or not hasattr(self, "_disposer"):
6567
return
6668

6769
if self._self_owned and self._disposer:
6870
self._disposer(self)
6971

72+
7073
class CachedProperty(object):
7174
"""Decorator that caches the result of a property lookup.
7275
7376
This is a useful replacement for @property. It is recommended to use this
7477
decorator on properties that invoke C API calls for which the result of the
7578
call will be idempotent.
7679
"""
80+
7781
def __init__(self, wrapped):
7882
self.wrapped = wrapped
7983
try:
8084
self.__doc__ = wrapped.__doc__
81-
except: # pragma: no cover
85+
except: # pragma: no cover
8286
pass
8387

8488
def __get__(self, instance, instance_type=None):
@@ -90,6 +94,7 @@ def __get__(self, instance, instance_type=None):
9094

9195
return value
9296

97+
9398
def get_library():
9499
"""Obtain a reference to the llvm library."""
95100

@@ -101,14 +106,14 @@ def get_library():
101106
# library into a default linker search path. Always Try ctypes.cdll.LoadLibrary()
102107
# with all possible library names first, then try ctypes.util.find_library().
103108

104-
names = ['LLVM-' + LLVM_VERSION, 'LLVM-' + LLVM_VERSION + 'svn']
109+
names = ["LLVM-" + LLVM_VERSION, "LLVM-" + LLVM_VERSION + "svn"]
105110
t = platform.system()
106-
if t == 'Darwin':
107-
pfx, ext = 'lib', '.dylib'
108-
elif t == 'Windows':
109-
pfx, ext = '', '.dll'
111+
if t == "Darwin":
112+
pfx, ext = "lib", ".dylib"
113+
elif t == "Windows":
114+
pfx, ext = "", ".dll"
110115
else:
111-
pfx, ext = 'lib', '.so'
116+
pfx, ext = "lib", ".so"
112117

113118
for i in names:
114119
try:
@@ -122,4 +127,4 @@ def get_library():
122127
t = ctypes.util.find_library(i)
123128
if t:
124129
return cdll.LoadLibrary(t)
125-
raise Exception('LLVM shared library not found!')
130+
raise Exception("LLVM shared library not found!")

0 commit comments

Comments
 (0)