Skip to content

Commit 7438aa0

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 2177733 commit 7438aa0

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
@@ -83,6 +83,12 @@ jobs:
8383
pip install -e .
8484
flake8 libensemble
8585
86+
- name: Install mypy
87+
run: pip install mypy
88+
89+
- name: Run mypy (limited scope)
90+
run: mypy
91+
8692
- name: Remove various tests on newer pythons
8793
if: matrix.python-version >= '3.11'
8894
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
@@ -140,7 +140,18 @@ inpt = "inpt"
140140
extend-exclude = ["*.bib", "*.xml", "docs/nitpicky"]
141141

142142
[tool.mypy]
143+
# Initial, permissive mypy configuration for libensemble.
144+
# Allows incremental adoption. To be tightened in future releases.
145+
packages = ["libensemble.utils"]
146+
exclude = '''
147+
libensemble/utils/(launcher|loc_stack|runners|pydantic|output_directory)\.py
148+
'''
143149
disable_error_code = ["import-not-found", "import-untyped"]
150+
ignore_missing_imports = true
151+
follow_imports = "skip"
152+
check_untyped_defs = false
153+
disallow_untyped_defs = false
154+
warn_unused_ignores = false
144155

145156
[dependency-groups]
146157
dev = ["pyenchant", "enchant>=0.0.1,<0.0.2", "flake8-modern-annotations>=1.6.0,<2", "flake8-type-checking>=3.0.0,<4"]

0 commit comments

Comments
 (0)