We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add type hints to toilMain.py
Add type hints to src/toil/utils/toilMain.py so it can be checked under mypy during linting.

Refers to #3568.

┆Issue is synchronized with this [Jira Task](https://ucsc-cgl.atlassian.net/browse/TOIL-891)
┆Issue Number: TOIL-891


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/toil/utils/toilMain.py`
Content:
```
1 import os
2 import re
3 import sys
4 import textwrap
5 
6 import pkg_resources
7 
8 from toil.version import version
9 
10 
11 def main():
12     modules = loadModules()
13 
14     if len(sys.argv) < 2 or sys.argv[1] == '--help':
15         printHelp(modules)
16         sys.exit(0)
17 
18     cmd = sys.argv[1]
19     if cmd == '--version':
20         printVersion()
21         sys.exit(0)
22 
23     try:
24         module = modules[cmd]
25     except KeyError:
26         sys.stderr.write(f'Unknown option "{cmd}".  Pass --help to display usage information.\n')
27         sys.exit(1)
28 
29     del sys.argv[1]
30     module.main()
31 
32 def loadModules():
33     # noinspection PyUnresolvedReferences
34     from toil.utils import (toilClean,
35                             toilDebugFile,
36                             toilDebugJob,
37                             toilDestroyCluster,
38                             toilKill,
39                             toilLaunchCluster,
40                             toilRsyncCluster,
41                             toilSshCluster,
42                             toilStats,
43                             toilStatus)
44     return {"-".join([i.lower() for i in re.findall('[A-Z][^A-Z]*', name)]): module for name, module in locals().items()}
45 
46 
47 def printHelp(modules):
48     name = os.path.basename(sys.argv[0])
49     descriptions = '\n        '.join(f'{cmd} - {mod.__doc__.strip()}' for cmd, mod in modules.items() if mod)
50     print(textwrap.dedent(f"""
51         Usage: {name} COMMAND ...
52                {name} --help
53                {name} COMMAND --help
54 
55         Where COMMAND is one of the following:
56 
57         {descriptions}
58         """[1:]))
59 
60 
61 def printVersion():
62     try:
63         print(pkg_resources.get_distribution('toil').version)
64     except:
65         print(f'Version gathered from toil.version: {version}')
66
```

Path: `contrib/admin/mypy-with-ignore.py`
Content:
```
1 #!/usr/bin/env python3
2 """
3 Runs mypy and ignores files that do not yet have passing type hints.
4 
5 Does not type check test files (any path including "src/toil/test").
6 """
7 import os
8 import subprocess
9 import sys
10 
11 os.environ['MYPYPATH'] = 'contrib/typeshed'
12 pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))  # noqa
13 sys.path.insert(0, pkg_root)  # noqa
14 
15 from src.toil.lib.resources import glob  # type: ignore
16 
17 
18 def main():
19     all_files_to_check = []
20     for d in ['dashboard', 'docker', 'docs', 'src']:
21         all_files_to_check += glob(glob_pattern='*.py', directoryname=os.path.join(pkg_root, d))
22 
23     # TODO: Remove these paths as typing is added and mypy conflicts are addressed
24     ignore_paths = [os.path.abspath(f) for f in [
25         'docker/Dockerfile.py',
26         'docs/conf.py',
27         'docs/vendor/sphinxcontrib/fulltoc.py',
28         'docs/vendor/sphinxcontrib/__init__.py',
29         'src/toil/job.py',
30         'src/toil/leader.py',
31         'src/toil/statsAndLogging.py',
32         'src/toil/common.py',
33         'src/toil/realtimeLogger.py',
34         'src/toil/worker.py',
35         'src/toil/serviceManager.py',
36         'src/toil/toilState.py',
37         'src/toil/__init__.py',
38         'src/toil/resource.py',
39         'src/toil/deferred.py',
40         'src/toil/version.py',
41         'src/toil/wdl/utils.py',
42         'src/toil/wdl/wdl_types.py',
43         'src/toil/wdl/wdl_synthesis.py',
44         'src/toil/wdl/wdl_analysis.py',
45         'src/toil/wdl/wdl_functions.py',
46         'src/toil/wdl/toilwdl.py',
47         'src/toil/wdl/versions/draft2.py',
48         'src/toil/wdl/versions/v1.py',
49         'src/toil/wdl/versions/dev.py',
50         'src/toil/provisioners/clusterScaler.py',
51         'src/toil/provisioners/abstractProvisioner.py',
52         'src/toil/provisioners/gceProvisioner.py',
53         'src/toil/provisioners/__init__.py',
54         'src/toil/provisioners/node.py',
55         'src/toil/provisioners/aws/boto2Context.py',
56         'src/toil/provisioners/aws/awsProvisioner.py',
57         'src/toil/provisioners/aws/__init__.py',
58         'src/toil/batchSystems/slurm.py',
59         'src/toil/batchSystems/gridengine.py',
60         'src/toil/batchSystems/singleMachine.py',
61         'src/toil/batchSystems/abstractBatchSystem.py',
62         'src/toil/batchSystems/parasol.py',
63         'src/toil/batchSystems/kubernetes.py',
64         'src/toil/batchSystems/torque.py',
65         'src/toil/batchSystems/options.py',
66         'src/toil/batchSystems/registry.py',
67         'src/toil/batchSystems/lsf.py',
68         'src/toil/batchSystems/__init__.py',
69         'src/toil/batchSystems/abstractGridEngineBatchSystem.py',
70         'src/toil/batchSystems/lsfHelper.py',
71         'src/toil/batchSystems/htcondor.py',
72         'src/toil/batchSystems/mesos/batchSystem.py',
73         'src/toil/batchSystems/mesos/executor.py',
74         'src/toil/batchSystems/mesos/conftest.py',
75         'src/toil/batchSystems/mesos/__init__.py',
76         'src/toil/batchSystems/mesos/test/__init__.py',
77         'src/toil/cwl/conftest.py',
78         'src/toil/cwl/__init__.py',
79         'src/toil/cwl/cwltoil.py',
80         'src/toil/fileStores/cachingFileStore.py',
81         'src/toil/fileStores/abstractFileStore.py',
82         'src/toil/fileStores/nonCachingFileStore.py',
83         'src/toil/fileStores/__init__.py',
84         'src/toil/jobStores/utils.py',
85         'src/toil/jobStores/abstractJobStore.py',
86         'src/toil/jobStores/conftest.py',
87         'src/toil/jobStores/fileJobStore.py',
88         'src/toil/jobStores/__init__.py',
89         'src/toil/jobStores/googleJobStore.py',
90         'src/toil/jobStores/aws/utils.py',
91         'src/toil/jobStores/aws/jobStore.py',
92         'src/toil/jobStores/aws/__init__.py',
93         'src/toil/utils/toilDebugFile.py',
94         'src/toil/utils/toilStatus.py',
95         'src/toil/utils/toilStats.py',
96         'src/toil/utils/toilMain.py',
97         'src/toil/utils/__init__.py',
98         'src/toil/utils/toilLaunchCluster.py',
99         'src/toil/lib/memoize.py',
100         'src/toil/lib/throttle.py',
101         'src/toil/lib/humanize.py',
102         'src/toil/lib/compatibility.py',
103         'src/toil/lib/iterables.py',
104         'src/toil/lib/bioio.py',
105         'src/toil/lib/ec2.py',
106         # 'src/toil/lib/conversions.py',
107         'src/toil/lib/ec2nodes.py',
108         # 'src/toil/lib/misc.py',
109         'src/toil/lib/expando.py',
110         'src/toil/lib/threading.py',
111         'src/toil/lib/exceptions.py',
112         'src/toil/lib/__init__.py',
113         'src/toil/lib/generatedEC2Lists.py',
114         'src/toil/lib/retry.py',
115         'src/toil/lib/objects.py',
116         'src/toil/lib/io.py',
117         'src/toil/lib/docker.py',
118         # 'src/toil/lib/encryption/_nacl.py',
119         'src/toil/lib/encryption/_dummy.py',
120         'src/toil/lib/encryption/conftest.py',
121         'src/toil/lib/encryption/__init__.py',
122         'src/toil/lib/aws/utils.py',
123         'src/toil/lib/aws/__init__.py'
124     ]]
125 
126     filtered_files_to_check = []
127     for file_path in all_files_to_check:
128         if file_path not in ignore_paths and 'src/toil/test' not in file_path:
129             filtered_files_to_check.append(file_path)
130     # follow-imports type checks pypi projects we don't control, so we skip it; why is this their default?
131     args = ['mypy', '--follow-imports=skip'] + filtered_files_to_check
132     p = subprocess.run(args=args, stdout=subprocess.PIPE)
133     result = p.stdout.decode()
134     print(result)
135     if 'Success: no issues found' not in result:
136         exit(1)
137 
138 
139 if __name__ == '__main__':
140     main()
141
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/contrib/admin/mypy-with-ignore.py b/contrib/admin/mypy-with-ignore.py
--- a/contrib/admin/mypy-with-ignore.py
+++ b/contrib/admin/mypy-with-ignore.py
@@ -93,7 +93,6 @@
         'src/toil/utils/toilDebugFile.py',
         'src/toil/utils/toilStatus.py',
         'src/toil/utils/toilStats.py',
