66from pathlib import Path
77
88import pytest
9- from conftest import PackageInfo , VEnv , process_package
9+ from conftest import PackageInfo , process_package
1010
1111
1212@pytest .mark .compile
1313@pytest .mark .configure
1414@pytest .mark .integration
15- @pytest .mark .parametrize ("isolate" , [True , False ], ids = ["isolated" , "notisolated" ])
1615@pytest .mark .parametrize (
1716 "py_pkg" ,
1817 [
3029 sys .version_info [:2 ] == (3 , 9 ), reason = "Python 3.9 not supported yet"
3130)
3231def test_navigate_editable (isolated , isolate , py_pkg ):
33- isolate_args = ["--no-build-isolation" ] if not isolate else []
34- isolated .install ("pip>=23" )
35- if not isolate :
36- isolated .install ("scikit-build-core" )
37-
3832 if py_pkg :
3933 init_py = Path ("python/shared_pkg/data/__init__.py" )
4034 init_py .touch ()
4135
4236 isolated .install (
43- "-v" , "--config-settings=build-dir=build/{wheel_tag}" , * isolate_args , "-e" , "."
37+ "-v" , "--config-settings=build-dir=build/{wheel_tag}" , * isolate . flags , "-e" , "."
4438 )
4539
4640 value = isolated .execute ("import shared_pkg; shared_pkg.call_c_method()" )
@@ -59,17 +53,9 @@ def test_navigate_editable(isolated, isolate, py_pkg):
5953@pytest .mark .compile
6054@pytest .mark .configure
6155@pytest .mark .integration
62- @pytest .mark .parametrize (
63- ("editable" , "editable_mode" ), [(False , "" ), (True , "redirect" ), (True , "inplace" )]
64- )
65- def test_cython_pxd (monkeypatch , tmp_path , editable , editable_mode , isolated ):
66- editable_flag = ["-e" ] if editable else []
67-
68- config_mode_flags = []
69- if editable :
70- config_mode_flags .append (f"--config-settings=editable.mode={ editable_mode } " )
71- if editable_mode != "inplace" :
72- config_mode_flags .append ("--config-settings=build-dir=build/{wheel_tag}" )
56+ @pytest .mark .parametrize ("isolate" , {False }, indirect = True )
57+ def test_cython_pxd (monkeypatch , tmp_path , editable , isolated , isolate ):
58+ isolated .install ("cython" )
7359
7460 package1 = PackageInfo (
7561 "cython_pxd_editable/pkg1" ,
@@ -78,21 +64,10 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
7864 tmp_path1 .mkdir ()
7965 process_package (package1 , tmp_path1 , monkeypatch )
8066
81- ninja = [
82- "ninja" for f in isolated .wheelhouse .iterdir () if f .name .startswith ("ninja-" )
83- ]
84- cmake = [
85- "cmake" for f in isolated .wheelhouse .iterdir () if f .name .startswith ("cmake-" )
86- ]
87-
88- isolated .install ("pip>23" )
89- isolated .install ("cython" , "scikit-build-core" , * ninja , * cmake )
90-
9167 isolated .install (
9268 "-v" ,
93- * config_mode_flags ,
94- "--no-build-isolation" ,
95- * editable_flag ,
69+ * isolate .flags ,
70+ * editable .flags ,
9671 "." ,
9772 )
9873
@@ -105,9 +80,8 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
10580
10681 isolated .install (
10782 "-v" ,
108- * config_mode_flags ,
109- "--no-build-isolation" ,
110- * editable_flag ,
83+ * isolate .flags ,
84+ * editable .flags ,
11185 "." ,
11286 )
11387
@@ -118,9 +92,6 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
11892@pytest .mark .parametrize ("package" , {"simplest_c" }, indirect = True )
11993@pytest .mark .usefixtures ("package" )
12094def test_install_dir (isolated ):
121- isolated .install ("pip>=23" )
122- isolated .install ("scikit-build-core" )
123-
12495 settings_overrides = {
12596 "build-dir" : "build/{wheel_tag}" ,
12697 "wheel.install-dir" : "other_pkg" ,
@@ -141,7 +112,6 @@ def test_install_dir(isolated):
141112 isolated .install (
142113 "-v" ,
143114 * [f"--config-settings={ k } ={ v } " for k , v in settings_overrides .items ()],
144- "--no-build-isolation" ,
145115 "-e" ,
146116 "." ,
147117 )
@@ -163,67 +133,25 @@ def test_install_dir(isolated):
163133 assert not failed_c_module .exists ()
164134
165135
166- def _setup_package_for_editable_layout_tests (
167- monkeypatch : pytest .MonkeyPatch ,
168- tmp_path : Path ,
169- editable : bool ,
170- editable_mode : str ,
171- isolated : VEnv ,
172- ) -> None :
173- editable_flag = ["-e" ] if editable else []
174-
175- config_mode_flags = []
176- if editable :
177- config_mode_flags .append (f"--config-settings=editable.mode={ editable_mode } " )
178- if editable_mode != "inplace" :
179- config_mode_flags .append ("--config-settings=build-dir=build/{wheel_tag}" )
180-
181- # Use a context so that we only change into the directory up until the point where
182- # we run the editable install. We do not want to be in that directory when importing
183- # to avoid importing the source directory instead of the installed package.
184- with monkeypatch .context () as m :
185- package = PackageInfo ("importlib_editable" )
186- process_package (package , tmp_path , m )
187-
188- assert isolated .wheelhouse
189-
190- ninja = [
191- "ninja"
192- for f in isolated .wheelhouse .iterdir ()
193- if f .name .startswith ("ninja-" )
194- ]
195- cmake = [
196- "cmake"
197- for f in isolated .wheelhouse .iterdir ()
198- if f .name .startswith ("cmake-" )
199- ]
200-
201- isolated .install ("pip>23" )
202- isolated .install ("scikit-build-core" , * ninja , * cmake )
203-
204- isolated .install (
205- "-v" ,
206- * config_mode_flags ,
207- "--no-build-isolation" ,
208- * editable_flag ,
209- "." ,
210- )
211-
212-
213136@pytest .mark .compile
214137@pytest .mark .configure
215138@pytest .mark .integration
216- @pytest .mark .parametrize (
217- ("editable" , "editable_mode" ), [(False , "" ), (True , "redirect" ), (True , "inplace" )]
218- )
219- def test_direct_import (monkeypatch , tmp_path , editable , editable_mode , isolated ):
139+ @pytest .mark .parametrize ("package" , {"importlib_editable" }, indirect = True )
140+ @pytest .mark .usefixtures ("package" )
141+ def test_direct_import (editable , isolated , monkeypatch , tmp_path ):
220142 # TODO: Investigate these failures
221- if platform .system () == "Windows" and editable_mode == "inplace" :
143+ if platform .system () == "Windows" and editable . mode == "inplace" :
222144 pytest .xfail ("Windows fails to import the top-level extension module" )
223145
224- _setup_package_for_editable_layout_tests (
225- monkeypatch , tmp_path , editable , editable_mode , isolated
146+ isolated .install (
147+ "-v" ,
148+ * editable .flags ,
149+ "." ,
226150 )
151+
152+ # Exit the package path before execution
153+ # TODO: Use src-layout instead
154+ monkeypatch .chdir (tmp_path )
227155 isolated .execute ("import pkg" )
228156 isolated .execute ("import pmod" )
229157 isolated .execute ("import emod" )
@@ -232,32 +160,27 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated)
232160@pytest .mark .compile
233161@pytest .mark .configure
234162@pytest .mark .integration
235- @pytest .mark .parametrize (
236- ("editable" , "editable_mode" ),
237- [
238- (False , "" ),
239- pytest .param (
240- True ,
241- "redirect" ,
242- marks = pytest .mark .xfail ,
243- ),
244- (True , "inplace" ),
245- ],
246- )
247- def test_importlib_resources (monkeypatch , tmp_path , editable , editable_mode , isolated ):
163+ @pytest .mark .parametrize ("package" , {"importlib_editable" }, indirect = True )
164+ @pytest .mark .usefixtures ("package" )
165+ def test_importlib_resources (editable , isolated , monkeypatch , tmp_path ):
248166 if sys .version_info < (3 , 9 ):
249167 pytest .skip ("importlib.resources.files is introduced in Python 3.9" )
250168
251169 # TODO: Investigate these failures
252- if editable_mode == "redirect" :
170+ if editable . mode == "redirect" :
253171 pytest .xfail ("Redirect mode is at navigating importlib.resources.files" )
254- if platform .system () == "Windows" and editable_mode == "inplace" :
172+ if platform .system () == "Windows" and editable . mode == "inplace" :
255173 pytest .xfail ("Windows fails to import the top-level extension module" )
256174
257- _setup_package_for_editable_layout_tests (
258- monkeypatch , tmp_path , editable , editable_mode , isolated
175+ isolated .install (
176+ "-v" ,
177+ * editable .flags ,
178+ "." ,
259179 )
260180
181+ # Exit the package path before execution
182+ # TODO: Use src-layout instead
183+ monkeypatch .chdir (tmp_path )
261184 isolated .execute (
262185 textwrap .dedent (
263186 """
0 commit comments