Skip to content

Commit 88ecfb8

Browse files
committed
Add initial mypy configuration and CI integration
Introduce mypy with a permissive, incremental configuration. Type checking is limited to libensemble/utils and excludes files not yet migrated. Make libensemble/utils/misc.py compliant with mypy.
1 parent 0f2ee07 commit 88ecfb8

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/basic.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ jobs:
6363
pip install -e .
6464
flake8 libensemble
6565
66+
- name: Install mypy
67+
run: pip install mypy
68+
69+
- name: Run mypy (limited scope)
70+
run: mypy
71+
6672
- name: Remove various tests on newer pythons
6773
if: matrix.python-version == 'py311' || matrix.python-version == 'py312' || matrix.python-version == 'py313' || matrix.python-version == 'py314'
6874
run: |

libensemble/utils/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def extract_H_ranges(Work: dict) -> str:
1414
else:
1515
# From https://stackoverflow.com/a/30336492
1616
ranges = []
17-
for diff, group in groupby(enumerate(work_H_rows.tolist()), lambda x: x[0] - x[1]):
18-
group = list(map(itemgetter(1), group))
17+
for diff, group_iter in groupby(enumerate(work_H_rows.tolist()), lambda x: x[0] - x[1]):
18+
group = list(map(itemgetter(1), group_iter))
1919
if len(group) > 1:
2020
ranges.append(str(group[0]) + "-" + str(group[-1]))
2121
else:

libensemble/utils/output_directory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def _make_calc_dir(self, workerID, H_rows, calc_str: str, locs: LocationStack):
110110

111111
# If using input_dir, set of files to copy is contents of provided dir
112112
if input_dir:
113+
assert isinstance(input_dir, Path)
113114
copy_files = set(copy_files + [i for i in input_dir.iterdir()])
114115

115116
# If identical paths to copy and symlink, remove those paths from symlink_files
@@ -124,7 +125,7 @@ def _make_calc_dir(self, workerID, H_rows, calc_str: str, locs: LocationStack):
124125
prefix = self.ensemble_dir
125126
else: # Each worker does work in prefix (ensemble_dir)
126127
key = self.ensemble_dir
127-
dirname = self.ensemble_dir
128+
dirname = str(self.ensemble_dir)
128129
prefix = None
129130

130131
locs.register_loc(

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,15 @@ inpt = "inpt"
244244
extend-exclude = ["*.bib", "*.xml", "docs/nitpicky"]
245245

246246
[tool.mypy]
247+
# Initial, permissive mypy configuration for libensemble.
248+
# Allows incremental adoption. To be tightened in future releases.
249+
packages = ["libensemble.utils"]
250+
exclude = '''
251+
libensemble/utils/(launcher|loc_stack|runners|pydantic|output_directory)\.py
252+
'''
247253
disable_error_code = ["import-not-found", "import-untyped"]
254+
ignore_missing_imports = true
255+
follow_imports = "skip"
256+
check_untyped_defs = false
257+
disallow_untyped_defs = false
258+
warn_unused_ignores = false

0 commit comments

Comments
 (0)