-        'src/toil/utils/toilMain.py',
         'src/toil/utils/__init__.py',
         'src/toil/utils/toilLaunchCluster.py',
         'src/toil/lib/memoize.py',
@@ -103,9 +102,7 @@
         'src/toil/lib/iterables.py',
         'src/toil/lib/bioio.py',
         'src/toil/lib/ec2.py',
-        # 'src/toil/lib/conversions.py',
         'src/toil/lib/ec2nodes.py',
-        # 'src/toil/lib/misc.py',
         'src/toil/lib/expando.py',
         'src/toil/lib/threading.py',
         'src/toil/lib/exceptions.py',
diff --git a/src/toil/utils/toilMain.py b/src/toil/utils/toilMain.py
--- a/src/toil/utils/toilMain.py
+++ b/src/toil/utils/toilMain.py
@@ -2,13 +2,14 @@
 import re
 import sys
 import textwrap
+import types
 
 import pkg_resources
 
 from toil.version import version
+from typing import Any, Dict
 
-
-def main():
+def main() -> None:
     modules = loadModules()
 
     if len(sys.argv) < 2 or sys.argv[1] == '--help':
@@ -27,9 +28,20 @@
         sys.exit(1)
 
     del sys.argv[1]
-    module.main()
+    get_or_die(module, 'main')()
+
+def get_or_die(module: types.ModuleType, name: str) -> Any:
+    """
+    Get an object from a module or complain that it is missing.
+    """
+    if hasattr(module, name):
+        return getattr(module, name)
+    else:
+        sys.stderr.write(f'Internal Toil error!\nToil utility module '
+                         f'{module.__name__} is missing required attribute {name}\n')
+        sys.exit(1)
 
