Skip to content

Commit 4b3b945

Browse files
committed
setup.py: modernize use of mypycify; switch to skiplist
1 parent 647713b commit 4b3b945

File tree

1 file changed

+66
-43
lines changed

1 file changed

+66
-43
lines changed

setup.py

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/usr/bin/env python3
22
"""Setup for the reference implementation of the CWL standards."""
3+
import glob
34
import os
45
import sys
56
import warnings
7+
from typing import TYPE_CHECKING, Any
68

7-
from setuptools import setup
9+
from setuptools import Extension, setup
10+
11+
if TYPE_CHECKING:
12+
from typing_extensions import TypeGuard
813

914
if os.name == "nt":
1015
warnings.warn(
@@ -20,6 +25,31 @@
2025
stacklevel=1,
2126
)
2227

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+
2353
SETUP_DIR = os.path.dirname(__file__)
2454
README = os.path.join(SETUP_DIR, "README.rst")
2555

@@ -34,55 +64,48 @@
3464
USE_MYPYC = True
3565

3666
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)
7784
]
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))]
7890

79-
from mypyc.build import mypycify # type: ignore[import-untyped]
91+
mypyc_targets.sort()
92+
93+
from mypyc.build import mypycify
8094

8195
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+
)
83104
else:
84105
ext_modules = []
85106

107+
assert _is_list_of_setuptools_extension(ext_modules), "Expected mypycify to use setuptools"
108+
86109
setup(
87110
name="cwltool",
88111
description="Common workflow language reference implementation",

0 commit comments

Comments
 (0)