|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Setup for the reference implementation of the CWL standards.""" |
| 3 | +import glob |
3 | 4 | import os |
4 | 5 | import sys |
5 | 6 | import warnings |
| 7 | +from typing import TYPE_CHECKING, Any |
6 | 8 |
|
7 | | -from setuptools import setup |
| 9 | +from setuptools import Extension, setup |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from typing_extensions import TypeGuard |
8 | 13 |
|
9 | 14 | if os.name == "nt": |
10 | 15 | warnings.warn( |
|
20 | 25 | stacklevel=1, |
21 | 26 | ) |
22 | 27 |
|
| 28 | + |
| 29 | +def _is_list_of_setuptools_extension(items: list[Any]) -> "TypeGuard[list[Extension]]": |
| 30 | + return all(isinstance(item, Extension) for item in items) |
| 31 | + |
| 32 | + |
| 33 | +def _find_package_data(base: str, globs: list[str], root: str = "cwltool") -> list[str]: |
| 34 | + """ |
| 35 | + Find all interesting data files, for setup(package_data=). |
| 36 | +
|
| 37 | + Arguments: |
| 38 | + root: The directory to search in. |
| 39 | + globs: A list of glob patterns to accept files. |
| 40 | + """ |
| 41 | + rv_dirs = [root for root, dirs, files in os.walk(base)] |
| 42 | + rv = [] |
| 43 | + for rv_dir in rv_dirs: |
| 44 | + files = [] |
| 45 | + for pat in globs: |
| 46 | + files += glob.glob(os.path.join(rv_dir, pat)) |
| 47 | + if not files: |
| 48 | + continue |
| 49 | + rv.extend([os.path.relpath(f, root) for f in files]) |
| 50 | + return rv |
| 51 | + |
| 52 | + |
23 | 53 | SETUP_DIR = os.path.dirname(__file__) |
24 | 54 | README = os.path.join(SETUP_DIR, "README.rst") |
25 | 55 |
|
|
34 | 64 | USE_MYPYC = True |
35 | 65 |
|
36 | 66 | if USE_MYPYC: |
37 | | - mypyc_targets = [ |
38 | | - "cwltool/argparser.py", |
39 | | - "cwltool/builder.py", |
40 | | - "cwltool/checker.py", |
41 | | - "cwltool/command_line_tool.py", |
42 | | - # "cwltool/context.py", # monkeypatching |
43 | | - "cwltool/cwlrdf.py", |
44 | | - "cwltool/docker_id.py", |
45 | | - "cwltool/docker.py", |
46 | | - "cwltool/udocker.py", |
47 | | - "cwltool/errors.py", |
48 | | - "cwltool/executors.py", |
49 | | - "cwltool/factory.py", |
50 | | - "cwltool/flatten.py", |
51 | | - # "cwltool/__init__.py", |
52 | | - "cwltool/job.py", |
53 | | - "cwltool/load_tool.py", |
54 | | - # "cwltool/loghandler.py", # so we can monkeypatch the logger from tests |
55 | | - # "cwltool/__main__.py", |
56 | | - "cwltool/main.py", |
57 | | - "cwltool/mutation.py", |
58 | | - "cwltool/pack.py", |
59 | | - "cwltool/pathmapper.py", |
60 | | - "cwltool/process.py", |
61 | | - "cwltool/procgenerator.py", |
62 | | - # "cwltool/cwlprov/__init__.py", |
63 | | - "cwltool/cwlprov/provenance_constants.py", |
64 | | - "cwltool/cwlprov/provenance_profile.py", |
65 | | - "cwltool/cwlprov/ro.py", |
66 | | - # "cwltool/cwlprov/writablebagfile.py", # WritableBag is having issues |
67 | | - "cwltool/resolver.py", |
68 | | - "cwltool/secrets.py", |
69 | | - "cwltool/singularity.py", |
70 | | - "cwltool/software_requirements.py", |
71 | | - # "cwltool/stdfsaccess.py", # StdFsAccess needs to be subclassable |
72 | | - "cwltool/subgraph.py", |
73 | | - "cwltool/update.py", |
74 | | - "cwltool/utils.py", |
75 | | - "cwltool/validate_js.py", |
76 | | - "cwltool/workflow.py", |
| 67 | + mypyc_skiplist = tuple( |
| 68 | + os.path.join("cwltool", x) |
| 69 | + for x in ( |
| 70 | + "context.py", # monkeypatching |
| 71 | + "__init__.py", |
| 72 | + "loghandler.py", # so we can monkeypatch the logger from tests |
| 73 | + "__main__.py", |
| 74 | + "cwlprov/__init__.py", |
| 75 | + "cuda.py", # for monkeypatch |
| 76 | + "run_job.py", |
| 77 | + "cwlprov/writablebagfile.py", # WritableBag is having issues |
| 78 | + "stdfsaccess.py", # StdFsAccess needs to be subclassable |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + everything = [os.path.join("cwltool", x) for x in _find_package_data("cwltool", ["*.py"])] |
| 83 | + # Start with all the .py files |
| 84 | + all_real_pys = [ |
| 85 | + x for x in everything if not x.startswith(os.path.join("mypy", "typeshed") + os.sep) |
77 | 86 | ] |
| 87 | + # Strip out anything in our skiplist |
| 88 | + mypyc_targets = [x for x in all_real_pys if x not in mypyc_skiplist] |
| 89 | + |
| 90 | + # Strip out any test code |
| 91 | + mypyc_targets = [x for x in mypyc_targets if not x.startswith(("tests" + os.sep))] |
78 | 92 |
|
79 | | - from mypyc.build import mypycify # type: ignore[import-untyped] |
| 93 | + mypyc_targets.sort() |
| 94 | + |
| 95 | + from mypyc.build import mypycify |
80 | 96 |
|
81 | 97 | opt_level = os.getenv("MYPYC_OPT_LEVEL", "3") |
82 | | - ext_modules = mypycify(mypyc_targets, opt_level=opt_level) |
| 98 | + debug_level = os.getenv("MYPYC_DEBUG_LEVEL", "1") |
| 99 | + force_multifile = os.getenv("MYPYC_MULTI_FILE", "") == "1" |
| 100 | + ext_modules = mypycify( |
| 101 | + mypyc_targets, |
| 102 | + opt_level=opt_level, |
| 103 | + debug_level=debug_level, |
| 104 | + multi_file=force_multifile, |
| 105 | + ) |
83 | 106 | else: |
84 | 107 | ext_modules = [] |
85 | 108 |
|
| 109 | +assert _is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools" |
| 110 | + |
86 | 111 | setup( |
87 | 112 | name="cwltool", |
88 | 113 | description="Common workflow language reference implementation", |
|
0 commit comments