CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2025-03-25
by 张馆长

Original Post

Original - Posted on 2016-10-22
by espdev



            
Present in both answers; Present only in the new answer; Present only in the old answer;

``` # distutils/command/build_ext.py def get_ext_filename(self, ext_name): r"""Convert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). """ from distutils.sysconfig import get_config_var ext_path = ext_name.split('.') ext_suffix = get_config_var('EXT_SUFFIX') return os.path.join(*ext_path) + ext_suffix ```
add a class override func get_ext_filename
``` from Cython.Distutils import build_ext
class BuildExtWithTargetPlatformSuffix(build_ext): def get_ext_filename(self, ext_name): filename = super().get_ext_filename(ext_name) return filename.replace("linux", "1111") ```
use with setup
``` from distutils.core import setup setup( ... cmdclass={'build_ext': BuildExtWithTargetPlatformSuffix}, ) ```
This behavior has been defined in distutils package. distutils uses sysconfig and "EXT_SUFFIX" config variable:
# Lib\distutils\command\build_ext.py
def get_ext_filename(self, ext_name): r"""Convert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). """ from distutils.sysconfig import get_config_var ext_path = ext_name.split('.') ext_suffix = get_config_var('EXT_SUFFIX') return os.path.join(*ext_path) + ext_suffix
Starting with Python 3.5 "EXT_SUFFIX" variable contains platform information, for example ".cp35-win_amd64".
I have written the following function: def get_ext_filename_without_platform_suffix(filename): name, ext = os.path.splitext(filename) ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
if ext_suffix == ext: return filename
ext_suffix = ext_suffix.replace(ext, '') idx = name.find(ext_suffix)
if idx == -1: return filename else: return name[:idx] + ext
And custom **build_ext** command:
from Cython.Distutils import build_ext
class BuildExtWithoutPlatformSuffix(build_ext): def get_ext_filename(self, ext_name): filename = super().get_ext_filename(ext_name) return get_ext_filename_without_platform_suffix(filename)
Usage: setup( ... cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, ... )

        
Present in both answers; Present only in the new answer; Present only in the old answer;