@@ -489,30 +489,33 @@ def _wheel_write_metadata(self, whl: mesonpy._wheelfile.WheelFile) -> None:
489
489
def build (self , directory : Path ) -> pathlib .Path :
490
490
# ensure project is built
491
491
self ._project .build ()
492
- # install the project
493
- self ._project .install ()
494
492
495
- wheel_file = pathlib . Path ( directory , f' { self . name } .whl' )
496
- with mesonpy . _wheelfile . WheelFile ( wheel_file , 'w' ) as whl :
497
- self ._wheel_write_metadata ( whl )
493
+ # install project in temporary destination directory
494
+ with tempfile . TemporaryDirectory ( ) as destdir :
495
+ self ._project . install ( destdir )
498
496
499
- with mesonpy . _util . cli_counter ( sum ( len ( x ) for x in self ._wheel_files . values ())) as counter :
497
+ wheel_file = pathlib . Path ( directory , f' { self .name } .whl' )
500
498
501
- root = 'purelib' if self .is_pure else 'platlib'
499
+ with mesonpy ._wheelfile .WheelFile (wheel_file , 'w' ) as whl :
500
+ self ._wheel_write_metadata (whl )
502
501
503
- for path , entries in self ._wheel_files .items ():
504
- for dst , src in entries :
505
- counter .update (src )
502
+ with mesonpy ._util .cli_counter (sum (len (x ) for x in self ._wheel_files .values ())) as counter :
506
503
507
- if path == root :
508
- pass
509
- elif path == 'mesonpy-libs' :
510
- # custom installation path for bundled libraries
511
- dst = pathlib .Path (f'.{ self ._project .name } .mesonpy.libs' , dst )
512
- else :
513
- dst = pathlib .Path (self .data_dir , path , dst )
504
+ root = 'purelib' if self .is_pure else 'platlib'
505
+
506
+ for path , entries in self ._wheel_files .items ():
507
+ for dst , src in entries :
508
+ counter .update (src )
514
509
515
- self ._install_path (whl , src , dst )
510
+ if path == root :
511
+ pass
512
+ elif path == 'mesonpy-libs' :
513
+ # custom installation path for bundled libraries
514
+ dst = pathlib .Path (f'.{ self ._project .name } .mesonpy.libs' , dst )
515
+ else :
516
+ dst = pathlib .Path (self .data_dir , path , dst )
517
+
518
+ self ._install_path (whl , src , dst )
516
519
517
520
return wheel_file
518
521
@@ -628,16 +631,13 @@ class Project():
628
631
def __init__ (
629
632
self ,
630
633
source_dir : Path ,
631
- working_dir : Path ,
632
- build_dir : Optional [Path ] = None ,
634
+ build_dir : Path ,
633
635
meson_args : Optional [MesonArgs ] = None ,
634
636
editable_verbose : bool = False ,
635
637
) -> None :
636
638
self ._source_dir = pathlib .Path (source_dir ).absolute ()
637
- self ._working_dir = pathlib .Path (working_dir ).absolute ()
638
- self ._build_dir = pathlib .Path (build_dir ).absolute () if build_dir else (self ._working_dir / 'build' )
639
+ self ._build_dir = pathlib .Path (build_dir ).absolute ()
639
640
self ._editable_verbose = editable_verbose
640
- self ._install_dir = self ._working_dir / 'install'
641
641
self ._meson_native_file = self ._build_dir / 'meson-python-native-file.ini'
642
642
self ._meson_cross_file = self ._build_dir / 'meson-python-cross-file.ini'
643
643
self ._meson_args : MesonArgs = collections .defaultdict (list )
@@ -651,7 +651,6 @@ def __init__(
651
651
652
652
# make sure the build dir exists
653
653
self ._build_dir .mkdir (exist_ok = True , parents = True )
654
- self ._install_dir .mkdir (exist_ok = True , parents = True )
655
654
656
655
# setuptools-like ARCHFLAGS environment variable support
657
656
if sysconfig .get_platform ().startswith ('macosx-' ):
@@ -805,24 +804,11 @@ def build(self) -> None:
805
804
"""Build the Meson project."""
806
805
self ._run (self ._build_command )
807
806
808
- def install (self ) -> None :
807
+ def install (self , destdir : Path ) -> None :
809
808
"""Install the Meson project."""
810
- destdir = os .fspath (self . _install_dir )
809
+ destdir = os .fspath (destdir )
811
810
self ._run (['meson' , 'install' , '--quiet' , '--no-rebuild' , '--destdir' , destdir , * self ._meson_args ['install' ]])
812
811
813
- @classmethod
814
- @contextlib .contextmanager
815
- def with_temp_working_dir (
816
- cls ,
817
- source_dir : Path = os .path .curdir ,
818
- build_dir : Optional [Path ] = None ,
819
- meson_args : Optional [MesonArgs ] = None ,
820
- editable_verbose : bool = False ,
821
- ) -> Iterator [Project ]:
822
- """Creates a project instance pointing to a temporary working directory."""
823
- with tempfile .TemporaryDirectory (prefix = '.mesonpy-' , dir = os .fspath (source_dir )) as tmpdir :
824
- yield cls (source_dir , tmpdir , build_dir , meson_args , editable_verbose )
825
-
826
812
@functools .lru_cache ()
827
813
def _info (self , name : str ) -> Dict [str , Any ]:
828
814
"""Read info from meson-info directory."""
@@ -974,18 +960,19 @@ def editable(self, directory: Path) -> pathlib.Path:
974
960
975
961
976
962
@contextlib .contextmanager
977
- def _project (config_settings : Optional [Dict [Any , Any ]]) -> Iterator [Project ]:
963
+ def _project (config_settings : Optional [Dict [Any , Any ]] = None ) -> Iterator [Project ]:
978
964
"""Create the project given the given config settings."""
979
965
980
966
settings = _validate_config_settings (config_settings or {})
981
- meson_args = {name : settings .get (f'{ name } -args' , []) for name in _MESON_ARGS_KEYS }
982
-
983
- with Project .with_temp_working_dir (
984
- build_dir = settings .get ('builddir' ),
985
- meson_args = typing .cast (MesonArgs , meson_args ),
986
- editable_verbose = bool (settings .get ('editable-verbose' ))
987
- ) as project :
988
- yield project
967
+ meson_args = typing .cast (MesonArgs , {name : settings .get (f'{ name } -args' , []) for name in _MESON_ARGS_KEYS })
968
+ source_dir = os .path .curdir
969
+ build_dir = settings .get ('builddir' )
970
+ editable_verbose = bool (settings .get ('editable-verbose' ))
971
+
972
+ with contextlib .ExitStack () as ctx :
973
+ if build_dir is None :
974
+ build_dir = ctx .enter_context (tempfile .TemporaryDirectory (prefix = '.mesonpy-' , dir = source_dir ))
975
+ yield Project (source_dir , build_dir , meson_args , editable_verbose )
989
976
990
977
991
978
def _parse_version_string (string : str ) -> Tuple [int , ...]:
0 commit comments