1818from pathlib import Path
1919from typing import Dict , List , Literal , NamedTuple , Optional , Set , Tuple , cast
2020
21- import pkg_resources
22- from semantic_version import Version
2321from setuptools import Distribution
2422from setuptools .command .build import build as CommandBuild
2523from setuptools .command .build_ext import build_ext as CommandBuildExt
2624from setuptools .command .build_ext import get_abi3_suffix
25+ from setuptools .command .install_scripts import install_scripts as CommandInstallScripts
2726
2827from ._utils import format_called_process_error
2928from .command import RustCommand
@@ -93,8 +92,6 @@ def initialize_options(self) -> None:
9392 def finalize_options (self ) -> None :
9493 super ().finalize_options ()
9594
96- self .data_dir = self .get_data_dir ()
97-
9895 if self .plat_name is None :
9996 self .plat_name = cast (
10097 CommandBuild , self .get_finalized_command ("build" )
@@ -112,17 +109,6 @@ def finalize_options(self) -> None:
112109 if self .build_number is not None and not self .build_number [:1 ].isdigit ():
113110 raise ValueError ("Build tag (build-number) must start with a digit." )
114111
115- def get_data_dir (self ) -> str :
116- components = (
117- pkg_resources .safe_name (self .distribution .get_name ()).replace ("-" , "_" ),
118- pkg_resources .safe_version (self .distribution .get_version ()).replace (
119- "-" , "_"
120- ),
121- )
122- if self .build_number :
123- components += (self .build_number ,)
124- return "-" .join (components ) + ".data"
125-
126112 def run_for_extension (self , ext : RustExtension ) -> None :
127113 assert self .plat_name is not None
128114
@@ -358,30 +344,33 @@ def install_extension(
358344 )
359345
360346 if ext ._uses_exec_binding ():
361- ext_path = build_ext .get_ext_fullpath (module_name )
362- # remove extensions
363- ext_path , _ , _ = _split_platform_and_extension (ext_path )
364-
365- # Add expected extension
366347 exe = sysconfig .get_config_var ("EXE" )
367- if exe is not None :
368- ext_path += exe
369348
370- os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
371349 if isinstance (ext , RustBin ):
372- executable_name = module_name
350+ # will install the rust binary into the scripts directory
351+ bin_name = module_name
373352 if exe is not None :
374- executable_name += exe
375- scripts_dir = os .path .join (
376- build_ext .build_lib , self .data_dir , "scripts"
353+ bin_name += exe
354+
355+ install_scripts = cast (
356+ CommandInstallScripts ,
357+ self .get_finalized_command ("install_scripts" ),
377358 )
378- os .makedirs (scripts_dir , exist_ok = True )
379- ext_path = os .path .join (scripts_dir , executable_name )
359+ ext_path = os .path .join (install_scripts .build_dir , bin_name )
380360 else :
361+ # will install the rust binary into the module directory
362+ ext_path = build_ext .get_ext_fullpath (module_name )
363+
364+ # add expected extension
365+ ext_path , _ , _ = _split_platform_and_extension (ext_path )
366+ if exe is not None :
367+ ext_path += exe
368+
369+ # if required, also generate a console script entry point
381370 ext .install_script (module_name .split ("." )[- 1 ], ext_path )
382371 else :
372+ # will install the rust library into the module directory
383373 ext_path = self .get_dylib_ext_path (ext , module_name )
384- os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
385374
386375 # Make filenames relative to cwd where possible, to make logs and
387376 # errors below a little neater
@@ -392,6 +381,7 @@ def install_extension(
392381 if ext_path .startswith (cwd ):
393382 ext_path = os .path .relpath (ext_path , cwd )
394383
384+ os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
395385 logger .info ("Copying rust artifact from %s to %s" , dylib_path , ext_path )
396386
397387 # We want to atomically replace any existing library file. We can't
0 commit comments