|
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 | + "cwlprov/writablebagfile.py", # WritableBag is having issues |
| 76 | + "stdfsaccess.py", # StdFsAccess needs to be subclassable |
| 77 | + ) |
| 78 | + ) |
| 79 | + |
| 80 | + everything = [os.path.join("cwltool", x) for x in _find_package_data("cwltool", ["*.py"])] |
| 81 | + # Start with all the .py files |
| 82 | + all_real_pys = [ |
| 83 | + x for x in everything if not x.startswith(os.path.join("mypy", "typeshed") + os.sep) |
77 | 84 | ]
|
| 85 | + # Strip out anything in our skiplist |
| 86 | + mypyc_targets = [x for x in all_real_pys if x not in mypyc_skiplist] |
| 87 | + |
| 88 | + # Strip out any test code |
| 89 | + mypyc_targets = [x for x in mypyc_targets if not x.startswith(("tests" + os.sep))] |
78 | 90 |
|
79 |
| - from mypyc.build import mypycify # type: ignore[import-untyped] |
| 91 | + mypyc_targets.sort() |
| 92 | + |
| 93 | + from mypyc.build import mypycify |
80 | 94 |
|
81 | 95 | opt_level = os.getenv("MYPYC_OPT_LEVEL", "3")
|
82 |
| - ext_modules = mypycify(mypyc_targets, opt_level=opt_level) |
| 96 | + debug_level = os.getenv("MYPYC_DEBUG_LEVEL", "1") |
| 97 | + force_multifile = os.getenv("MYPYC_MULTI_FILE", "") == "1" |
| 98 | + ext_modules = mypycify( |
| 99 | + mypyc_targets, |
| 100 | + opt_level=opt_level, |
| 101 | + debug_level=debug_level, |
| 102 | + multi_file=force_multifile, |
| 103 | + ) |
83 | 104 | else:
|
84 | 105 | ext_modules = []
|
85 | 106 |
|
| 107 | +assert _is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools" |
| 108 | + |
86 | 109 | setup(
|
87 | 110 | name="cwltool",
|
88 | 111 | description="Common workflow language reference implementation",
|
|
0 commit comments