update shared
This commit is contained in:
parent
1c7d934c4c
commit
9d7763e017
51 changed files with 566 additions and 337 deletions
|
|
@ -2,9 +2,13 @@ from glob import glob
|
|||
from distutils.util import convert_path
|
||||
import distutils.command.build_py as orig
|
||||
import os
|
||||
import sys
|
||||
import fnmatch
|
||||
import textwrap
|
||||
import io
|
||||
import distutils.errors
|
||||
import collections
|
||||
import itertools
|
||||
|
||||
|
||||
try:
|
||||
from setuptools.lib2to3_ex import Mixin2to3
|
||||
|
|
@ -157,17 +161,15 @@ class build_py(orig.build_py, Mixin2to3):
|
|||
else:
|
||||
return init_py
|
||||
|
||||
f = open(init_py, 'rbU')
|
||||
if 'declare_namespace'.encode() not in f.read():
|
||||
from distutils.errors import DistutilsError
|
||||
|
||||
raise DistutilsError(
|
||||
with io.open(init_py, 'rb') as f:
|
||||
contents = f.read()
|
||||
if b'declare_namespace' not in contents:
|
||||
raise distutils.errors.DistutilsError(
|
||||
"Namespace package problem: %s is a namespace package, but "
|
||||
"its\n__init__.py does not call declare_namespace()! Please "
|
||||
'fix it.\n(See the setuptools manual under '
|
||||
'"Namespace Packages" for details.)\n"' % (package,)
|
||||
)
|
||||
f.close()
|
||||
return init_py
|
||||
|
||||
def initialize_options(self):
|
||||
|
|
@ -182,20 +184,25 @@ class build_py(orig.build_py, Mixin2to3):
|
|||
|
||||
def exclude_data_files(self, package, src_dir, files):
|
||||
"""Filter filenames for package's data files in 'src_dir'"""
|
||||
globs = (self.exclude_package_data.get('', [])
|
||||
+ self.exclude_package_data.get(package, []))
|
||||
bad = []
|
||||
for pattern in globs:
|
||||
bad.extend(
|
||||
fnmatch.filter(
|
||||
files, os.path.join(src_dir, convert_path(pattern))
|
||||
)
|
||||
globs = (
|
||||
self.exclude_package_data.get('', [])
|
||||
+ self.exclude_package_data.get(package, [])
|
||||
)
|
||||
bad = set(
|
||||
item
|
||||
for pattern in globs
|
||||
for item in fnmatch.filter(
|
||||
files,
|
||||
os.path.join(src_dir, convert_path(pattern)),
|
||||
)
|
||||
bad = dict.fromkeys(bad)
|
||||
seen = {}
|
||||
)
|
||||
seen = collections.defaultdict(itertools.count)
|
||||
return [
|
||||
f for f in files if f not in bad
|
||||
and f not in seen and seen.setdefault(f, 1) # ditch dupes
|
||||
fn
|
||||
for fn in files
|
||||
if fn not in bad
|
||||
# ditch dupes
|
||||
and not next(seen[fn])
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from distutils import log
|
|||
from distutils.errors import DistutilsError, DistutilsOptionError
|
||||
import os
|
||||
import glob
|
||||
import io
|
||||
|
||||
from pkg_resources import Distribution, PathMetadata, normalize_path
|
||||
from setuptools.command.easy_install import easy_install
|
||||
|
|
@ -53,8 +54,8 @@ class develop(easy_install):
|
|||
# pick up setup-dir .egg files only: no .egg-info
|
||||
self.package_index.scan(glob.glob('*.egg'))
|
||||
|
||||
self.egg_link = os.path.join(self.install_dir, ei.egg_name +
|
||||
'.egg-link')
|
||||
egg_link_fn = ei.egg_name + '.egg-link'
|
||||
self.egg_link = os.path.join(self.install_dir, egg_link_fn)
|
||||
self.egg_base = ei.egg_base
|
||||
if self.egg_path is None:
|
||||
self.egg_path = os.path.abspath(ei.egg_base)
|
||||
|
|
@ -124,9 +125,8 @@ class develop(easy_install):
|
|||
# create an .egg-link in the installation dir, pointing to our egg
|
||||
log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
|
||||
if not self.dry_run:
|
||||
f = open(self.egg_link, "w")
|
||||
f.write(self.egg_path + "\n" + self.setup_path)
|
||||
f.close()
|
||||
with open(self.egg_link, "w") as f:
|
||||
f.write(self.egg_path + "\n" + self.setup_path)
|
||||
# postprocess the installed distro, fixing up .pth, installing scripts,
|
||||
# and handling requirements
|
||||
self.process_distribution(None, self.dist, not self.no_deps)
|
||||
|
|
@ -163,7 +163,33 @@ class develop(easy_install):
|
|||
for script_name in self.distribution.scripts or []:
|
||||
script_path = os.path.abspath(convert_path(script_name))
|
||||
script_name = os.path.basename(script_path)
|
||||
f = open(script_path, 'rU')
|
||||
script_text = f.read()
|
||||
f.close()
|
||||
with io.open(script_path) as strm:
|
||||
script_text = strm.read()
|
||||
self.install_script(dist, script_name, script_text, script_path)
|
||||
|
||||
def install_wrapper_scripts(self, dist):
|
||||
dist = VersionlessRequirement(dist)
|
||||
return easy_install.install_wrapper_scripts(self, dist)
|
||||
|
||||
|
||||
class VersionlessRequirement(object):
|
||||
"""
|
||||
Adapt a pkg_resources.Distribution to simply return the project
|
||||
name as the 'requirement' so that scripts will work across
|
||||
multiple versions.
|
||||
|
||||
>>> dist = Distribution(project_name='foo', version='1.0')
|
||||
>>> str(dist.as_requirement())
|
||||
'foo==1.0'
|
||||
>>> adapted_dist = VersionlessRequirement(dist)
|
||||
>>> str(adapted_dist.as_requirement())
|
||||
'foo'
|
||||
"""
|
||||
def __init__(self, dist):
|
||||
self.__dist = dist
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.__dist, name)
|
||||
|
||||
def as_requirement(self):
|
||||
return self.project_name
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from distutils.errors import DistutilsArgError, DistutilsOptionError, \
|
|||
from distutils.command.install import INSTALL_SCHEMES, SCHEME_KEYS
|
||||
from distutils import log, dir_util
|
||||
from distutils.command.build_scripts import first_line_re
|
||||
from distutils.spawn import find_executable
|
||||
import sys
|
||||
import os
|
||||
import zipimport
|
||||
|
|
@ -760,9 +761,10 @@ class easy_install(Command):
|
|||
return dst
|
||||
|
||||
def install_wrapper_scripts(self, dist):
|
||||
if not self.exclude_scripts:
|
||||
for args in ScriptWriter.best().get_args(dist):
|
||||
self.write_script(*args)
|
||||
if self.exclude_scripts:
|
||||
return
|
||||
for args in ScriptWriter.best().get_args(dist):
|
||||
self.write_script(*args)
|
||||
|
||||
def install_script(self, dist, script_name, script_text, dev_path=None):
|
||||
"""Generate a legacy script wrapper and install it"""
|
||||
|
|
@ -770,8 +772,8 @@ class easy_install(Command):
|
|||
is_script = is_python_script(script_text, script_name)
|
||||
|
||||
if is_script:
|
||||
script_text = (ScriptWriter.get_header(script_text) +
|
||||
self._load_template(dev_path) % locals())
|
||||
body = self._load_template(dev_path) % locals()
|
||||
script_text = ScriptWriter.get_header(script_text) + body
|
||||
self.write_script(script_name, _to_ascii(script_text), 'b')
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -803,9 +805,8 @@ class easy_install(Command):
|
|||
ensure_directory(target)
|
||||
if os.path.exists(target):
|
||||
os.unlink(target)
|
||||
f = open(target, "w" + mode)
|
||||
f.write(contents)
|
||||
f.close()
|
||||
with open(target, "w" + mode) as f:
|
||||
f.write(contents)
|
||||
chmod(target, 0o777 - mask)
|
||||
|
||||
def install_eggs(self, spec, dist_filename, tmpdir):
|
||||
|
|
@ -1401,7 +1402,7 @@ def expand_paths(inputs):
|
|||
def extract_wininst_cfg(dist_filename):
|
||||
"""Extract configuration data from a bdist_wininst .exe
|
||||
|
||||
Returns a ConfigParser.RawConfigParser, or None
|
||||
Returns a configparser.RawConfigParser, or None
|
||||
"""
|
||||
f = open(dist_filename, 'rb')
|
||||
try:
|
||||
|
|
@ -1414,7 +1415,7 @@ def extract_wininst_cfg(dist_filename):
|
|||
return None
|
||||
f.seek(prepended - 12)
|
||||
|
||||
from setuptools.compat import StringIO, ConfigParser
|
||||
from setuptools.compat import StringIO, configparser
|
||||
import struct
|
||||
|
||||
tag, cfglen, bmlen = struct.unpack("<iii", f.read(12))
|
||||
|
|
@ -1422,7 +1423,7 @@ def extract_wininst_cfg(dist_filename):
|
|||
return None # not a valid tag
|
||||
|
||||
f.seek(prepended - (12 + cfglen))
|
||||
cfg = ConfigParser.RawConfigParser(
|
||||
cfg = configparser.RawConfigParser(
|
||||
{'version': '', 'target_version': ''})
|
||||
try:
|
||||
part = f.read(cfglen)
|
||||
|
|
@ -1432,7 +1433,7 @@ def extract_wininst_cfg(dist_filename):
|
|||
# be text, so decode it.
|
||||
config = config.decode(sys.getfilesystemencoding())
|
||||
cfg.readfp(StringIO(config))
|
||||
except ConfigParser.Error:
|
||||
except configparser.Error:
|
||||
return None
|
||||
if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
|
||||
return None
|
||||
|
|
@ -2125,8 +2126,8 @@ class WindowsScriptWriter(ScriptWriter):
|
|||
blockers = [name + x for x in old]
|
||||
yield name + ext, header + script_text, 't', blockers
|
||||
|
||||
@staticmethod
|
||||
def _adjust_header(type_, orig_header):
|
||||
@classmethod
|
||||
def _adjust_header(cls, type_, orig_header):
|
||||
"""
|
||||
Make sure 'pythonw' is used for gui and and 'python' is used for
|
||||
console (regardless of what sys.executable is).
|
||||
|
|
@ -2137,11 +2138,19 @@ class WindowsScriptWriter(ScriptWriter):
|
|||
pattern, repl = repl, pattern
|
||||
pattern_ob = re.compile(re.escape(pattern), re.IGNORECASE)
|
||||
new_header = pattern_ob.sub(string=orig_header, repl=repl)
|
||||
return new_header if cls._use_header(new_header) else orig_header
|
||||
|
||||
@staticmethod
|
||||
def _use_header(new_header):
|
||||
"""
|
||||
Should _adjust_header use the replaced header?
|
||||
|
||||
On non-windows systems, always use. On
|
||||
Windows systems, only use the replaced header if it resolves
|
||||
to an executable on the system.
|
||||
"""
|
||||
clean_header = new_header[2:-1].strip('"')
|
||||
if sys.platform == 'win32' and not os.path.exists(clean_header):
|
||||
# the adjusted version doesn't exist, so return the original
|
||||
return orig_header
|
||||
return new_header
|
||||
return sys.platform != 'win32' or find_executable(clean_header)
|
||||
|
||||
|
||||
class WindowsExecutableLauncherWriter(WindowsScriptWriter):
|
||||
|
|
|
|||
|
|
@ -10,16 +10,17 @@ import distutils.filelist
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import io
|
||||
import warnings
|
||||
import time
|
||||
|
||||
try:
|
||||
from setuptools_svn import svn_utils
|
||||
except ImportError:
|
||||
pass
|
||||
from setuptools.compat import basestring, PY3, StringIO
|
||||
|
||||
from setuptools import Command
|
||||
from setuptools.command.sdist import sdist
|
||||
from setuptools.compat import basestring, PY3, StringIO
|
||||
from setuptools.command.sdist import walk_revctrl
|
||||
from setuptools.command.setopt import edit_config
|
||||
from setuptools.command import bdist_egg
|
||||
from pkg_resources import (
|
||||
parse_requirements, safe_name, parse_version,
|
||||
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
|
||||
|
|
@ -27,6 +28,12 @@ import setuptools.unicode_utils as unicode_utils
|
|||
|
||||
from pkg_resources import packaging
|
||||
|
||||
try:
|
||||
from setuptools_svn import svn_utils
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class egg_info(Command):
|
||||
description = "create a distribution's .egg-info directory"
|
||||
|
||||
|
|
@ -58,8 +65,6 @@ class egg_info(Command):
|
|||
self.vtags = None
|
||||
|
||||
def save_version_info(self, filename):
|
||||
from setuptools.command.setopt import edit_config
|
||||
|
||||
values = dict(
|
||||
egg_info=dict(
|
||||
tag_svn_revision=0,
|
||||
|
|
@ -184,12 +189,8 @@ class egg_info(Command):
|
|||
if self.tag_build:
|
||||
version += self.tag_build
|
||||
if self.tag_svn_revision:
|
||||
rev = self.get_svn_revision()
|
||||
if rev: # is 0 if it's not an svn working copy
|
||||
version += '-r%s' % rev
|
||||
version += '-r%s' % self.get_svn_revision()
|
||||
if self.tag_date:
|
||||
import time
|
||||
|
||||
version += time.strftime("-%Y%m%d")
|
||||
return version
|
||||
|
||||
|
|
@ -390,7 +391,6 @@ def write_pkg_info(cmd, basename, filename):
|
|||
metadata.name, metadata.version = oldname, oldver
|
||||
|
||||
safe = getattr(cmd.distribution, 'zip_safe', None)
|
||||
from setuptools.command import bdist_egg
|
||||
|
||||
bdist_egg.write_safety_flag(cmd.egg_info, safe)
|
||||
|
||||
|
|
@ -467,14 +467,15 @@ def write_entries(cmd, basename, filename):
|
|||
|
||||
|
||||
def get_pkg_info_revision():
|
||||
# See if we can get a -r### off of PKG-INFO, in case this is an sdist of
|
||||
# a subversion revision
|
||||
#
|
||||
"""
|
||||
Get a -r### off of PKG-INFO Version in case this is an sdist of
|
||||
a subversion revision.
|
||||
"""
|
||||
warnings.warn("get_pkg_info_revision is deprecated.", DeprecationWarning)
|
||||
if os.path.exists('PKG-INFO'):
|
||||
f = open('PKG-INFO', 'rU')
|
||||
for line in f:
|
||||
match = re.match(r"Version:.*-r(\d+)\s*$", line)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
f.close()
|
||||
with io.open('PKG-INFO') as f:
|
||||
for line in f:
|
||||
match = re.match(r"Version:.*-r(\d+)\s*$", line)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ class install_lib(orig.install_lib):
|
|||
base = os.path.join('__pycache__', '__init__.' + imp.get_tag())
|
||||
yield base + '.pyc'
|
||||
yield base + '.pyo'
|
||||
yield base + '.opt-1.pyc'
|
||||
yield base + '.opt-2.pyc'
|
||||
|
||||
def copy_tree(
|
||||
self, infile, outfile,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from distutils import log
|
|||
import distutils.command.sdist as orig
|
||||
import os
|
||||
import sys
|
||||
import io
|
||||
|
||||
from setuptools.compat import PY3
|
||||
from setuptools.utils import cs_path_exists
|
||||
|
|
@ -166,11 +167,8 @@ class sdist(orig.sdist):
|
|||
if not os.path.isfile(self.manifest):
|
||||
return False
|
||||
|
||||
fp = open(self.manifest, 'rbU')
|
||||
try:
|
||||
with io.open(self.manifest, 'rb') as fp:
|
||||
first_line = fp.readline()
|
||||
finally:
|
||||
fp.close()
|
||||
return (first_line !=
|
||||
'# file GENERATED by distutils, do NOT edit\n'.encode())
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@ def edit_config(filename, settings, dry_run=False):
|
|||
while a dictionary lists settings to be changed or deleted in that section.
|
||||
A setting of ``None`` means to delete that setting.
|
||||
"""
|
||||
from setuptools.compat import ConfigParser
|
||||
from setuptools.compat import configparser
|
||||
|
||||
log.debug("Reading configuration from %s", filename)
|
||||
opts = ConfigParser.RawConfigParser()
|
||||
opts = configparser.RawConfigParser()
|
||||
opts.read([filename])
|
||||
for section, options in settings.items():
|
||||
if options is None:
|
||||
|
|
|
|||
|
|
@ -41,6 +41,17 @@ class ScanningLoader(TestLoader):
|
|||
return tests[0] # don't create a nested suite for only one return
|
||||
|
||||
|
||||
# adapted from jaraco.classes.properties:NonDataProperty
|
||||
class NonDataProperty(object):
|
||||
def __init__(self, fget):
|
||||
self.fget = fget
|
||||
|
||||
def __get__(self, obj, objtype=None):
|
||||
if obj is None:
|
||||
return self
|
||||
return self.fget(obj)
|
||||
|
||||
|
||||
class test(Command):
|
||||
"""Command to run unit tests after in-place build"""
|
||||
|
||||
|
|
@ -78,7 +89,7 @@ class test(Command):
|
|||
if self.test_runner is None:
|
||||
self.test_runner = getattr(self.distribution, 'test_runner', None)
|
||||
|
||||
@property
|
||||
@NonDataProperty
|
||||
def test_args(self):
|
||||
return list(self._test_args())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue