Skip to content

Commit 52dece5

Browse files
committed
fix charm4py formatting and add check
1 parent a067434 commit 52dece5

107 files changed

Lines changed: 4305 additions & 2514 deletions

File tree

Some content is hidden

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

.github/workflows/formatting.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Lint
2+
3+
on: # yamllint disable-line rule:truthy
4+
push: null
5+
pull_request: null
6+
7+
permissions: {}
8+
9+
jobs:
10+
build:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
14+
permissions:
15+
contents: read
16+
packages: read
17+
# To report GitHub Actions status checks
18+
statuses: write
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
# super-linter needs the full git history to get the
25+
# list of files that changed across commits
26+
fetch-depth: 0
27+
28+
- name: Super-linter
29+
uses: super-linter/super-linter@v7.4.0 # x-release-please-version
30+
env:
31+
# To report GitHub Actions status checks
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

auto_test.py

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import subprocess
33
import sys
4+
45
if sys.version_info[0] < 3:
56
print("auto_test requires Python 3")
67
exit(1)
@@ -10,21 +11,23 @@
1011
import json
1112

1213

13-
if len(sys.argv) == 2 and sys.argv[1] == '-version_check':
14+
if len(sys.argv) == 2 and sys.argv[1] == "-version_check":
1415
exit(sys.version_info[0])
1516

1617

1718
def searchForPython(python_implementations):
1819
py3_exec = None
19-
py3_exec = shutil.which('python3')
20+
py3_exec = shutil.which("python3")
2021
if py3_exec is None:
21-
exec_str = shutil.which('python')
22+
exec_str = shutil.which("python")
2223
if exec_str is not None:
23-
version = subprocess.call([exec_str, 'auto_test.py', '-version_check'])
24+
version = subprocess.call([exec_str, "auto_test.py", "-version_check"])
2425
if version >= 3:
2526
py3_exec = exec_str
2627
if py3_exec is None:
27-
print("WARNING: Python 3 executable not found for auto_test. If desired, set manually")
28+
print(
29+
"WARNING: Python 3 executable not found for auto_test. If desired, set manually"
30+
)
2831
else:
2932
python_implementations.add((3, py3_exec))
3033

@@ -33,76 +36,89 @@ def searchForPython(python_implementations):
3336
TIMEOUT = 120 # timeout for each test (in seconds)
3437
CHARM_QUIET_AFTER_NUM_TESTS = 5
3538

36-
commonArgs = ['++local']
37-
default_num_processes = int(os.environ.get('CHARM4PY_TEST_NUM_PROCESSES', 4))
39+
commonArgs = ["++local"]
40+
default_num_processes = int(os.environ.get("CHARM4PY_TEST_NUM_PROCESSES", 4))
3841

3942
try:
4043
import numba
44+
4145
numbaInstalled = True
4246
except:
4347
numbaInstalled = False
4448

4549
# search for python executables
46-
python_implementations = set() # python implementations can also be added here manually
50+
python_implementations = set() # python implementations can also be added here manually
4751
searchForPython(python_implementations)
4852

49-
interfaces = ['cython']
53+
interfaces = ["cython"]
5054

51-
with open('test_config.json', 'r') as infile:
55+
with open("test_config.json", "r") as infile:
5256
tests = json.load(infile)
5357

5458
num_tests = 0
5559
durations = defaultdict(dict)
5660
for test in tests:
57-
if 'condition' in test:
58-
if test['condition'] == 'numbaInstalled' and not numbaInstalled:
61+
if "condition" in test:
62+
if test["condition"] == "numbaInstalled" and not numbaInstalled:
5963
continue
60-
if test['condition'] == 'not numbaInstalled' and numbaInstalled:
64+
if test["condition"] == "not numbaInstalled" and numbaInstalled:
6165
continue
62-
if 'timeout_override' in test:
63-
TIMEOUT = test['timeout_override']
66+
if "timeout_override" in test:
67+
TIMEOUT = test["timeout_override"]
6468
else:
6569
TIMEOUT = 120
66-
num_processes = max(test.get('force_min_processes', default_num_processes), default_num_processes)
70+
num_processes = max(
71+
test.get("force_min_processes", default_num_processes), default_num_processes
72+
)
6773
for interface in interfaces:
68-
durations[interface][test['path']] = []
74+
durations[interface][test["path"]] = []
6975
for version, python in sorted(python_implementations):
70-
if version < test.get('requires_py_version', -1):
76+
if version < test.get("requires_py_version", -1):
7177
continue
7278
additionalArgs = []
73-
if num_tests >= CHARM_QUIET_AFTER_NUM_TESTS and '++quiet' not in commonArgs:
74-
additionalArgs.append('++quiet')
75-
cmd = ['charmrun/charmrun']
76-
if test.get('prefix'):
77-
cmd += [test['prefix']]
78-
if not test.get('interactive', False):
79-
cmd += [python] + [test['path']]
79+
if num_tests >= CHARM_QUIET_AFTER_NUM_TESTS and "++quiet" not in commonArgs:
80+
additionalArgs.append("++quiet")
81+
cmd = ["charmrun/charmrun"]
82+
if test.get("prefix"):
83+
cmd += [test["prefix"]]
84+
if not test.get("interactive", False):
85+
cmd += [python] + [test["path"]]
8086
else:
81-
cmd += [python] + ['-m', 'charm4py.interactive']
82-
if 'args' in test:
83-
cmd += test['args'].split(' ')
87+
cmd += [python] + ["-m", "charm4py.interactive"]
88+
if "args" in test:
89+
cmd += test["args"].split(" ")
8490
cmd += commonArgs
85-
cmd += ['+p' + str(num_processes), '+libcharm_interface', interface]
91+
cmd += ["+p" + str(num_processes), "+libcharm_interface", interface]
8692
cmd += additionalArgs
87-
print('Test command is ' + ' '.join(cmd))
93+
print("Test command is " + " ".join(cmd))
8894
startTime = time.time()
8995
stdin = None
90-
if test.get('interactive', False):
91-
stdin = open(test['path'])
96+
if test.get("interactive", False):
97+
stdin = open(test["path"])
9298
p = subprocess.Popen(cmd, stdin=stdin)
9399
try:
94100
rc = p.wait(TIMEOUT)
95101
except subprocess.TimeoutExpired:
96-
print("Timeout (" + str(TIMEOUT) + " secs) expired when running " + test['path'] + ", Killing process")
102+
print(
103+
"Timeout ("
104+
+ str(TIMEOUT)
105+
+ " secs) expired when running "
106+
+ test["path"]
107+
+ ", Killing process"
108+
)
97109
p.kill()
98110
rc = -1
99111
if rc != 0:
100-
print("ERROR running test " + test['path'] + " with " + python)
112+
print("ERROR running test " + test["path"] + " with " + python)
101113
exit(1)
102114
else:
103115
elapsed = round(time.time() - startTime, 3)
104-
durations[interface][test['path']].append(elapsed)
105-
print("\n\n--------------------- TEST PASSED (in " + str(elapsed) + " secs) ---------------------\n\n")
116+
durations[interface][test["path"]].append(elapsed)
117+
print(
118+
"\n\n--------------------- TEST PASSED (in "
119+
+ str(elapsed)
120+
+ " secs) ---------------------\n\n"
121+
)
106122
num_tests += 1
107123

