10
10
wheel test environment and to run the appropriate tests.
11
11
12
12
CLI Commands
13
- - pull-deps [PROJECT_DIR]: when testing parallel targets, installs
14
- the serial stringzilla into the test venv, and ensures test-only
13
+ - pull-deps [PROJECT_DIR]: when testing parallel targets, installs
14
+ the serial stringzilla into the test venv, and ensures test-only
15
15
deps (NumPy, affine-gaps) are present.
16
16
- run-tests [PROJECT_DIR]: runs scripts/test_stringzilla.py and,
17
17
for parallel targets, also runs scripts/test_stringzillas.py.
@@ -30,15 +30,21 @@ def _build_meta():
30
30
return _orig_build_meta
31
31
32
32
33
+ def _detect_target () -> str :
34
+ t = os .environ .get ("SZ_TARGET" )
35
+ if t :
36
+ return t
37
+ try :
38
+ return Path ("SZ_TARGET.env" ).read_text (encoding = "utf-8" ).strip () or "stringzilla"
39
+ except FileNotFoundError :
40
+ return "stringzilla"
41
+
42
+
33
43
def get_requires_for_build_wheel (config_settings = None ):
34
44
"""Get build requirements, conditionally including numpy."""
35
45
requirements = _build_meta ().get_requires_for_build_wheel (config_settings )
36
-
37
- # Add NumPy for variants that need it
38
- sz_target = os .environ .get ("SZ_TARGET" , "stringzilla" )
39
- if sz_target in ("stringzillas-cpus" , "stringzillas-cuda" ):
46
+ if _detect_target () in ("stringzillas-cpus" , "stringzillas-cuda" ):
40
47
requirements .append ("numpy" )
41
-
42
48
return requirements
43
49
44
50
@@ -51,8 +57,7 @@ def get_requires_for_build_editable(config_settings=None):
51
57
else :
52
58
requirements = bm .get_requires_for_build_wheel (config_settings )
53
59
54
- sz_target = os .environ .get ("SZ_TARGET" , "stringzilla" )
55
- if sz_target in ("stringzillas-cpus" , "stringzillas-cuda" ):
60
+ if _detect_target () in ("stringzillas-cpus" , "stringzillas-cuda" ):
56
61
requirements .append ("numpy" )
57
62
return requirements
58
63
@@ -68,8 +73,21 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
68
73
69
74
70
75
def build_sdist (sdist_directory , config_settings = None ):
71
- """Build source distribution."""
72
- return _build_meta ().build_sdist (sdist_directory , config_settings )
76
+ """Build source distribution and embed SZ_TARGET.env for installs from sdist."""
77
+ target = os .environ .get ("SZ_TARGET" , "stringzilla" )
78
+ marker_path = Path ("SZ_TARGET.env" )
79
+ created = False
80
+ try :
81
+ if not marker_path .exists ():
82
+ marker_path .write_text (f"{ target } \n " , encoding = "utf-8" )
83
+ created = True
84
+ return _build_meta ().build_sdist (sdist_directory , config_settings )
85
+ finally :
86
+ if created and marker_path .exists ():
87
+ try :
88
+ marker_path .unlink ()
89
+ except OSError :
90
+ pass
73
91
74
92
75
93
def prepare_metadata_for_build_wheel (metadata_directory , config_settings = None ):
@@ -83,7 +101,7 @@ def prepare_metadata_for_build_editable(metadata_directory, config_settings=None
83
101
if hasattr (bm , "prepare_metadata_for_build_editable" ):
84
102
return bm .prepare_metadata_for_build_editable (metadata_directory , config_settings )
85
103
raise RuntimeError (
86
- "Editable installs require setuptools with PEP 660 support. "
104
+ "Editable installs require setuptools with PEP 660 support. " #
87
105
"Please upgrade setuptools (setuptools>=61)."
88
106
)
89
107
@@ -94,7 +112,7 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
94
112
if hasattr (bm , "build_editable" ):
95
113
return bm .build_editable (wheel_directory , config_settings , metadata_directory )
96
114
raise RuntimeError (
97
- "Editable installs require setuptools with PEP 660 support. "
115
+ "Editable installs require setuptools with PEP 660 support. " #
98
116
"Please upgrade setuptools (setuptools>=61)."
99
117
)
100
118
@@ -103,9 +121,28 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
103
121
# CLI utilities for cibuildwheel
104
122
# ------------------------------
105
123
124
+
106
125
def _is_parallel_target () -> bool :
107
- t = os .environ .get ("SZ_TARGET" , "stringzilla" )
108
- return t in ("stringzillas-cpus" , "stringzillas-cuda" )
126
+ return _detect_target () in ("stringzillas-cpus" , "stringzillas-cuda" )
127
+
128
+
129
+ def _build_sdist_for (target : str , outdir : str = "dist" ) -> None :
130
+ """Build a single sdist with the provided SZ_TARGET value."""
131
+ env = os .environ .copy ()
132
+ env ["SZ_TARGET" ] = target
133
+ subprocess .check_call ([sys .executable , "-m" , "build" , "--sdist" , "--outdir" , outdir ], env = env )
134
+
135
+
136
+ def cli_build_sdists (outdir : str = "dist" ) -> None :
137
+ """Build sdists for stringzilla, stringzillas-cpus, stringzillas-cuda.
138
+
139
+ Ensures the PKG-INFO Name matches the intended PyPI package by setting
140
+ SZ_TARGET for each build. Outputs to the provided directory (default: dist).
141
+ """
142
+ Path (outdir ).mkdir (exist_ok = True )
143
+ for target in ("stringzilla" , "stringzillas-cpus" , "stringzillas-cuda" ):
144
+ print (f"Building sdist for target: { target } " )
145
+ _build_sdist_for (target , outdir )
109
146
110
147
111
148
def cli_prepare_tests (project_dir : Optional [str ] = None ) -> None :
@@ -156,13 +193,19 @@ def _main(argv: List[str]) -> int:
156
193
parser_run = sub .add_parser ("run-tests" , help = "Run StringZilla test suites" )
157
194
parser_run .add_argument ("project_dir" , nargs = "?" , default = "." )
158
195
196
+ parser_sdists = sub .add_parser ("build-sdists" , help = "Build sdists for all targets with correct metadata" )
197
+ parser_sdists .add_argument ("--outdir" , default = "dist" , help = "Output directory for sdists (default: dist)" )
198
+
159
199
namespace = parser .parse_args (argv )
160
200
if namespace .cmd == "pull-deps" :
161
201
cli_prepare_tests (namespace .project_dir )
162
202
return 0
163
203
if namespace .cmd == "run-tests" :
164
204
cli_run_tests (namespace .project_dir )
165
205
return 0
206
+ if namespace .cmd == "build-sdists" :
207
+ cli_build_sdists (namespace .outdir )
208
+ return 0
166
209
return 2
167
210
168
211
0 commit comments