tested django-newsletter

This commit is contained in:
Esther Kleinhenz
2018-10-26 15:21:17 +02:00
parent 7ed667d043
commit 811b7c5453
2352 changed files with 448169 additions and 1 deletions
@@ -0,0 +1 @@
# Init for terryfy waf helpers
@@ -0,0 +1,33 @@
#!/usr/bin/env python
""" Script to run bdist_wheel after setuptools import
"""
import sys, os
import setuptools
def main():
del sys.argv[0]
if not sys.argv:
sys.argv[:0] = ['setup.py']
elif sys.argv[0].startswith('-'):
sys.argv[:0] = ['setup.py']
sys.argv.insert(1, 'bdist_wheel')
if os.path.isdir(sys.argv[0]):
sys.argv[0] = os.path.join(sys.argv[0], 'setup.py')
path, name = os.path.split(os.path.abspath(sys.argv[0]))
if path:
os.chdir(path)
sys.path.insert(0, path)
sys.argv[0] = name
g = dict(globals())
g['__file__'] = sys.argv[0]
g['__name__'] = '__main__'
if sys.version_info[0] < 3:
execfile(sys.argv[0], g, g)
else:
exec(open(sys.argv[0]).read(), g, g)
if __name__ == '__main__':
main()
@@ -0,0 +1,34 @@
""" Copy real (not symlinks to) libraries with given suffix
"""
from __future__ import print_function
USAGE = """\
cp_suff_real_libs.py <lib_dir> <lib_suffix>
"""
import os
from os.path import splitext, join as pjoin, islink
import sys
import shutil
LIB_EXTS = ('.a', '.so', '.dylib')
def main():
try:
lib_dir, suffix = sys.argv[1:]
except (IndexError, ValueError):
print(USAGE)
sys.exit(-1)
for fname in os.listdir(lib_dir):
if not splitext(fname)[1] in LIB_EXTS:
continue
old_path = pjoin(lib_dir, fname)
if islink(old_path):
continue
shutil.copyfile(old_path, old_path + suffix)
if __name__ == '__main__':
main()
@@ -0,0 +1,42 @@
""" Fuse real (not symlinks to) libraries with same name
"""
from __future__ import print_function
USAGE = """\
fuse_suff_real_libs.py <lib_dir_out> <lib_dir_in1> <lib_dir_in2>
"""
import os
from os.path import (splitext, join as pjoin, split as psplit, islink, isfile,
abspath, realpath)
import sys
import shutil
from subprocess import check_call
LIB_EXTS = ('.a', '.so', '.dylib')
def main():
try:
lib_dir_out, lib_dir_in1, lib_dir_in2 = sys.argv[1:]
except (IndexError, ValueError):
print(USAGE)
sys.exit(-1)
for fname in os.listdir(lib_dir_in1):
if not splitext(fname)[1] in LIB_EXTS:
continue
lib_path = pjoin(lib_dir_in1, fname)
out_path = pjoin(lib_dir_out, fname)
if islink(lib_path):
continue
lib_path_2 = pjoin(lib_dir_in2, fname)
if not isfile(lib_path_2):
continue
# Fuse and copy library
check_call(['lipo', '-create', lib_path, lib_path_2,
'-output', out_path])
if __name__ == '__main__':
main()
@@ -0,0 +1,56 @@
""" Monkey patch waf code to pipe command output direct to stdout
As far as I know there is no way to do this using standard waf build commands
options.
"""
import sys
from waflib import Utils, Errors, Logs, Context
def my_exec_command(self,cmd,**kw):
""" Copy of Context.exec_command that doesn't capture stdout / stderr
This is necessary to prevent travis-ci timing out while waiting for
feedback from the scipy build process, in particular
"""
subprocess=Utils.subprocess
kw['shell']=isinstance(cmd,str)
Logs.debug('runner: %r'%cmd)
Logs.debug('runner_env: kw=%s'%kw)
if self.logger:
self.logger.info(cmd)
if'stdout'not in kw:
kw['stdout']=sys.stdout
if'stderr'not in kw:
kw['stderr']=sys.stderr
try:
if kw['stdout']or kw['stderr']:
p=subprocess.Popen(cmd,**kw)
(out,err)=p.communicate()
ret=p.returncode
else:
out,err=(None,None)
ret=subprocess.Popen(cmd,**kw).wait()
except Exception as e:
raise Errors.WafError('Execution failure: %s'%str(e),ex=e)
if out:
if not isinstance(out,str):
out=out.decode(sys.stdout.encoding or'iso8859-1')
if self.logger:
self.logger.debug('out: %s'%out)
else:
sys.stdout.write(out)
if err:
if not isinstance(err,str):
err=err.decode(sys.stdout.encoding or'iso8859-1')
if self.logger:
self.logger.error('err: %s'%err)
else:
sys.stderr.write(err)
return ret
def monkey_patch():
""" Apply monkey patch to exec_command """
Context.Context.exec_command = my_exec_command
@@ -0,0 +1,36 @@
""" Change install names and ids to reflect changed path
"""
USAGE = """\
USAGE: repath_lib_names.py <old_path> <new_path> <lib_fname> [<lib_fname, ...]
"""
from os.path import islink, isfile
import sys
from delocate.tools import (get_install_names, set_install_name,
get_install_id, set_install_id)
def repath_lib(lib_fname, old_path, new_path):
install_id = get_install_id(lib_fname)
L = len(old_path)
if install_id and install_id.startswith(old_path):
set_install_id(lib_fname, new_path + install_id[L:])
for name in get_install_names(lib_fname):
if name.startswith(old_path):
set_install_name(lib_fname, name, new_path + name[L:])
def main():
if len(sys.argv) < 4:
print(USAGE)
sys.exit(-1)
old_path, new_path = sys.argv[1:3]
for lib_fname in sys.argv[3:]:
if isfile(lib_fname) and not islink(lib_fname):
repath_lib(lib_fname, old_path, new_path)
if __name__ == '__main__':
main()
@@ -0,0 +1,60 @@
""" Nosetests for travis2bashes script
"""
from __future__ import absolute_import, print_function
import os
import sys
sys.path.append(os.path.dirname(__file__))
from travisparse import get_envs, TravisError
from nose.tools import assert_equal, assert_true, assert_false, assert_raises
def test_get_envs():
# Get fetch of environment from .travis.yml
assert_equal(get_envs({}), '')
assert_equal(get_envs(dict(install = ['something'])), '')
yaml = dict(env = {'global': ['LATEST_TAG=1'],
'matrix': ['VERSION=2.7.8 NUMPY_VERSION=1.6.1',
'VERSION=3.3.5 NUMPY_VERSION=1.7.1',
'VERSION=3.4.1 NUMPY_VERSION=1.7.1']})
assert_equal(get_envs(yaml),
"""LATEST_TAG=1
VERSION=2.7.8 NUMPY_VERSION=1.6.1
""")
yaml = dict(env = {'matrix': ['VERSION=2.7.8 NUMPY_VERSION=1.6.1',
'VERSION=3.3.5 NUMPY_VERSION=1.7.1',
'VERSION=3.4.1 NUMPY_VERSION=1.7.1']})
assert_equal(get_envs(yaml),
"""VERSION=2.7.8 NUMPY_VERSION=1.6.1
""")
yaml = dict(env = ['ISOLATED=true', 'ISOLATED=false'])
assert_equal(get_envs(yaml),
"""ISOLATED=true
""")
# excludes too complicated
yaml = dict(env = {'matrix':
{'exclude':
[{'gemfile': 'Gemfile', 'rvm': '2.0.0'}]}})
assert_raises(TravisError, get_envs, yaml)
# includes too complicated
yaml = dict(env = {'matrix':
{'include':
[{'gemfile': 'gemfiles/Gemfile.rails-3.2.x',
'rvm': 'ruby-head',
'env': 'ISOLATED=false'}]}})
assert_raises(TravisError, get_envs, yaml)
# global implies matrix
yaml = dict(env = {'global': ['LATEST_TAG=1']})
assert_raises(TravisError, get_envs, yaml)
# one line is OK too
yaml = dict(env = {'global': 'LATEST_TAG=1',
'matrix': 'VERSION=3.3.1'})
assert_equal(get_envs(yaml),
"""LATEST_TAG=1
VERSION=3.3.1
""")
yaml = dict(env = 'MY_VAR=1')
assert_equal(get_envs(yaml),
"""MY_VAR=1
""")
@@ -0,0 +1,71 @@
""" Parse travis.yml file, partly
"""
import sys
if sys.version_info[0] > 2:
basestring = str
class TravisError(Exception):
pass
def get_yaml_entry(yaml_dict, name):
""" Get entry `name` from dict `yaml_dict`
Parameters
----------
yaml_dict : dict
dict or subdict from parsing .travis.yml file
name : str
key to analyze and return
Returns
-------
entry : None or list
If `name` not in `yaml_dict` return None. If key value is a string
return a single entry list. Otherwise return the key value.
"""
entry = yaml_dict.get(name)
if entry is None:
return None
if isinstance(entry, basestring):
return [entry]
return entry
def get_envs(yaml_dict):
""" Get first env combination from travis yaml dict
Parameters
----------
yaml_dict : dict
dict or subdict from parsing .travis.yml file
Returns
-------
bash_str : str
bash scripting lines as string
"""
env = get_yaml_entry(yaml_dict, 'env')
if env is None:
return ''
# Bare string
if isinstance(env, basestring):
return env + '\n'
# Simple list defining matrix
if isinstance(env, (list, tuple)):
return env[0] + '\n'
# More complex dictey things
globals, matrix = [get_yaml_entry(env, name)
for name in ('global', 'matrix')]
if hasattr(matrix, 'keys'):
raise TravisError('Oops, envs too complicated')
lines = []
if not globals is None:
if matrix is None:
raise TravisError('global section needs matrix section')
lines += globals
if not matrix is None:
lines.append(matrix[0])
return '\n'.join(lines) + '\n'
@@ -0,0 +1,254 @@
from __future__ import print_function
from os.path import split as psplit, join as pjoin
from subprocess import Popen, PIPE
def back_tick(cmd, ret_err=False, as_str=True, shell=False):
""" Run command `cmd`, return stdout, or stdout, stderr if `ret_err`
Roughly equivalent to ``check_output`` in Python 2.7
Parameters
----------
cmd : str
command to execute
ret_err : bool, optional
If True, return stderr in addition to stdout. If False, just return
stdout
as_str : bool, optional
Whether to decode outputs to unicode string on exit.
Returns
-------
out : str or tuple
If `ret_err` is False, return stripped string containing stdout from
`cmd`. If `ret_err` is True, return tuple of (stdout, stderr) where
``stdout`` is the stripped stdout, and ``stderr`` is the stripped
stderr.
Raises
------
Raises RuntimeError if command returns non-zero exit code
"""
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell)
out, err = proc.communicate()
retcode = proc.returncode
if retcode is None:
proc.terminate()
raise RuntimeError(cmd + ' process did not terminate')
if retcode != 0:
raise RuntimeError(cmd + ' process returned code %d' % retcode)
out = out.strip()
if as_str:
out = out.decode('latin-1')
if not ret_err:
return out
err = err.strip()
if as_str:
err = err.decode('latin-1')
return out, err
def seq_to_list(seq):
""" Convert non-sequence to 1 element sequence, tuples to lists
"""
if not isinstance(seq, (list, tuple)):
return [seq]
return list(seq)
class FilePackageMaker(object):
# all packages
instances = {}
def __init__(self, name, filename, build_cmd,
depends=(),
after=(),
patcher=None,
unpacked_sdir=None,
build_src_sdir='src',
):
""" Initialize object for creating unpack, patch, build tasks
Unpacking assumed to have no dependencies.
Patching assumed to depend only on the unpacking.
Build depends on packing / patching and on given dependencies
Parameters
----------
name : str
package name
filename : str
filename containing source archive to unpack
build_cmd : str or callable
command to build after extracting
depends : str or sequence, optional
depends for build
after : str or sequence, optional
names to set build to follow after (task name depends)
patcher : None or str or callable, optional
If str, a file containing a ``-p1`` patch for the sources. If
callable, then a rule to apply for patching. If None, don't patch
unpacked_sdir : str or None, optional
directory created by unpacking `filename`. If None we guess from
`filename`
build_src_sdir : str, optional
subdirectory in build directory into which to unpack
"""
self.name = name
self.filename = filename
self.build_cmd = build_cmd
_, fname = psplit(filename)
if fname.endswith('.tar.gz'):
self.unpack_cmd = 'tar zxf'
fname = fname[:-7]
elif fname.endswith('.tar.bz2'):
self.unpack_cmd = 'tar jxf'
fname = fname[:-8]
elif fname.endswith('.zip'):
self.unpack_cmd = 'unzip'
fname = fname[:-4]
else:
raise ValueError("Can't work out type of archive " + fname)
self.patcher = patcher
if unpacked_sdir is None: # Guess at output subdirectory
unpacked_sdir = fname
self.unpacked_sdir = unpacked_sdir
self.depends = seq_to_list(depends)
self.after = seq_to_list(after)
self.build_src_sdir = build_src_sdir
self._register_instance()
def _register_instance(self):
""" Register instance to class dictionary """
if self.name in self.instances:
raise ValueError('Name "{0}" already in instance '
'dict'.format(self.name))
self.instances[self.name] = self
def _unpack(self, bctx):
task_name = self.name + '.unpack'
dir_relpath = pjoin(self.build_src_sdir, self.unpacked_sdir)
dir_node = bctx.bldnode.make_node(dir_relpath)
archive_path = pjoin(bctx.srcnode.abspath(), self.filename)
rule = 'cd {dir_path} && {unpack_cmd} {archive_path}'.format(
dir_path = pjoin(bctx.bldnode.abspath(), self.build_src_sdir),
unpack_cmd = self.unpack_cmd,
archive_path = archive_path)
bctx(rule = rule,
target = dir_node,
name = task_name)
return task_name, dir_node
def unpack_patch_build(self, bctx):
""" Make task generators to unpack, patch and build
Parameters
----------
bctx : build context
Returns
-------
build_name : str
name of build task, for other tasks to depend on if necessary
dir_node : :class:`Node` instance
node pointing to directory containing unpacked and built sources
"""
task_name, dir_node = self._unpack(bctx)
if not self.patcher is None:
if hasattr(self.patcher, '__call__'): # patch function
rule = self.patcher
else: # assume filename in source tree
patch_node = bctx.srcnode.find_node(self.patcher)
if patch_node is None:
bctx.fatal('Patch file {0} does not exist'.format(
self.patcher))
rule = 'cd ${SRC} && patch -p1 < ' + patch_node.abspath()
task_name = self.name + '.patch'
bctx(
rule = rule,
source = dir_node,
name = task_name)
build_name = self.name + '.build'
bctx(
rule = self.build_cmd,
source = [dir_node] + self.depends,
after = [task_name] + self.after,
name = build_name)
return build_name, dir_node
class GitPackageMaker(FilePackageMaker):
# all packages
instances = {}
def __init__(self, name, commit, build_cmd,
depends=(),
after=(),
patcher=None,
out_sdir=None,
git_sdir=None,
build_src_sdir='src',
):
""" Initialize object for creating unpack, patch, build tasks
* Unpacking assumed to have no dependencies.
* Patching assumed to depend only on the unpacking.
* Build depends on packing / patching and on given dependencies
Parameters
----------
name : str
package name
commit : str
identifier for commit to unarchive
build_cmd : str or callable
command to build after extracting
depends : str or sequence, optional
depends for build
after : str or sequence, optional
names to set build to follow after (task name depends)
patcher : None or str or callable, optional
If str, a file containing a ``-p1`` patch for the sources. If
callable, then a rule to apply for patching. If None, don't patch
out_sdir : None or str, optional
subdirectory in `build_src_sdir` in which to unpack. If None, use
`name`
git_sdir : str or None, optional
directory containing git repository. Defaults to `name`
build_src_sdir : str, optional
subdirectory in build directory into which to unpack
"""
self.name = name
self.commit = commit
self.build_cmd = build_cmd
self.patcher = patcher
if git_sdir is None:
git_sdir = name
self.git_sdir = git_sdir
self.depends = seq_to_list(depends)
self.after = seq_to_list(after)
self.build_src_sdir = build_src_sdir
self.out_sdir = name if out_sdir is None else out_sdir
self._register_instance()
def _unpack(self, bctx):
src_path = bctx.srcnode.abspath()
bld_path = bctx.bldnode.abspath()
task_name = self.name + '.unpack'
dir_relpath = pjoin(self.build_src_sdir, self.out_sdir)
dir_node = bctx.bldnode.make_node(dir_relpath)
git_dir = pjoin(src_path, self.git_sdir)
bctx(
rule = ('cd {git_dir} && '
'git archive --prefix={dir_relpath}/ {commit} | '
'( cd {bld_path} && tar x )'.format(
git_dir = git_dir,
dir_relpath = dir_relpath,
commit = self.commit,
bld_path = bld_path)),
target = dir_node,
name = task_name)
return task_name, dir_node