108124

charm4py/__init__.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
import sys
2+
23
if sys.version_info < (3, 8, 0):
3-
raise RuntimeError('Charm4py requires Python 3.8 or higher')
4+
raise RuntimeError("Charm4py requires Python 3.8 or higher")
45
import atexit
56
import os
7+
68
try:
79
import greenlet
810
except ImportError:
9-
print('Charm4py requires the greenlet package. It can be installed via pip')
11+
print("Charm4py requires the greenlet package. It can be installed via pip")
1012
exit(-1)
1113

1214

13-
charm4py_version = 'unknown'
15+
charm4py_version = "unknown"
1416
try:
1517
from ._version import version as charm4py_version
1618
except:
1719
try:
1820
import subprocess
19-
charm4py_version = subprocess.check_output(['git', 'describe'],
20-
cwd=os.path.dirname(__file__)).rstrip().decode()
21+
22+
charm4py_version = (
23+
subprocess.check_output(["git", "describe"], cwd=os.path.dirname(__file__))
24+
.rstrip()
25+
.decode()
26+
)
2127
except:
2228
pass
2329

24-
if os.environ.get('CHARM_NOLOAD', '0') == '0':
30+
if os.environ.get("CHARM_NOLOAD", "0") == "0":
2531
from .charm import register, charm, readonlies, Options
32+
2633
Reducer = charm.reducers
2734
Future = charm.createFuture
2835

@@ -34,7 +41,9 @@
3441

3542
def checkCharmStarted():
3643
if not charm.started:
37-
print('Program is exiting but charm was not started: charm.start() was not '
38-
'called or error happened before start')
44+
print(
45+
"Program is exiting but charm was not started: charm.start() was not "
46+
"called or error happened before start"
47+
)
3948

4049
atexit.register(checkCharmStarted)

charm4py/channel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Channel(object):
55

66
def __new__(cls, chare, remote, local=None):
7-
if not hasattr(chare, '__channels__'):
7+
if not hasattr(chare, "__channels__"):
88
chare.__initchannelattrs__()
99
ch = chare.__findPendingChannel__(remote, False)
1010
if ch is None:
@@ -16,7 +16,7 @@ def __new__(cls, chare, remote, local=None):
1616
ch.setEstablished()
1717
if local is None:
1818
# if local is None, we assume local endpoint is the individual chare
19-
if hasattr(chare, 'thisIndex'):
19+
if hasattr(chare, "thisIndex"):
2020
local = chare.thisProxy[chare.thisIndex]
2121
else:
2222
local = chare.thisProxy
@@ -26,6 +26,7 @@ def __new__(cls, chare, remote, local=None):
2626

2727
CHAN_BUF_SIZE = 40000
2828

29+
2930
class _Channel(object):
3031

3132
def __init__(self, port, remote, locally_initiated):
@@ -36,7 +37,9 @@ def __init__(self, port, remote, locally_initiated):
3637
self.recv_seqno = 0
3738
self.data = {}
3839
self.recv_fut = None # this future is used to block on self.recv()
39-
self.wait_ready = None # this future is used to block on ready (by charm.iwait())
40+
self.wait_ready = (
41+
None # this future is used to block on ready (by charm.iwait())
42+
)
4043
self.established = False
4144
self.established_fut = None
4245
self.locally_initiated = locally_initiated

0 commit comments

Comments
 (0)