@@ -498,30 +498,33 @@ def _wheel_write_metadata(self, whl: mesonpy._wheelfile.WheelFile) -> None:
498
498
def build (self , directory : Path ) -> pathlib .Path :
499
499
# ensure project is built
500
500
self ._project .build ()
501
- # install the project
502
- self ._project .install ()
503
501
504
- wheel_file = pathlib . Path ( directory , f' { self . name } .whl' )
505
- with mesonpy . _wheelfile . WheelFile ( wheel_file , 'w' ) as whl :
506
- self ._wheel_write_metadata ( whl )
502
+ # install project in temporary destination directory
503
+ with tempfile . TemporaryDirectory ( ) as destdir :
504
+ self ._project . install ( destdir )
507
505
508
- with mesonpy . _util . cli_counter ( sum ( len ( x ) for x in self ._wheel_files . values ())) as counter :
506
+ wheel_file = pathlib . Path ( directory , f' { self .name } .whl' )
509
507
510
- root = 'purelib' if self .is_pure else 'platlib'
508
+ with mesonpy ._wheelfile .WheelFile (wheel_file , 'w' ) as whl :
509
+ self ._wheel_write_metadata (whl )
511
510
512
- for path , entries in self ._wheel_files .items ():
513
- for dst , src in entries :
514
- counter .update (src )
511
+ with mesonpy ._util .cli_counter (sum (len (x ) for x in self ._wheel_files .values ())) as counter :
515
512
516
- if path == root :
517
- pass
518
- elif path == 'mesonpy-libs' :
519
- # custom installation path for bundled libraries
520
- dst = pathlib .Path (f'.{ self ._project .name } .mesonpy.libs' , dst )
521
- else :
522
- dst = pathlib .Path (self .data_dir , path , dst )
513
+ root = 'purelib' if self .is_pure else 'platlib'
514
+
515
+ for path , entries in self ._wheel_files .items ():
516
+ for dst , src in entries :
517
+ counter .update (src )
523
518
524
- self ._install_path (whl , src , dst )
519
+ if path == root :
520
+ pass
521
+ elif path == 'mesonpy-libs' :
522
+ # custom installation path for bundled libraries
523
+ dst = pathlib .Path (f'.{ self ._project .name } .mesonpy.libs' , dst )
524
+ else :
525
+ dst = pathlib .Path (self .data_dir , path , dst )
526
+
527
+ self ._install_path (whl , src , dst )
525
528
526
529
return wheel_file
527
530
@@ -638,16 +641,13 @@ class Project():
638
641
def __init__ ( # noqa: C901
639
642
self ,
640
643
source_dir : Path ,
641
- working_dir : Path ,
642
- build_dir : Optional [Path ] = None ,
644
+ build_dir : Path ,
643
645
meson_args : Optional [MesonArgs ] = None ,
644
646
editable_verbose : bool = False ,
645
647
) -> None :
646
648
self ._source_dir = pathlib .Path (source_dir ).absolute ()
647
- self ._working_dir = pathlib .Path (working_dir ).absolute ()
648
- self ._build_dir = pathlib .Path (build_dir ).absolute () if build_dir else (self ._working_dir / 'build' )
649
+ self ._build_dir = pathlib .Path (build_dir ).absolute ()
649
650
self ._editable_verbose = editable_verbose
650
- self ._install_dir = self ._working_dir / 'install'
651
651
self ._meson_native_file = self ._build_dir / 'meson-python-native-file.ini'
652
652
self ._meson_cross_file = self ._build_dir / 'meson-python-cross-file.ini'
653
653
self ._meson_args : MesonArgs = collections .defaultdict (list )
@@ -662,7 +662,6 @@ def __init__( # noqa: C901
662
662
663
663
# make sure the build dir exists
664
664
self ._build_dir .mkdir (exist_ok = True , parents = True )
665
- self ._install_dir .mkdir (exist_ok = True , parents = True )
666
665
667
666
# setuptools-like ARCHFLAGS environment variable support
668
667
if sysconfig .get_platform ().startswith ('macosx-' ):
@@ -818,24 +817,11 @@ def build(self) -> None:
818
817
"""Build the Meson project."""
819
818
self ._run (self ._build_command )
820
819
821
- def install (self ) -> None :
820
+ def install (self , destdir : Path ) -> None :
822
821
"""Install the Meson project."""
823
- destdir = os .fspath (self . _install_dir )
822
+ destdir = os .fspath (destdir )
824
823
self ._run (['meson' , 'install' , '--quiet' , '--no-rebuild' , '--destdir' , destdir , * self ._meson_args ['install' ]])
825
824
826
- @classmethod
827
- @contextlib .contextmanager
828
- def with_temp_working_dir (
829
- cls ,
830
- source_dir : Path = os .path .curdir ,
831
- build_dir : Optional [Path ] = None ,
832
- meson_args : Optional [MesonArgs ] = None ,
833
- editable_verbose : bool = False ,
834
- ) -> Iterator [Project ]:
835
- """Creates a project instance pointing to a temporary working directory."""
836
- with tempfile .TemporaryDirectory (prefix = '.mesonpy-' , dir = os .fspath (source_dir )) as tmpdir :
837
- yield cls (source_dir , tmpdir , build_dir , meson_args , editable_verbose )
838
-
839
825
@functools .lru_cache ()
840
826
def _info (self , name : str ) -> Any :
841
827
"""Read info from meson-info directory."""
@@ -983,18 +969,19 @@ def editable(self, directory: Path) -> pathlib.Path:
983
969
984
970
985
971
@contextlib .contextmanager
986
- def _project (config_settings : Optional [Dict [Any , Any ]]) -> Iterator [Project ]:
972
+ def _project (config_settings : Optional [Dict [Any , Any ]] = None ) -> Iterator [Project ]:
987
973
"""Create the project given the given config settings."""
988
974
989
975
settings = _validate_config_settings (config_settings or {})
990
- meson_args = {name : settings .get (f'{ name } -args' , []) for name in _MESON_ARGS_KEYS }
991
-
992
- with Project .with_temp_working_dir (
993
- build_dir = settings .get ('builddir' ),
994
- meson_args = typing .cast (MesonArgs , meson_args ),
995
- editable_verbose = bool (settings .get ('editable-verbose' ))
996
- ) as project :
997
- yield project
976
+ meson_args = typing .cast (MesonArgs , {name : settings .get (f'{ name } -args' , []) for name in _MESON_ARGS_KEYS })
977
+ source_dir = os .path .curdir
978
+ build_dir = settings .get ('builddir' )
979
+ editable_verbose = bool (settings .get ('editable-verbose' ))
980
+
981
+ with contextlib .ExitStack () as ctx :
982
+ if build_dir is None :
983
+ build_dir = ctx .enter_context (tempfile .TemporaryDirectory (prefix = '.mesonpy-' , dir = source_dir ))
984
+ yield Project (source_dir , build_dir , meson_args , editable_verbose )
998
985
999
986
1000
987
def _parse_version_string (string : str ) -> Tuple [int , ...]:
0 commit comments