Skip to content

Commit ed62fa1

Browse files
authored
Format python files with YAPF (#1947)
Enabling yapf formatting of python files
1 parent cd23baa commit ed62fa1

File tree

24 files changed

+442
-469
lines changed

24 files changed

+442
-469
lines changed

geosx_mesh_tools_package/geosx_mesh_tools/abaqus_converter.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import meshio
32
from meshio._mesh import CellBlock
43
import numpy as np
@@ -19,8 +18,8 @@ def convert_abaqus_to_gmsh(input_mesh, output_mesh, logger=None):
1918
"""
2019
# Initialize the logger if it is empty
2120
if not logger:
22-
logging.basicConfig(level=logging.WARNING)
23-
logger = logging.getLogger(__name__)
21+
logging.basicConfig(level=logging.WARNING)
22+
logger = logging.getLogger(__name__)
2423

2524
# Keep track of the number of warnings
2625
n_warnings = 0
@@ -142,10 +141,9 @@ def main():
142141
logging.basicConfig(level=logging.WARNING)
143142
logger = logging.getLogger(__name__)
144143
if args.verbose:
145-
logger.setLevel(logging.INFO)
144+
logger.setLevel(logging.INFO)
146145

147146
# Call the converter
148147
err = convert_abaqus_to_gmsh(args.input, args.output, logger)
149148
if err:
150149
sys.exit('Warnings detected: check the output file for potential errors!')
151-

geosx_mesh_tools_package/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
packages=['geosx_mesh_tools'],
99
entry_points={'console_scripts': ['convert_abaqus = geosx_mesh_tools.abaqus_converter:main']},
1010
install_requires=['meshio'])
11-

geosx_xml_tools_package/geosx_xml_tools/attribute_coverage.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from lxml import etree as ElementTree
32
import os
43
from pathlib import Path
@@ -65,9 +64,7 @@ def collect_xml_attributes_level(local_types, node, folder):
6564

6665
for child in node:
6766
if child.tag in local_types['children']:
68-
collect_xml_attributes_level(local_types['children'][child.tag],
69-
child,
70-
folder)
67+
collect_xml_attributes_level(local_types['children'][child.tag], child, folder)
7168

7269

7370
def collect_xml_attributes(xml_types, fname, folder):

geosx_xml_tools_package/geosx_xml_tools/main.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ def parse_arguments():
1111
# Parse the user arguments
1212
parser = argparse.ArgumentParser()
1313
parser.add_argument('-i', '--input', type=str, action='append', help='Input file name (multiple allowed)')
14-
parser.add_argument('-c', '--compiled-name', type=str, help='Compiled xml file name (otherwise, it is randomly genrated)', default='')
14+
parser.add_argument('-c',
15+
'--compiled-name',
16+
type=str,
17+
help='Compiled xml file name (otherwise, it is randomly genrated)',
18+
default='')
1519
parser.add_argument('-s', '--schema', type=str, help='GEOSX schema to use for validation', default='')
1620
parser.add_argument('-v', '--verbose', type=int, help='Verbosity of outputs', default=0)
17-
parser.add_argument('-p', '--parameters', nargs='+', action='append', help='Parameter overrides (name value, multiple allowed)', default=[])
21+
parser.add_argument('-p',
22+
'--parameters',
23+
nargs='+',
24+
action='append',
25+
help='Parameter overrides (name value, multiple allowed)',
26+
default=[])
1827
return parser.parse_known_args()
1928

2029

@@ -28,7 +37,9 @@ def check_mpi_rank():
2837

2938

3039
def wait_for_file_write_rank_0(target_file_argument=0, max_wait_time=100, max_startup_delay=1):
40+
3141
def wait_for_file_write_rank_0_inner(writer):
42+
3243
def wait_for_file_write_rank_0_decorator(*args, **kwargs):
3344
# Check the target file status
3445
rank = check_mpi_rank()
@@ -46,22 +57,24 @@ def wait_for_file_write_rank_0_decorator(*args, **kwargs):
4657
# Variations in thread startup times may mean the file has already been processed
4758
# If the last edit was done within the specified time, then allow the thread to proceed
4859
if (abs(target_file_edit_time - time.time()) < max_startup_delay):
49-
target_file_edit_time = 0
60+
target_file_edit_time = 0
5061

5162
# Go into the target process or wait for the expected file update
5263
if (rank == 0):
5364
return writer(*args, **kwargs)
5465
else:
5566
ta = time.time()
56-
while(time.time() - ta < max_wait_time):
67+
while (time.time() - ta < max_wait_time):
5768
if target_file_exists:
5869
if (os.path.getmtime(fname) > target_file_edit_time):
5970
break
6071
else:
6172
if os.path.isfile(fname):
6273
break
6374
time.sleep(0.1)
75+
6476
return wait_for_file_write_rank_0_decorator
77+
6578
return wait_for_file_write_rank_0_inner
6679

6780

@@ -89,7 +102,9 @@ def preprocess_serial():
89102
if args.compiled_name:
90103
compiled_name = args.compiled_name
91104
else:
92-
raise Exception('When applying the preprocessor in parallel (outside of pygeosx), the --compiled_name argument is required')
105+
raise Exception(
106+
'When applying the preprocessor in parallel (outside of pygeosx), the --compiled_name argument is required'
107+
)
93108

94109
# Note: the return value may be passed to sys.exit, and cause bash to report an error
95110
# return format_geosx_arguments(compiled_name, unknown_args)

geosx_xml_tools_package/geosx_xml_tools/regex_tools.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import re
44

5-
65
# Define regex patterns used throughout the module:
76
#
87
# Pattern | Example targets | Notes
@@ -16,13 +15,15 @@
1615
# strip_trailing | 3.0000, 5.150050 | Removes unnecessary float strings
1716
# strip_trailing_b| 3.0000e0, 1.23e0 | Removes unnecessary float strings
1817
#
19-
patterns = {'parameters': r"\$:?([a-zA-Z_0-9]*)\$?",
20-
'units': r"([0-9]*?\.?[0-9]+(?:[eE][-+]?[0-9]*?)?)\ *?\[([-+.*/()a-zA-Z0-9]*)\]",
21-
'units_b': r"([a-zA-Z]*)",
22-
'symbolic': r"\`([-+.*/() 0-9eE]*)\`",
23-
'sanitize': r"[a-z-[e]A-Z-[E]]",
24-
'strip_trailing': r"\.?0+(?=e)",
25-
'strip_trailing_b': r"e\+00|\+0?|(?<=-)0"}
18+
patterns = {
19+
'parameters': r"\$:?([a-zA-Z_0-9]*)\$?",
20+
'units': r"([0-9]*?\.?[0-9]+(?:[eE][-+]?[0-9]*?)?)\ *?\[([-+.*/()a-zA-Z0-9]*)\]",
21+
'units_b': r"([a-zA-Z]*)",
22+
'symbolic': r"\`([-+.*/() 0-9eE]*)\`",
23+
'sanitize': r"[a-z-[e]A-Z-[E]]",
24+
'strip_trailing': r"\.?0+(?=e)",
25+
'strip_trailing_b': r"e\+00|\+0?|(?<=-)0"
26+
}
2627

2728
# String formatting for symbolic expressions
2829
symbolic_format = '%1.6e'
@@ -31,7 +32,7 @@
3132
def SymbolicMathRegexHandler(match):
3233
"""Evaluate symbolic expressions that are identified using the regex_tools.patterns['symbolic'].
3334
34-
@param match A matching string identified by the regex.
35+
@param match A matching string identified by the regex.
3536
"""
3637
k = match.group(1)
3738
if k:
@@ -52,15 +53,15 @@ class DictRegexHandler():
5253

5354
def __init__(self):
5455
"""Initialize the handler with an empty target list.
55-
The key/value pairs of self.target indicate which values
56-
to look for and the values they will replace with.
56+
The key/value pairs of self.target indicate which values
57+
to look for and the values they will replace with.
5758
"""
5859
self.target = {}
5960

6061
def __call__(self, match):
6162
"""Replace the matching strings with their target.
6263
63-
@param match A matching string identified by the regex.
64+
@param match A matching string identified by the regex.
6465
"""
6566

6667
k = match.group(1)

geosx_xml_tools_package/geosx_xml_tools/table_generator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
def write_GEOS_table(axes_values, properties, axes_names=['x', 'y', 'z', 't'], string_format='%1.5e'):
77
"""Write an GEOS-compatible ascii table.
88
9-
@param axes_values List of arrays containing the coordinates for each axis of the table.
10-
@param properties Dict of arrays with dimensionality/size defined by the axes_values
11-
@param axes_names Names for each axis (default = ['x', 'y', 'z', 't'])
12-
@param string_format Format for output values (default = %1.5e)
9+
@param axes_values List of arrays containing the coordinates for each axis of the table.
10+
@param properties Dict of arrays with dimensionality/size defined by the axes_values
11+
@param axes_names Names for each axis (default = ['x', 'y', 'z', 't'])
12+
@param string_format Format for output values (default = %1.5e)
1313
"""
1414

1515
# Check to make sure the axes/property files have the correct shape
@@ -31,9 +31,9 @@ def write_GEOS_table(axes_values, properties, axes_names=['x', 'y', 'z', 't'], s
3131
def read_GEOS_table(axes_files, property_files):
3232
"""Read an GEOS-compatible ascii table.
3333
34-
@param axes_files List of the axes file names in order.
35-
@param property_files List of property file names
36-
@return List of axis definitions, dict of property values
34+
@param axes_files List of the axes file names in order.
35+
@param property_files List of property file names
36+
@return List of axis definitions, dict of property values
3737
"""
3838
axes_values = []
3939
for f in axes_files:
@@ -59,7 +59,7 @@ def write_read_GEOS_table_example():
5959

6060
# Generate table values (note: the indexing argument is important)
6161
A, B = np.meshgrid(a, b, indexing='ij')
62-
properties = {'c': A + 2.0*B}
62+
properties = {'c': A + 2.0 * B}
6363

6464
# Write, then read tables
6565
write_GEOS_table(axes_values, properties, axes_names=['a', 'b'])

geosx_xml_tools_package/geosx_xml_tools/tests/generate_test_xml.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def generate_test_xml_files(root_dir):
99
"""Build example input/output xml files, which can be used to test the parser.
1010
These are derived from a GEOSX integrated test xml.
1111
12-
@param root_dir The folder to write the example xml files.
12+
@param root_dir The folder to write the example xml files.
1313
"""
1414

1515
# Build segments of an xml file that can be compiled to form a test
@@ -340,35 +340,35 @@ def generate_test_xml_files(root_dir):
340340
# Write the files, and apply pretty_print to targets for easy matches
341341
# No advanced features case
342342
with open('%s/no_advanced_features_input.xml' % (root_dir), 'w') as f:
343-
f.write(xml_header+xml_base_a+xml_base_b+field_string_base+xml_footer)
343+
f.write(xml_header + xml_base_a + xml_base_b + field_string_base + xml_footer)
344344
with open('%s/no_advanced_features_target.xml' % (root_dir), 'w') as f:
345-
f.write(xml_header+xml_base_a+xml_base_b+field_string_base+xml_footer)
345+
f.write(xml_header + xml_base_a + xml_base_b + field_string_base + xml_footer)
346346
xml_formatter.format_file('%s/no_advanced_features_target.xml' % (root_dir))
347347

348348
# Parameters case
349349
with open('%s/parameters_input.xml' % (root_dir), 'w') as f:
350-
f.write(xml_header+xml_parameters+xml_base_a+xml_base_b+field_string_with_parameters+xml_footer)
350+
f.write(xml_header + xml_parameters + xml_base_a + xml_base_b + field_string_with_parameters + xml_footer)
351351
with open('%s/parameters_target.xml' % (root_dir), 'w') as f:
352-
f.write(xml_header+xml_base_a+xml_base_b+field_string_base+xml_footer)
352+
f.write(xml_header + xml_base_a + xml_base_b + field_string_base + xml_footer)
353353
xml_formatter.format_file('%s/parameters_target.xml' % (root_dir))
354354

355355
# Symbolic + parameters case
356356
with open('%s/symbolic_parameters_input.xml' % (root_dir), 'w') as f:
357-
f.write(xml_header+xml_parameters+xml_base_a+xml_base_b+field_string_with_symbolic+xml_footer)
357+
f.write(xml_header + xml_parameters + xml_base_a + xml_base_b + field_string_with_symbolic + xml_footer)
358358
with open('%s/symbolic_parameters_target.xml' % (root_dir), 'w') as f:
359-
f.write(xml_header+xml_base_a+xml_base_b+field_string_alt+xml_footer)
359+
f.write(xml_header + xml_base_a + xml_base_b + field_string_alt + xml_footer)
360360
xml_formatter.format_file('%s/symbolic_parameters_target.xml' % (root_dir))
361361

362362
# Included case
363363
os.makedirs('%s/included' % (root_dir), exist_ok=True)
364364
with open('%s/included_input.xml' % (root_dir), 'w') as f:
365-
f.write(xml_header+xml_includes+xml_footer)
365+
f.write(xml_header + xml_includes + xml_footer)
366366
with open('%s/included/included_a.xml' % (root_dir), 'w') as f:
367-
f.write(xml_header+xml_base_a+xml_footer)
367+
f.write(xml_header + xml_base_a + xml_footer)
368368
with open('%s/included/included_b.xml' % (root_dir), 'w') as f:
369-
f.write(xml_header+xml_base_b+xml_footer)
369+
f.write(xml_header + xml_base_b + xml_footer)
370370
with open('%s/included/included_c.xml' % (root_dir), 'w') as f:
371-
f.write(xml_header+field_string_base+xml_footer)
371+
f.write(xml_header + field_string_base + xml_footer)
372372
with open('%s/included_target.xml' % (root_dir), 'w') as f:
373-
f.write(xml_header+xml_base_a+xml_base_b+field_string_base+xml_footer)
373+
f.write(xml_header + xml_base_a + xml_base_b + field_string_base + xml_footer)
374374
xml_formatter.format_file('%s/included_target.xml' % (root_dir))

geosx_xml_tools_package/geosx_xml_tools/tests/test_manager.py

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import argparse
88
from parameterized import parameterized
99

10-
1110
# Create an instance of the unit manager
1211
unitManager = unit_manager.UnitManager()
1312

1413

1514
# Test the unit manager definitions
1615
class TestUnitManager(unittest.TestCase):
16+
1717
@classmethod
1818
def setUpClass(cls):
1919
cls.tol = 1e-6
@@ -23,30 +23,14 @@ def test_unit_dict(self):
2323
self.assertTrue(bool(unitManager.units))
2424

2525
# Scale value tests
26-
@parameterized.expand([['meter', '2', 2.0],
27-
['meter', '1.234', 1.234],
28-
['meter', '1.234e1', 12.34],
29-
['meter', '1.234E1', 12.34],
30-
['meter', '1.234e+1', 12.34],
31-
['meter', '1.234e-1', 0.1234],
32-
['mumeter', '1', 1.0e-6],
33-
['micrometer', '1', 1.0e-6],
34-
['kilometer', '1', 1.0e3],
35-
['ms', '1', 1.0e-3],
36-
['millisecond', '1', 1.0e-3],
37-
['Ms', '1', 1.0e6],
38-
['m/s', '1', 1.0],
39-
['micrometer/s', '1', 1.0e-6],
40-
['micrometer/ms', '1', 1.0e-3],
41-
['micrometer/microsecond', '1', 1.0],
42-
['m**2', '1', 1.0],
43-
['km**2', '1', 1.0e6],
44-
['kilometer**2', '1', 1.0e6],
45-
['(km*mm)', '1', 1.0],
46-
['(km*mm)**2', '1', 1.0],
47-
['km^2', '1', 1.0e6, True],
48-
['bbl/day', '1', 0.000001840130728333],
49-
['cP', '1', 0.001]])
26+
@parameterized.expand([['meter', '2', 2.0], ['meter', '1.234', 1.234], ['meter', '1.234e1', 12.34],
27+
['meter', '1.234E1', 12.34], ['meter', '1.234e+1', 12.34], ['meter', '1.234e-1', 0.1234],
28+
['mumeter', '1', 1.0e-6], ['micrometer', '1', 1.0e-6], ['kilometer', '1', 1.0e3],
29+
['ms', '1', 1.0e-3], ['millisecond', '1', 1.0e-3], ['Ms', '1', 1.0e6], ['m/s', '1', 1.0],
30+
['micrometer/s', '1', 1.0e-6], ['micrometer/ms', '1', 1.0e-3],
31+
['micrometer/microsecond', '1', 1.0], ['m**2', '1', 1.0], ['km**2', '1', 1.0e6],
32+
['kilometer**2', '1', 1.0e6], ['(km*mm)', '1', 1.0], ['(km*mm)**2', '1', 1.0],
33+
['km^2', '1', 1.0e6, True], ['bbl/day', '1', 0.000001840130728333], ['cP', '1', 0.001]])
5034
def test_units(self, unit, scale, expected_value, expect_fail=False):
5135
try:
5236
val = float(unitManager([scale, unit]))
@@ -64,11 +48,9 @@ def setUpClass(cls):
6448
cls.regexHandler.target['foo'] = '1.23'
6549
cls.regexHandler.target['bar'] = '4.56e7'
6650

67-
@parameterized.expand([['$:foo*1.234', '1.23*1.234'],
68-
['$:foo*1.234/$:bar', '1.23*1.234/4.56e7'],
51+
@parameterized.expand([['$:foo*1.234', '1.23*1.234'], ['$:foo*1.234/$:bar', '1.23*1.234/4.56e7'],
6952
['$:foo*1.234/($:bar*$:foo)', '1.23*1.234/(4.56e7*1.23)'],
70-
['$foo*1.234/$bar', '1.23*1.234/4.56e7'],
71-
['$foo$*1.234/$bar', '1.23*1.234/4.56e7'],
53+
['$foo*1.234/$bar', '1.23*1.234/4.56e7'], ['$foo$*1.234/$bar', '1.23*1.234/4.56e7'],
7254
['$foo$*1.234/$bar$', '1.23*1.234/4.56e7'],
7355
['$blah$*1.234/$bar$', '1.23*1.234/4.56e7', True],
7456
['$foo$*1.234/$bar$', '4.56e7*1.234/4.56e7', True]])
@@ -87,9 +69,7 @@ class TestUnitsRegex(unittest.TestCase):
8769
def setUpClass(cls):
8870
cls.tol = 1e-6
8971

90-
@parameterized.expand([['1.234[m**2/s]', '1.234'],
91-
['1.234 [m**2/s]', '1.234'],
92-
['1.234[m**2/s]*3.4', '1.234*3.4'],
72+
@parameterized.expand([['1.234[m**2/s]', '1.234'], ['1.234 [m**2/s]', '1.234'], ['1.234[m**2/s]*3.4', '1.234*3.4'],
9373
['1.234[m**2/s] + 5.678[mm/s]', '1.234 + 5.678e-3'],
9474
['1.234 [m**2/s] + 5.678 [mm/s]', '1.234 + 5.678e-3'],
9575
['(1.234[m**2/s])*5.678', '(1.234)*5.678']])
@@ -108,19 +88,10 @@ class TestSymbolicRegex(unittest.TestCase):
10888
def setUpClass(cls):
10989
cls.tol = 1e-6
11090

111-
@parameterized.expand([['`1.234`', '1.234'],
112-
['`1.234*2.0`', '2.468'],
113-
['`10`', '1e1'],
114-
['`10*2`', '2e1'],
115-
['`1.0/2.0`', '5e-1'],
116-
['`2.0**2`', '4'],
117-
['`1.0 + 2.0**2`', '5'],
118-
['`(1.0 + 2.0)**2`', '9'],
119-
['`((1.0 + 2.0)**2)**(0.5)`', '3'],
120-
['`(1.2e3)*2`', '2.4e3'],
121-
['`1.2e3*2`', '2.4e3'],
122-
['`2.0^2`', '4', True],
123-
['`sqrt(4.0)`', '2', True]])
91+
@parameterized.expand([['`1.234`', '1.234'], ['`1.234*2.0`', '2.468'], ['`10`', '1e1'], ['`10*2`', '2e1'],
92+
['`1.0/2.0`', '5e-1'], ['`2.0**2`', '4'], ['`1.0 + 2.0**2`', '5'], ['`(1.0 + 2.0)**2`', '9'],
93+
['`((1.0 + 2.0)**2)**(0.5)`', '3'], ['`(1.2e3)*2`', '2.4e3'], ['`1.2e3*2`', '2.4e3'],
94+
['`2.0^2`', '4', True], ['`sqrt(4.0)`', '2', True]])
12495
def test_symbolic_regex(self, symbolicInput, expectedValue, expect_fail=False):
12596
try:
12697
result = re.sub(regex_tools.patterns['symbolic'], regex_tools.SymbolicMathRegexHandler, symbolicInput)
@@ -131,6 +102,7 @@ def test_symbolic_regex(self, symbolicInput, expectedValue, expect_fail=False):
131102

132103
# Test the complete xml processor
133104
class TestXMLProcessor(unittest.TestCase):
105+
134106
@classmethod
135107
def setUpClass(cls):
136108
generate_test_xml.generate_test_xml_files('.')

0 commit comments

Comments
 (0)