Commit f4143238 authored by PJ Eby's avatar PJ Eby

Don't write .py stubs except for actual extensions that don't already

have them.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042034
parent eb8c892b
...@@ -10,6 +10,7 @@ from distutils.sysconfig import get_python_version, get_python_lib ...@@ -10,6 +10,7 @@ from distutils.sysconfig import get_python_version, get_python_lib
from distutils import log from distutils import log
from pkg_resources import get_platform, Distribution from pkg_resources import get_platform, Distribution
from types import CodeType from types import CodeType
from setuptools.extension import Library
def write_stub(resource, pyfile): def write_stub(resource, pyfile):
f = open(pyfile,'w') f = open(pyfile,'w')
...@@ -38,7 +39,6 @@ NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)' ...@@ -38,7 +39,6 @@ NS_PKG_STUB = '__import__("pkg_resources").declare_namespace(__name__)'
class bdist_egg(Command): class bdist_egg(Command):
description = "create an \"egg\" distribution" description = "create an \"egg\" distribution"
...@@ -174,7 +174,7 @@ class bdist_egg(Command): ...@@ -174,7 +174,7 @@ class bdist_egg(Command):
cmd = self.call_command('install_lib', warn_dir=0) cmd = self.call_command('install_lib', warn_dir=0)
instcmd.root = old_root instcmd.root = old_root
ext_outputs = self.get_ext_outputs() all_outputs, ext_outputs = self.get_ext_outputs()
self.stubs = [] self.stubs = []
to_compile = [] to_compile = []
for (p,ext_name) in enumerate(ext_outputs): for (p,ext_name) in enumerate(ext_outputs):
...@@ -204,11 +204,11 @@ class bdist_egg(Command): ...@@ -204,11 +204,11 @@ class bdist_egg(Command):
self.call_command('install_scripts', install_dir=script_dir) self.call_command('install_scripts', install_dir=script_dir)
native_libs = os.path.join(self.egg_info,"native_libs.txt") native_libs = os.path.join(self.egg_info,"native_libs.txt")
if ext_outputs: if all_outputs:
log.info("writing %s" % native_libs) log.info("writing %s" % native_libs)
if not self.dry_run: if not self.dry_run:
libs_file = open(native_libs, 'wt') libs_file = open(native_libs, 'wt')
libs_file.write('\n'.join(ext_outputs)) libs_file.write('\n'.join(all_outputs))
libs_file.write('\n') libs_file.write('\n')
libs_file.close() libs_file.close()
elif os.path.isfile(native_libs): elif os.path.isfile(native_libs):
...@@ -288,28 +288,28 @@ class bdist_egg(Command): ...@@ -288,28 +288,28 @@ class bdist_egg(Command):
def get_ext_outputs(self): def get_ext_outputs(self):
"""Get a list of relative paths to C extensions in the output distro""" """Get a list of relative paths to C extensions in the output distro"""
outputs = [] all_outputs = []
ext_outputs = []
paths = {self.bdist_dir:''} paths = {self.bdist_dir:''}
for base, dirs, files in os.walk(self.bdist_dir): for base, dirs, files in os.walk(self.bdist_dir):
for filename in files: for filename in files:
if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS: if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS:
outputs.append(paths[base]+filename) all_outputs.append(paths[base]+filename)
for filename in dirs: for filename in dirs:
paths[os.path.join(base,filename)] = paths[base]+filename+'/' paths[os.path.join(base,filename)] = paths[base]+filename+'/'
if not self.distribution.has_ext_modules():
return outputs
build_cmd = self.get_finalized_command('build_ext')
prefix_len = len(build_cmd.build_lib) + len(os.sep)
for filename in build_cmd.get_outputs():
if os.path.splitext(filename)[1].lower() not in NATIVE_EXTENSIONS:
# only add files w/unrecognized extensions, since the
# recognized ones will already be in the list
outputs.append(filename[prefix_len:])
return outputs if self.distribution.has_ext_modules():
build_cmd = self.get_finalized_command('build_ext')
for ext in build_cmd.extensions:
if isinstance(ext,Library):
continue
fullname = build_cmd.get_ext_fullname(ext.name)
filename = build_cmd.get_ext_filename(fullname)
if not os.path.basename(filename).startswith('dl-'):
ext_outputs.append(filename)
return all_outputs, ext_outputs
NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split()) NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split())
......
...@@ -165,12 +165,12 @@ class build_ext(_build_ext): ...@@ -165,12 +165,12 @@ class build_ext(_build_ext):
def build_extension(self, ext): def build_extension(self, ext):
_compiler = self.compiler _compiler = self.compiler
_rpath = ext.runtime_library_dirs _rpath = ext.runtime_library_dirs
_ldirs = library_dirs _ldirs = ext.library_dirs
try: try:
if isinstance(ext,Library): if isinstance(ext,Library):
self.compiler = self.shlib_compiler self.compiler = self.shlib_compiler
if have_rtld and self.links_to_dynamic(ext): if self.links_to_dynamic(ext):
ext.runtime_library_dirs = _rpath + [os.curdir] if have_rtld: ext.runtime_library_dirs = _rpath + [os.curdir]
ext.library_dirs = _ldirs + [ ext.library_dirs = _ldirs + [
os.path.dirname( os.path.dirname(
os.path.join(self.build_lib, os.path.join(self.build_lib,
...@@ -196,12 +196,12 @@ class build_ext(_build_ext): ...@@ -196,12 +196,12 @@ class build_ext(_build_ext):
libnames = dict.fromkeys( libnames = dict.fromkeys(
[self.get_ext_fullname(lib.name) for lib in self.shlibs] [self.get_ext_fullname(lib.name) for lib in self.shlibs]
) )
if not libnames:
return False
pkg = '.'.join(self.get_ext_fullname(ext.name).split('.')[:-1]) pkg = '.'.join(self.get_ext_fullname(ext.name).split('.')[:-1])
if pkg: pkg+='.'
for libname in ext.libraries: for libname in ext.libraries:
if ('%s.%s' % (pkg,libname)) in libnames: if pkg+libname in libnames: return True
return True return False
if have_rtld or os.name=='nt': if have_rtld or os.name=='nt':
# Build shared libraries # Build shared libraries
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment