Skip to content

Commit

Permalink
compatible to pyyaml>=6.0
Browse files Browse the repository at this point in the history
yaml/pyyaml#576
Signed-off-by: quan <[email protected]>
  • Loading branch information
quan committed May 3, 2022
1 parent 775b869 commit 573a98c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
9 changes: 7 additions & 2 deletions aten/src/ATen/cwrap_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# from importlib.abc import Loader
import yaml

try:
# use faster C loader if available
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
# follows similar logic to cwrap, ignores !inc, and just looks for [[]]


Expand All @@ -15,7 +20,7 @@ def parse(filename):
in_declaration = True
elif line == ']]':
in_declaration = False
declaration = yaml.load('\n'.join(declaration_lines))
declaration = yaml.load('\n'.join(declaration_lines),Loader=Loader)
declarations.append(declaration)
elif in_declaration:
declaration_lines.append(line)
Expand Down
8 changes: 7 additions & 1 deletion test/test_namedtuple_return_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
'triangular_solve'
}

try:
# use faster C loader if available
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader


class TestNamedTupleAPI(unittest.TestCase):

def test_native_functions_yaml(self):
operators_found = set()
regex = re.compile(r"^(\w*)\(")
file = open(aten_native_yaml, 'r')
for f in yaml.load(file.read()):
for f in yaml.load(file.read(),Loader=Loader):
f = f['func']
ret = f.split('->')[1].strip()
name = regex.findall(f)[0]
Expand Down
8 changes: 7 additions & 1 deletion tools/clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def run_shell_commands_in_parallel(commands):
finally:
os.unlink(f.name)

try:
# use faster C loader if available
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader


def run_clang_tidy(options, line_filters, files):
"""Executes the actual clang-tidy command in the shell."""
Expand All @@ -167,7 +173,7 @@ def run_clang_tidy(options, line_filters, files):

with open(options.config_file) as config:
# Here we convert the YAML config file to a JSON blob.
command += ["-config", json.dumps(yaml.load(config))]
command += ["-config", json.dumps(yaml.load(config,Loader=Loader))]
command += options.extra_args

if line_filters:
Expand Down
8 changes: 7 additions & 1 deletion tools/cwrap/cwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
BeforeAfterCall, ConstantArguments, ReturnArguments, GILRelease
from ..shared import cwrap_common

try:
# use faster C loader if available
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader


class cwrap(object):
BASE_INDENT_SIZE = 6
Expand Down Expand Up @@ -88,7 +94,7 @@ def wrap_declarations(self, declarations):
in_declaration = True
elif line == ']]':
in_declaration = False
declaration = yaml.load('\n'.join(declaration_lines))
declaration = yaml.load('\n'.join(declaration_lines),Loader=Loader)
cwrap_common.set_declaration_defaults(declaration)

# Pass declaration in a list - maybe some plugins want to add
Expand Down

0 comments on commit 573a98c

Please sign in to comment.