-def loadModules():
+def loadModules() -> Dict[str, types.ModuleType]:
     # noinspection PyUnresolvedReferences
     from toil.utils import (toilClean,
                             toilDebugFile,
@@ -44,9 +56,9 @@
     return {"-".join([i.lower() for i in re.findall('[A-Z][^A-Z]*', name)]): module for name, module in locals().items()}
 
 
-def printHelp(modules):
+def printHelp(modules: Dict[str, types.ModuleType]) -> None:
     name = os.path.basename(sys.argv[0])
-    descriptions = '\n        '.join(f'{cmd} - {mod.__doc__.strip()}' for cmd, mod in modules.items() if mod)
+    descriptions = '\n        '.join(f'{cmd} - {get_or_die(mod, "__doc__").strip()}' for cmd, mod in modules.items() if mod)
     print(textwrap.dedent(f"""
         Usage: {name} COMMAND ...
                {name} --help
@@ -58,7 +70,7 @@
         """[1:]))
 
 
-def printVersion():
+def printVersion() -> None:
     try:
         print(pkg_resources.get_distribution('toil').version)
     except:

{"golden_diff": "diff --git a/contrib/admin/mypy-with-ignore.py b/contrib/admin/mypy-with-ignore.py\n--- a/contrib/admin/mypy-with-ignore.py\n+++ b/contrib/admin/mypy-with-ignore.py\n@@ -93,7 +93,6 @@\n         'src/toil/utils/toilDebugFile.py',\n         'src/toil/utils/toilStatus.py',\n         'src/toil/utils/toilStats.py',\n-        'src/toil/utils/toilMain.py',\n         'src/toil/utils/__init__.py',\n         'src/toil/utils/toilLaunchCluster.py',\n         'src/toil/lib/memoize.py',\n@@ -103,9 +102,7 @@\n         'src/toil/lib/iterables.py',\n         'src/toil/lib/bioio.py',\n         'src/toil/lib/ec2.py',\n-        # 'src/toil/lib/conversions.py',\n         'src/toil/lib/ec2nodes.py',\n-        # 'src/toil/lib/misc.py',\n         'src/toil/lib/expando.py',\n         'src/toil/lib/threading.py',\n         'src/toil/lib/exceptions.py',\ndiff --git a/src/toil/utils/toilMain.py b/src/toil/utils/toilMain.py\n--- a/src/toil/utils/toilMain.py\n+++ b/src/toil/utils/toilMain.py\n@@ -2,13 +2,14 @@\n import re\n import sys\n import textwrap\n+import types\n \n import pkg_resources\n \n from toil.version import version\n+from typing import Any, Dict\n \n-\n-def main():\n+def main() -> None:\n     modules = loadModules()\n \n     if len(sys.argv) < 2 or sys.argv[1] == '--help':\n@@ -27,9 +28,20 @@\n         sys.exit(1)\n \n     del sys.argv[1]\n-    module.main()\n+    get_or_die(module, 'main')()\n+\n+def get_or_die(module: types.ModuleType, name: str) -> Any:\n+    \"\"\"\n+    Get an object from a module or complain that it is missing.\n+    \"\"\"\n+    if hasattr(module, name):\n+        return getattr(module, name)\n+    else:\n+        sys.stderr.write(f'Internal Toil error!\\nToil utility module '\n+                         f'{module.__name__} is missing required attribute {name}\\n')\n+        sys.exit(1)\n \n-def loadModules():\n+def loadModules() -> Dict[str, types.ModuleType]:\n     # noinspection PyUnresolvedReferences\n     from toil.utils import (toilClean,\n                             toilDebugFile,\n@@ -44,9 +56,9 @@\n     return {\"-\".join([i.lower() for i in re.findall('[A-Z][^A-Z]*', name)]): module for name, module in locals().items()}\n \n \n-def printHelp(modules):\n+def printHelp(modules: Dict[str, types.ModuleType]) -> None:\n     name = os.path.basename(sys.argv[0])\n-    descriptions = '\\n        '.join(f'{cmd} - {mod.__doc__.strip()}' for cmd, mod in modules.items() if mod)\n+    descriptions = '\\n        '.join(f'{cmd} - {get_or_die(mod, \"__doc__\").strip()}' for cmd, mod in modules.items() if mod)\n     print(textwrap.dedent(f\"\"\"\n         Usage: {name} COMMAND ...\n                {name} --help\n@@ -58,7 +70,7 @@\n         \"\"\"[1:]))\n \n \n-def printVersion():\n+def printVersion() -> None:\n     try:\n         print(pkg_resources.get_distribution('toil').version)\n     except:\n", "issue": "Add type hints to toilMain.py\nAdd type hints to src/toil/utils/toilMain.py so it can be checked under mypy during linting.\n\nRefers to #3568.\n\n\u2506Issue is synchronized with this [Jira Task](https://ucsc-cgl.atlassian.net/browse/TOIL-891)\n\u2506Issue Number: TOIL-891\n\n", "before_files": [{"content": "import os\nimport re\nimport sys\nimport textwrap\n\nimport pkg_resources\n\nfrom toil.version import version\n\n\ndef main():\n    modules = loadModules()\n\n    if len(sys.argv) < 2 or sys.argv[1] == '--help':\n        printHelp(modules)\n        sys.exit(0)\n\n    cmd = sys.argv[1]\n    if cmd == '--version':\n        printVersion()\n        sys.exit(0)\n\n    try:\n        module = modules[cmd]\n    except KeyError:\n        sys.stderr.write(f'Unknown option \"{cmd}\".  Pass --help to display usage information.\\n')\n        sys.exit(1)\n\n    del sys.argv[1]\n    module.main()\n\ndef loadModules():\n    # noinspection PyUnresolvedReferences\n    from toil.utils import (toilClean,\n                            toilDebugFile,\n                            toilDebugJob,\n                            toilDestroyCluster,\n                            toilKill,\n                            toilLaunchCluster,\n                            toilRsyncCluster,\n                            toilSshCluster,\n                            toilStats,\n                            toilStatus)\n    return {\"-\".join([i.lower() for i in re.findall('[A-Z][^A-Z]*', name)]): module for name, module in locals().items()}\n\n\ndef printHelp(modules):\n    name = os.path.basename(sys.argv[0])\n    descriptions = '\\n        '.join(f'{cmd} - {mod.__doc__.strip()}' for cmd, mod in modules.items() if mod)\n    print(textwrap.dedent(f\"\"\"\n        Usage: {name} COMMAND ...\n               {name} --help\n               {name} COMMAND --help\n\n        Where COMMAND is one of the following:\n\n        {descriptions}\n        \"\"\"[1:]))\n\n\ndef printVersion():\n    try:\n        print(pkg_resources.get_distribution('toil').version)\n    except:\n        print(f'Version gathered from toil.version: {version}')\n", "path": "src/toil/utils/toilMain.py"}, {"content": "#!/usr/bin/env python3\n\"\"\"\nRuns mypy and ignores files that do not yet have passing type hints.\n\nDoes not type check test files (any path including \"src/toil/test\").\n\"\"\"\nimport os\nimport subprocess\nimport sys\n\nos.environ['MYPYPATH'] = 'contrib/typeshed'\npkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))  # noqa\nsys.path.insert(0, pkg_root)  # noqa\n\nfrom src.toil.lib.resources import glob  # type: ignore\n\n\ndef main():\n    all_files_to_check = []\n    for d in ['dashboard', 'docker', 'docs', 'src']:\n        all_files_to_check += glob(glob_pattern='*.py', directoryname=os.path.join(pkg_root, d))\n\n    # TODO: Remove these paths as typing is added and mypy conflicts are addressed\n    ignore_paths = [os.path.abspath(f) for f in [\n        'docker/Dockerfile.py',\n        'docs/conf.py',\n        'docs/vendor/sphinxcontrib/fulltoc.py',\n        'docs/vendor/sphinxcontrib/__init__.py',\n        'src/toil/job.py',\n        'src/toil/leader.py',\n        'src/toil/statsAndLogging.py',\n        'src/toil/common.py',\n        'src/toil/realtimeLogger.py',\n        'src/toil/worker.py',\n        'src/toil/serviceManager.py',\n        'src/toil/toilState.py',\n        'src/toil/__init__.py',\n        'src/toil/resource.py',\n        'src/toil/deferred.py',\n        'src/toil/version.py',\n        'src/toil/wdl/utils.py',\n        'src/toil/wdl/wdl_types.py',\n        'src/toil/wdl/wdl_synthesis.py',\n        'src/toil/wdl/wdl_analysis.py',\n        'src/toil/wdl/wdl_functions.py',\n        'src/toil/wdl/toilwdl.py',\n        'src/toil/wdl/versions/draft2.py',\n        'src/toil/wdl/versions/v1.py',\n        'src/toil/wdl/versions/dev.py',\n        'src/toil/provisioners/clusterScaler.py',\n        'src/toil/provisioners/abstractProvisioner.py',\n        'src/toil/provisioners/gceProvisioner.py',\n        'src/toil/provisioners/__init__.py',\n        'src/toil/provisioners/node.py',\n        'src/toil/provisioners/aws/boto2Context.py',\n        'src/toil/provisioners/aws/awsProvisioner.py',\n        'src/toil/provisioners/aws/__init__.py',\n        'src/toil/batchSystems/slurm.py',\n        'src/toil/batchSystems/gridengine.py',\n        'src/toil/batchSystems/singleMachine.py',\n        'src/toil/batchSystems/abstractBatchSystem.py',\n        'src/toil/batchSystems/parasol.py',\n        'src/toil/batchSystems/kubernetes.py',\n        'src/toil/batchSystems/torque.py',\n        'src/toil/batchSystems/options.py',\n        'src/toil/batchSystems/registry.py',\n        'src/toil/batchSystems/lsf.py',\n        'src/toil/batchSystems/__init__.py',\n        'src/toil/batchSystems/abstractGridEngineBatchSystem.py',\n        'src/toil/batchSystems/lsfHelper.py',\n        'src/toil/batchSystems/htcondor.py',\n        'src/toil/batchSystems/mesos/batchSystem.py',\n        'src/toil/batchSystems/mesos/executor.py',\n        'src/toil/batchSystems/mesos/conftest.py',\n        'src/toil/batchSystems/mesos/__init__.py',\n        'src/toil/batchSystems/mesos/test/__init__.py',\n        'src/toil/cwl/conftest.py',\n        'src/toil/cwl/__init__.py',\n        'src/toil/cwl/cwltoil.py',\n        'src/toil/fileStores/cachingFileStore.py',\n        'src/toil/fileStores/abstractFileStore.py',\n        'src/toil/fileStores/nonCachingFileStore.py',\n        'src/toil/fileStores/__init__.py',\n        'src/toil/jobStores/utils.py',\n        'src/toil/jobStores/abstractJobStore.py',\n        'src/toil/jobStores/conftest.py',\n        'src/toil/jobStores/fileJobStore.py',\n        'src/toil/jobStores/__init__.py',\n        'src/toil/jobStores/googleJobStore.py',\n        'src/toil/jobStores/aws/utils.py',\n        'src/toil/jobStores/aws/jobStore.py',\n        'src/toil/jobStores/aws/__init__.py',\n        'src/toil/utils/toilDebugFile.py',\n        'src/toil/utils/toilStatus.py',\n        'src/toil/utils/toilStats.py',\n        'src/toil/utils/toilMain.py',\n        'src/toil/utils/__init__.py',\n        'src/toil/utils/toilLaunchCluster.py',\n        'src/toil/lib/memoize.py',\n        'src/toil/lib/throttle.py',\n        'src/toil/lib/humanize.py',\n        'src/toil/lib/compatibility.py',\n        'src/toil/lib/iterables.py',\n        'src/toil/lib/bioio.py',\n        'src/toil/lib/ec2.py',\n        # 'src/toil/lib/conversions.py',\n        'src/toil/lib/ec2nodes.py',\n        # 'src/toil/lib/misc.py',\n        'src/toil/lib/expando.py',\n        'src/toil/lib/threading.py',\n        'src/toil/lib/exceptions.py',\n        'src/toil/lib/__init__.py',\n        'src/toil/lib/generatedEC2Lists.py',\n        'src/toil/lib/retry.py',\n        'src/toil/lib/objects.py',\n        'src/toil/lib/io.py',\n        'src/toil/lib/docker.py',\n        # 'src/toil/lib/encryption/_nacl.py',\n        'src/toil/lib/encryption/_dummy.py',\n        'src/toil/lib/encryption/conftest.py',\n        'src/toil/lib/encryption/__init__.py',\n        'src/toil/lib/aws/utils.py',\n        'src/toil/lib/aws/__init__.py'\n    ]]\n\n    filtered_files_to_check = []\n    for file_path in all_files_to_check:\n        if file_path not in ignore_paths and 'src/toil/test' not in file_path:\n            filtered_files_to_check.append(file_path)\n    # follow-imports type checks pypi projects we don't control, so we skip it; why is this their default?\n    args = ['mypy', '--follow-imports=skip'] + filtered_files_to_check\n    p = subprocess.run(args=args, stdout=subprocess.PIPE)\n    result = p.stdout.decode()\n    print(result)\n    if 'Success: no issues found' not in result:\n        exit(1)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "contrib/admin/mypy-with-ignore.py"}], "after_files": [{"content": "import os\nimport re\nimport sys\nimport textwrap\nimport types\n\nimport pkg_resources\n\nfrom toil.version import version\nfrom typing import Any, Dict\n\ndef main() -> None:\n    modules = loadModules()\n\n    if len(sys.argv) < 2 or sys.argv[1] == '--help':\n        printHelp(modules)\n        sys.exit(0)\n\n    cmd = sys.argv[1]\n    if cmd == '--version':\n        printVersion()\n        sys.exit(0)\n\n    try:\n        module = modules[cmd]\n    except KeyError:\n        sys.stderr.write(f'Unknown option \"{cmd}\".  Pass --help to display usage information.\\n')\n        sys.exit(1)\n\n    del sys.argv[1]\n    get_or_die(module, 'main')()\n\ndef get_or_die(module: types.ModuleType, name: str) -> Any:\n    \"\"\"\n    Get an object from a module or complain that it is missing.\n    \"\"\"\n    if hasattr(module, name):\n        return getattr(module, name)\n    else:\n        sys.stderr.write(f'Internal Toil error!\\nToil utility module '\n                         f'{module.__name__} is missing required attribute {name}\\n')\n        sys.exit(1)\n\ndef loadModules() -> Dict[str, types.ModuleType]:\n    # noinspection PyUnresolvedReferences\n    from toil.utils import (toilClean,\n                            toilDebugFile,\n                            toilDebugJob,\n                            toilDestroyCluster,\n                            toilKill,\n                            toilLaunchCluster,\n                            toilRsyncCluster,\n                            toilSshCluster,\n                            toilStats,\n                            toilStatus)\n    return {\"-\".join([i.lower() for i in re.findall('[A-Z][^A-Z]*', name)]): module for name, module in locals().items()}\n\n\ndef printHelp(modules: Dict[str, types.ModuleType]) -> None:\n    name = os.path.basename(sys.argv[0])\n    descriptions = '\\n        '.join(f'{cmd} - {get_or_die(mod, \"__doc__\").strip()}' for cmd, mod in modules.items() if mod)\n    print(textwrap.dedent(f\"\"\"\n        Usage: {name} COMMAND ...\n               {name} --help\n               {name} COMMAND --help\n\n        Where COMMAND is one of the following:\n\n        {descriptions}\n        \"\"\"[1:]))\n\n\ndef printVersion() -> None:\n    try:\n        print(pkg_resources.get_distribution('toil').version)\n    except:\n        print(f'Version gathered from toil.version: {version}')\n", "path": "src/toil/utils/toilMain.py"}, {"content": "#!/usr/bin/env python3\n\"\"\"\nRuns mypy and ignores files that do not yet have passing type hints.\n\nDoes not type check test files (any path including \"src/toil/test\").\n\"\"\"\nimport os\nimport subprocess\nimport sys\n\nos.environ['MYPYPATH'] = 'contrib/typeshed'\npkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))  # noqa\nsys.path.insert(0, pkg_root)  # noqa\n\nfrom src.toil.lib.resources import glob  # type: ignore\n\n\ndef main():\n    all_files_to_check = []\n    for d in ['dashboard', 'docker', 'docs', 'src']:\n        all_files_to_check += glob(glob_pattern='*.py', directoryname=os.path.join(pkg_root, d))\n\n    # TODO: Remove these paths as typing is added and mypy conflicts are addressed\n    ignore_paths = [os.path.abspath(f) for f in [\n        'docker/Dockerfile.py',\n        'docs/conf.py',\n        'docs/vendor/sphinxcontrib/fulltoc.py',\n        'docs/vendor/sphinxcontrib/__init__.py',\n        'src/toil/job.py',\n        'src/toil/leader.py',\n        'src/toil/statsAndLogging.py',\n        'src/toil/common.py',\n        'src/toil/realtimeLogger.py',\n        'src/toil/worker.py',\n        'src/toil/serviceManager.py',\n        'src/toil/toilState.py',\n        'src/toil/__init__.py',\n        'src/toil/resource.py',\n        'src/toil/deferred.py',\n        'src/toil/version.py',\n        'src/toil/wdl/utils.py',\n        'src/toil/wdl/wdl_types.py',\n        'src/toil/wdl/wdl_synthesis.py',\n        'src/toil/wdl/wdl_analysis.py',\n        'src/toil/wdl/wdl_functions.py',\n        'src/toil/wdl/toilwdl.py',\n        'src/toil/wdl/versions/draft2.py',\n        'src/toil/wdl/versions/v1.py',\n        'src/toil/wdl/versions/dev.py',\n        'src/toil/provisioners/clusterScaler.py',\n        'src/toil/provisioners/abstractProvisioner.py',\n        'src/toil/provisioners/gceProvisioner.py',\n        'src/toil/provisioners/__init__.py',\n        'src/toil/provisioners/node.py',\n        'src/toil/provisioners/aws/boto2Context.py',\n        'src/toil/provisioners/aws/awsProvisioner.py',\n        'src/toil/provisioners/aws/__init__.py',\n        'src/toil/batchSystems/slurm.py',\n        'src/toil/batchSystems/gridengine.py',\n        'src/toil/batchSystems/singleMachine.py',\n        'src/toil/batchSystems/abstractBatchSystem.py',\n        'src/toil/batchSystems/parasol.py',\n        'src/toil/batchSystems/kubernetes.py',\n        'src/toil/batchSystems/torque.py',\n        'src/toil/batchSystems/options.py',\n        'src/toil/batchSystems/registry.py',\n        'src/toil/batchSystems/lsf.py',\n        'src/toil/batchSystems/__init__.py',\n        'src/toil/batchSystems/abstractGridEngineBatchSystem.py',\n        'src/toil/batchSystems/lsfHelper.py',\n        'src/toil/batchSystems/htcondor.py',\n        'src/toil/batchSystems/mesos/batchSystem.py',\n        'src/toil/batchSystems/mesos/executor.py',\n        'src/toil/batchSystems/mesos/conftest.py',\n        'src/toil/batchSystems/mesos/__init__.py',\n        'src/toil/batchSystems/mesos/test/__init__.py',\n        'src/toil/cwl/conftest.py',\n        'src/toil/cwl/__init__.py',\n        'src/toil/cwl/cwltoil.py',\n        'src/toil/fileStores/cachingFileStore.py',\n        'src/toil/fileStores/abstractFileStore.py',\n        'src/toil/fileStores/nonCachingFileStore.py',\n        'src/toil/fileStores/__init__.py',\n        'src/toil/jobStores/utils.py',\n        'src/toil/jobStores/abstractJobStore.py',\n        'src/toil/jobStores/conftest.py',\n        'src/toil/jobStores/fileJobStore.py',\n        'src/toil/jobStores/__init__.py',\n        'src/toil/jobStores/googleJobStore.py',\n        'src/toil/jobStores/aws/utils.py',\n        'src/toil/jobStores/aws/jobStore.py',\n        'src/toil/jobStores/aws/__init__.py',\n        'src/toil/utils/toilDebugFile.py',\n        'src/toil/utils/toilStatus.py',\n        'src/toil/utils/toilStats.py',\n        'src/toil/utils/__init__.py',\n        'src/toil/utils/toilLaunchCluster.py',\n        'src/toil/lib/memoize.py',\n        'src/toil/lib/throttle.py',\n        'src/toil/lib/humanize.py',\n        'src/toil/lib/compatibility.py',\n        'src/toil/lib/iterables.py',\n        'src/toil/lib/bioio.py',\n        'src/toil/lib/ec2.py',\n        'src/toil/lib/ec2nodes.py',\n        'src/toil/lib/expando.py',\n        'src/toil/lib/threading.py',\n        'src/toil/lib/exceptions.py',\n        'src/toil/lib/__init__.py',\n        'src/toil/lib/generatedEC2Lists.py',\n        'src/toil/lib/retry.py',\n        'src/toil/lib/objects.py',\n        'src/toil/lib/io.py',\n        'src/toil/lib/docker.py',\n        # 'src/toil/lib/encryption/_nacl.py',\n        'src/toil/lib/encryption/_dummy.py',\n        'src/toil/lib/encryption/conftest.py',\n        'src/toil/lib/encryption/__init__.py',\n        'src/toil/lib/aws/utils.py',\n        'src/toil/lib/aws/__init__.py'\n    ]]\n\n    filtered_files_to_check = []\n    for file_path in all_files_to_check:\n        if file_path not in ignore_paths and 'src/toil/test' not in file_path:\n            filtered_files_to_check.append(file_path)\n    # follow-imports type checks pypi projects we don't control, so we skip it; why is this their default?\n    args = ['mypy', '--follow-imports=skip'] + filtered_files_to_check\n    p = subprocess.run(args=args, stdout=subprocess.PIPE)\n    result = p.stdout.decode()\n    print(result)\n    if 'Success: no issues found' not in result:\n        exit(1)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "contrib/admin/mypy-with-ignore.py"}]}