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