1212import pkgconfig
1313from dataclasses import dataclass , field
1414from setuptools import setup , find_packages , Extension
15+ from setuptools .command .sdist import sdist as _sdist
1516from glob import glob
1617from pathlib import Path
1718from Cython .Build import cythonize
@@ -236,7 +237,9 @@ def extensions():
236237
237238
238239# TODO: It would be good to have a single source of truth for these files
239- FIREDRAKE_CHECK_TEST_FILES = (
240+ FIREDRAKE_CHECK_FILES = (
241+ "Makefile" ,
242+ "tests/firedrake/conftest.py" ,
240243 "tests/firedrake/regression/test_stokes_mini.py" ,
241244 "tests/firedrake/regression/test_locate_cell.py" ,
242245 "tests/firedrake/supermesh/test_assemble_mixed_mass_matrix.py" ,
@@ -247,46 +250,21 @@ def extensions():
247250)
248251
249252
250- # This diabolical function is needed to allow 'firedrake-check' to work. Since
251- # installed packages are not allowed to contain files from outside that Python
252- # package we cannot access the Makefile or test files once installation is
253- # complete. Therefore, before we install, we create a dummy package, called
254- # 'firedrake-check' containing said Makefile and tests.
255- def make_firedrake_check_package ():
256- package_dir = "firedrake_check"
257- logging .info (f"Creating '{ package_dir } ' package" )
258- if os .path .exists (package_dir ):
259- logging .info (f"'{ package_dir } ' already found, removing" )
260- shutil .rmtree (package_dir )
253+ class sdist (_sdist ):
254+ def run (self ):
255+ self ._copy_check_files ()
256+ super ().run ()
261257
262- os .mkdir (package_dir )
263- with open (f"{ package_dir } /__init__.py" , "w" ) as f :
264- # set 'errors=True' to make sure that we propagate failures to the
265- # outer process
266- f .write ("""import pathlib
267- import subprocess
268-
269- def main():
270- dir = pathlib.Path(__file__).parent
271- subprocess.run(f'make -C {dir} check'.split(), errors=True)
272- """ )
273-
274- # copy Makefile and tests into dummy package
275- shutil .copy ("Makefile" , package_dir )
276- for test_file in FIREDRAKE_CHECK_TEST_FILES :
277- package_test_dir = os .path .join (package_dir , Path (test_file ).parent )
278- os .makedirs (package_test_dir , exist_ok = True )
279- shutil .copy (test_file , package_test_dir )
280-
281- # Also copy conftest.py so any markers are recognised
282- conftest_dir = os .path .join (package_dir , "tests" , "firedrake" )
283- shutil .copy ("tests/firedrake/conftest.py" , conftest_dir )
284-
285-
286- make_firedrake_check_package ()
258+ def _copy_check_files (self ):
259+ """Copy Makefile and tests into firedrake/_check."""
260+ dest_dir = Path ("firedrake/_check" )
261+ for check_file in map (Path , FIREDRAKE_CHECK_FILES ):
262+ os .makedirs (dest_dir / check_file .parent , exist_ok = True )
263+ shutil .copy (check_file , dest_dir / check_file .parent )
287264
288265
289266setup (
267+ cmdclass = {"sdist" : sdist },
290268 packages = find_packages (),
291- ext_modules = extensions ()
269+ ext_modules = extensions (),
292270)
0 commit comments