summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <xistence@0x58.com>2022-05-15 20:26:49 -0600
committerGitHub <noreply@github.com>2022-05-15 20:26:49 -0600
commitd4287b56e56b765c9b4fa463cc4dd1191e3f9232 (patch)
tree03bff17fa2a61991aedb4c18fb2a5a1d508c73ed
parentac91794dfb7617b473c9d06d04900debfcdf585e (diff)
parentf18450e62b193782648ddba01355f89d36cfc726 (diff)
downloadpastedeploy-git-d4287b56e56b765c9b4fa463cc4dd1191e3f9232.tar.gz
Merge pull request #36 from Pylons/blackify
-rw-r--r--.flake812
-rw-r--r--MANIFEST.in1
-rw-r--r--docs/conf.py48
-rw-r--r--pyproject.toml23
-rw-r--r--src/paste/__init__.py5
-rw-r--r--src/paste/deploy/__init__.py2
-rw-r--r--src/paste/deploy/config.py63
-rw-r--r--src/paste/deploy/loadwsgi.py372
-rw-r--r--src/paste/deploy/paster_templates.py18
-rw-r--r--src/paste/deploy/util.py6
-rw-r--r--tests/__init__.py19
-rw-r--r--tests/fake_packages/FakeApp.egg/fakeapp/apps.py16
-rw-r--r--tests/fake_packages/FakeApp.egg/fakeapp/configapps.py4
-rw-r--r--tests/fake_packages/FakeApp.egg/setup.py14
-rw-r--r--tests/fixture.py17
-rw-r--r--tests/test_basic_app.py24
-rw-r--r--tests/test_config.py77
-rw-r--r--tests/test_config_middleware.py1
-rw-r--r--tests/test_converters.py3
-rw-r--r--tests/test_filter.py28
-rw-r--r--tests/test_load_package.py3
-rw-r--r--tox.ini16
22 files changed, 474 insertions, 298 deletions
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..641a1bd
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,12 @@
+[flake8]
+max-line-length = 88
+ignore =
+ # E203: whitespace before ':' (black fails to be PEP8 compliant)
+ E203
+ # E731: do not assign a lambda expression, use a def
+ E731
+ # W503: line break before binary operator (flake8 is not PEP8 compliant)
+ W503
+ # W504: line break after binary operator (flake8 is not PEP8 compliant)
+ W504
+show-source = True
diff --git a/MANIFEST.in b/MANIFEST.in
index 1108a6c..ce3529a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -8,6 +8,7 @@ include README.rst
include contributing.md
include license.txt
include .coveragerc
+include .flake8
include pytest.ini
include tox.ini
include rtd.txt
diff --git a/docs/conf.py b/docs/conf.py
index 00d8761..bf4faa8 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -16,7 +16,7 @@ import pkg_resources
import pylons_sphinx_themes
# If your extensions are in another directory, add it here.
-#sys.path.append('some/directory')
+# sys.path.append('some/directory')
# General configuration
# ---------------------
@@ -58,23 +58,23 @@ release = version
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
-#today = ''
+# today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
-#unused_docs = ['include/contact.txt', 'include/reference_header.txt']
+# unused_docs = ['include/contact.txt', 'include/reference_header.txt']
# If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
+# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
-#add_module_names = True
+# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
-#show_authors = False
+# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
@@ -107,27 +107,29 @@ html_last_updated_fmt = '%b %d, %Y'
smartquotes = False
# Content template for the index page.
-#html_index = ''
+# html_index = ''
# Custom sidebar templates, maps document names to template names.
# Control display of sidebars
-html_sidebars = { '**': [
- 'localtoc.html',
- 'ethicalads.html',
- 'relations.html',
- 'sourcelink.html',
- 'searchbox.html',
-] }
+html_sidebars = {
+ '**': [
+ 'localtoc.html',
+ 'ethicalads.html',
+ 'relations.html',
+ 'sourcelink.html',
+ 'searchbox.html',
+ ]
+}
# Additional templates that should be rendered to pages, maps page names to
# template names.
-#html_additional_pages = {}
+# html_additional_pages = {}
# If false, no module index is generated.
-#html_use_modindex = True
+# html_use_modindex = True
# If true, the reST sources are included in the HTML build as _sources/<name>.
-#html_copy_source = True
+# html_copy_source = True
# Output file base name for HTML help builder.
htmlhelp_basename = 'PasteDeploydoc'
@@ -137,20 +139,20 @@ htmlhelp_basename = 'PasteDeploydoc'
# ------------------------
# The paper size ('letter' or 'a4').
-#latex_paper_size = 'letter'
+# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
-#latex_font_size = '10pt'
+# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
-#latex_documents = []
+# latex_documents = []
# Additional stuff for the LaTeX preamble.
-#latex_preamble = ''
+# latex_preamble = ''
# Documents to append as an appendix to all manuals.
-#latex_appendices = []
+# latex_appendices = []
# If false, no module index is generated.
-#latex_use_modindex = True
+# latex_use_modindex = True
diff --git a/pyproject.toml b/pyproject.toml
index 89a9175..640a0d5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,3 +1,26 @@
[build-system]
requires = ["setuptools >= 41"]
build-backend = "setuptools.build_meta"
+
+[tool.black]
+target-version = ['py37', 'py38', 'py39', 'py310']
+skip-string-normalization = true
+exclude = '''
+/(
+ \.git
+ | .tox
+)/
+'''
+
+[tool.isort]
+profile = "black"
+multi_line_output = 3
+src_paths = ["src", "tests"]
+skip_glob = ["docs/*"]
+include_trailing_comma = true
+force_grid_wrap = false
+combine_as_imports = true
+line_length = 88
+force_sort_within_sections = true
+default_section = "THIRDPARTY"
+known_first_party = "paste.deploy"
diff --git a/src/paste/__init__.py b/src/paste/__init__.py
index cdb6121..d31480b 100644
--- a/src/paste/__init__.py
+++ b/src/paste/__init__.py
@@ -2,11 +2,13 @@
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
try:
import pkg_resources
+
pkg_resources.declare_namespace(__name__)
except ImportError:
# don't prevent use of paste if pkg_resources isn't installed
from pkgutil import extend_path
- __path__ = extend_path(__path__, __name__)
+
+ __path__ = extend_path(__path__, __name__)
try:
import modulefinder
@@ -15,4 +17,3 @@ except ImportError:
else:
for p in __path__:
modulefinder.AddPackagePath(__name__, p)
-
diff --git a/src/paste/deploy/__init__.py b/src/paste/deploy/__init__.py
index 94c63a8..cacb9a6 100644
--- a/src/paste/deploy/__init__.py
+++ b/src/paste/deploy/__init__.py
@@ -1,3 +1,3 @@
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
-from paste.deploy.loadwsgi import *
+from paste.deploy.loadwsgi import * # noqa F401,F403
diff --git a/src/paste/deploy/config.py b/src/paste/deploy/config.py
index f448350..0dae282 100644
--- a/src/paste/deploy/config.py
+++ b/src/paste/deploy/config.py
@@ -1,8 +1,8 @@
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
"""Paste Configuration Middleware and Objects"""
-import threading
import re
+import threading
# Loaded lazily
wsgilib = None
@@ -47,7 +47,7 @@ class DispatchingConfig:
self.dispatching_id = 0
while 1:
self._local_key = 'paste.processconfig_%i' % self.dispatching_id
- if not self._local_key in local_dict():
+ if self._local_key not in local_dict():
break
self.dispatching_id += 1
finally:
@@ -84,8 +84,8 @@ class DispatchingConfig:
if conf is not None and popped is not conf:
raise AssertionError(
"The config popped (%s) is not the same as the config "
- "expected (%s)"
- % (popped, conf))
+ "expected (%s)" % (popped, conf)
+ )
def push_process_config(self, conf):
"""
@@ -101,8 +101,8 @@ class DispatchingConfig:
conf = self.current_conf()
if conf is None:
raise AttributeError(
- "No configuration has been registered for this process "
- "or thread")
+ "No configuration has been registered for this process or thread"
+ )
return getattr(conf, attr)
def current_conf(self):
@@ -119,8 +119,8 @@ class DispatchingConfig:
conf = self.current_conf()
if conf is None:
raise TypeError(
- "No configuration has been registered for this process "
- "or thread")
+ "No configuration has been registered for this process or thread"
+ )
return conf[key]
def __contains__(self, key):
@@ -132,6 +132,7 @@ class DispatchingConfig:
conf = self.current_conf()
conf[key] = value
+
CONFIG = DispatchingConfig()
@@ -155,6 +156,7 @@ class ConfigMiddleware:
global wsgilib
if wsgilib is None:
import pkg_resources
+
pkg_resources.require('Paste')
from paste import wsgilib
popped_config = None
@@ -180,8 +182,10 @@ class ConfigMiddleware:
environ['paste.config'] = popped_config
return app_iter
else:
+
def close_config():
CONFIG.pop_thread_config(conf)
+
new_app_iter = wsgilib.add_close(app_iter, close_config)
return new_app_iter
@@ -191,6 +195,7 @@ def make_config_filter(app, global_conf, **local_conf):
conf.update(local_conf)
return ConfigMiddleware(app, conf)
+
make_config_middleware = ConfigMiddleware.__doc__
@@ -246,9 +251,16 @@ class PrefixMiddleware:
You can also use ``scheme`` to explicitly set the scheme (like
``scheme = https``).
"""
- def __init__(self, app, global_conf=None, prefix='/',
- translate_forwarded_server=True,
- force_port=None, scheme=None):
+
+ def __init__(
+ self,
+ app,
+ global_conf=None,
+ prefix='/',
+ translate_forwarded_server=True,
+ force_port=None,
+ scheme=None,
+ ):
self.app = app
self.prefix = prefix.rstrip('/')
self.translate_forwarded_server = translate_forwarded_server
@@ -265,11 +277,17 @@ class PrefixMiddleware:
environ['SCRIPT_NAME'] = self.prefix
if self.translate_forwarded_server:
if 'HTTP_X_FORWARDED_SERVER' in environ:
- environ['SERVER_NAME'] = environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_SERVER').split(',')[0]
+ environ['SERVER_NAME'] = environ['HTTP_HOST'] = environ.pop(
+ 'HTTP_X_FORWARDED_SERVER'
+ ).split(',')[0]
if 'HTTP_X_FORWARDED_HOST' in environ:
- environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_HOST').split(',')[0]
+ environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_HOST').split(',')[
+ 0
+ ]
if 'HTTP_X_FORWARDED_FOR' in environ:
- environ['REMOTE_ADDR'] = environ.pop('HTTP_X_FORWARDED_FOR').split(',')[0]
+ environ['REMOTE_ADDR'] = environ.pop('HTTP_X_FORWARDED_FOR').split(',')[
+ 0
+ ]
if 'HTTP_X_FORWARDED_SCHEME' in environ:
environ['wsgi.url_scheme'] = environ.pop('HTTP_X_FORWARDED_SCHEME')
elif 'HTTP_X_FORWARDED_PROTO' in environ:
@@ -292,14 +310,23 @@ class PrefixMiddleware:
def make_prefix_middleware(
- app, global_conf, prefix='/',
+ app,
+ global_conf,
+ prefix='/',
translate_forwarded_server=True,
- force_port=None, scheme=None):
+ force_port=None,
+ scheme=None,
+):
from paste.deploy.converters import asbool
+
translate_forwarded_server = asbool(translate_forwarded_server)
return PrefixMiddleware(
- app, prefix=prefix,
+ app,
+ prefix=prefix,
translate_forwarded_server=translate_forwarded_server,
- force_port=force_port, scheme=scheme)
+ force_port=force_port,
+ scheme=scheme,
+ )
+
make_prefix_middleware.__doc__ = PrefixMiddleware.__doc__
diff --git a/src/paste/deploy/loadwsgi.py b/src/paste/deploy/loadwsgi.py
index c5471e5..482b339 100644
--- a/src/paste/deploy/loadwsgi.py
+++ b/src/paste/deploy/loadwsgi.py
@@ -2,11 +2,11 @@
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
from configparser import ConfigParser
import os
-import pkg_resources
import re
import sys
from urllib.parse import unquote
+import pkg_resources
from paste.deploy.util import fix_call, lookup_object
@@ -14,7 +14,7 @@ __all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig']
############################################################
-## Utility functions
+# Utility functions
############################################################
@@ -54,7 +54,6 @@ def _flatten(lst):
class NicerConfigParser(ConfigParser):
-
def __init__(self, filename, *args, **kw):
ConfigParser.__init__(self, *args, **kw)
self.filename = filename
@@ -80,8 +79,9 @@ class NicerConfigParser(ConfigParser):
def before_get(self, parser, section, option, value, defaults):
try:
- return self._original.before_get(parser, section, option,
- value, defaults)
+ return self._original.before_get(
+ parser, section, option, value, defaults
+ )
except Exception:
e = sys.exc_info()[1]
args = list(e.args)
@@ -92,7 +92,7 @@ class NicerConfigParser(ConfigParser):
############################################################
-## Object types
+# Object types
############################################################
@@ -109,33 +109,43 @@ class _ObjectType:
def __repr__(self):
return '<{} protocols={!r} prefixes={!r}>'.format(
- self.name, self.egg_protocols, self.config_prefixes)
+ self.name, self.egg_protocols, self.config_prefixes
+ )
def invoke(self, context):
assert context.protocol in _flatten(self.egg_protocols)
- return fix_call(context.object,
- context.global_conf, **context.local_conf)
+ return fix_call(context.object, context.global_conf, **context.local_conf)
class _App(_ObjectType):
name = 'application'
- egg_protocols = ['paste.app_factory', 'paste.composite_factory',
- 'paste.composit_factory']
- config_prefixes = [['app', 'application'], ['composite', 'composit'],
- 'pipeline', 'filter-app']
+ egg_protocols = [
+ 'paste.app_factory',
+ 'paste.composite_factory',
+ 'paste.composit_factory',
+ ]
+ config_prefixes = [
+ ['app', 'application'],
+ ['composite', 'composit'],
+ 'pipeline',
+ 'filter-app',
+ ]
def invoke(self, context):
- if context.protocol in ('paste.composit_factory',
- 'paste.composite_factory'):
- return fix_call(context.object,
- context.loader, context.global_conf,
- **context.local_conf)
+ if context.protocol in ('paste.composit_factory', 'paste.composite_factory'):
+ return fix_call(
+ context.object,
+ context.loader,
+ context.global_conf,
+ **context.local_conf,
+ )
elif context.protocol == 'paste.app_factory':
return fix_call(context.object, context.global_conf, **context.local_conf)
else:
assert 0, "Protocol %r unknown" % context.protocol
+
APP = _App()
@@ -146,18 +156,20 @@ class _Filter(_ObjectType):
def invoke(self, context):
if context.protocol == 'paste.filter_factory':
- return fix_call(context.object,
- context.global_conf, **context.local_conf)
+ return fix_call(context.object, context.global_conf, **context.local_conf)
elif context.protocol == 'paste.filter_app_factory':
+
def filter_wrapper(wsgi_app):
# This should be an object, so it has a nicer __repr__
- return fix_call(context.object,
- wsgi_app, context.global_conf,
- **context.local_conf)
+ return fix_call(
+ context.object, wsgi_app, context.global_conf, **context.local_conf
+ )
+
return filter_wrapper
else:
assert 0, "Protocol %r unknown" % context.protocol
+
FILTER = _Filter()
@@ -168,18 +180,20 @@ class _Server(_ObjectType):
def invoke(self, context):
if context.protocol == 'paste.server_factory':
- return fix_call(context.object,
- context.global_conf, **context.local_conf)
+ return fix_call(context.object, context.global_conf, **context.local_conf)
elif context.protocol == 'paste.server_runner':
+
def server_wrapper(wsgi_app):
# This should be an object, so it has a nicer __repr__
- return fix_call(context.object,
- wsgi_app, context.global_conf,
- **context.local_conf)
+ return fix_call(
+ context.object, wsgi_app, context.global_conf, **context.local_conf
+ )
+
return server_wrapper
else:
assert 0, "Protocol %r unknown" % context.protocol
+
SERVER = _Server()
@@ -196,6 +210,7 @@ class _PipeLine(_ObjectType):
app = filter(app)
return app
+
PIPELINE = _PipeLine()
@@ -207,6 +222,7 @@ class _FilterApp(_ObjectType):
filter = context.filter_context.create()
return filter(next_app)
+
FILTER_APP = _FilterApp()
@@ -222,13 +238,15 @@ class _FilterWith(_App):
# filtering a filter
def composed(app):
return filter(filtered(app))
+
return composed
+
FILTER_WITH = _FilterWith()
############################################################
-## Loaders
+# Loaders
############################################################
@@ -245,24 +263,23 @@ def loadserver(uri, name=None, **kw):
def appconfig(uri, name=None, relative_to=None, global_conf=None):
- context = loadcontext(APP, uri, name=name,
- relative_to=relative_to,
- global_conf=global_conf)
+ context = loadcontext(
+ APP, uri, name=name, relative_to=relative_to, global_conf=global_conf
+ )
return context.config()
+
_loaders = {}
-def loadobj(object_type, uri, name=None, relative_to=None,
- global_conf=None):
+def loadobj(object_type, uri, name=None, relative_to=None, global_conf=None):
context = loadcontext(
- object_type, uri, name=name, relative_to=relative_to,
- global_conf=global_conf)
+ object_type, uri, name=name, relative_to=relative_to, global_conf=global_conf
+ )
return context.create()
-def loadcontext(object_type, uri, name=None, relative_to=None,
- global_conf=None):
+def loadcontext(object_type, uri, name=None, relative_to=None, global_conf=None):
if '#' in uri:
if name is None:
uri, name = uri.split('#', 1)
@@ -277,16 +294,21 @@ def loadcontext(object_type, uri, name=None, relative_to=None,
scheme = scheme.lower()
if scheme not in _loaders:
raise LookupError(
- "URI scheme not known: %r (from %s)"
- % (scheme, ', '.join(_loaders.keys())))
+ "URI scheme not known: {!r} (from {})".format(
+ scheme, ', '.join(_loaders.keys())
+ )
+ )
return _loaders[scheme](
object_type,
- uri, path, name=name, relative_to=relative_to,
- global_conf=global_conf)
+ uri,
+ path,
+ name=name,
+ relative_to=relative_to,
+ global_conf=global_conf,
+ )
-def _loadconfig(object_type, uri, path, name, relative_to,
- global_conf):
+def _loadconfig(object_type, uri, path, name, relative_to, global_conf):
isabs = os.path.isabs(path)
# De-Windowsify the paths:
path = path.replace('\\', '/')
@@ -294,7 +316,8 @@ def _loadconfig(object_type, uri, path, name, relative_to,
if not relative_to:
raise ValueError(
"Cannot resolve relative uri %r; no relative_to keyword "
- "argument given" % uri)
+ "argument given" % uri
+ )
relative_to = relative_to.replace('\\', '/')
if relative_to.endswith('/'):
path = relative_to + path
@@ -308,55 +331,49 @@ def _loadconfig(object_type, uri, path, name, relative_to,
loader.update_defaults(global_conf, overwrite=False)
return loader.get_context(object_type, name, global_conf)
+
_loaders['config'] = _loadconfig
-def _loadegg(object_type, uri, spec, name, relative_to,
- global_conf):
+def _loadegg(object_type, uri, spec, name, relative_to, global_conf):
loader = EggLoader(spec)
return loader.get_context(object_type, name, global_conf)
+
_loaders['egg'] = _loadegg
-def _loadfunc(object_type, uri, spec, name, relative_to,
- global_conf):
+def _loadfunc(object_type, uri, spec, name, relative_to, global_conf):
loader = FuncLoader(spec)
return loader.get_context(object_type, name, global_conf)
+
_loaders['call'] = _loadfunc
############################################################
-## Loaders
+# Loaders
############################################################
class _Loader:
-
def get_app(self, name=None, global_conf=None):
- return self.app_context(
- name=name, global_conf=global_conf).create()
+ return self.app_context(name=name, global_conf=global_conf).create()
def get_filter(self, name=None, global_conf=None):
- return self.filter_context(
- name=name, global_conf=global_conf).create()
+ return self.filter_context(name=name, global_conf=global_conf).create()
def get_server(self, name=None, global_conf=None):
- return self.server_context(
- name=name, global_conf=global_conf).create()
+ return self.server_context(name=name, global_conf=global_conf).create()
def app_context(self, name=None, global_conf=None):
- return self.get_context(
- APP, name=name, global_conf=global_conf)
+ return self.get_context(APP, name=name, global_conf=global_conf)
def filter_context(self, name=None, global_conf=None):
- return self.get_context(
- FILTER, name=name, global_conf=global_conf)
+ return self.get_context(FILTER, name=name, global_conf=global_conf)
def server_context(self, name=None, global_conf=None):
- return self.get_context(
- SERVER, name=name, global_conf=global_conf)
+ return self.get_context(SERVER, name=name, global_conf=global_conf)
_absolute_re = re.compile(r'^[a-zA-Z]+:')
@@ -370,13 +387,12 @@ class _Loader:
class ConfigLoader(_Loader):
-
def __init__(self, filename):
self.filename = filename = filename.strip()
defaults = {
'here': os.path.dirname(os.path.abspath(filename)),
- '__file__': os.path.abspath(filename)
- }
+ '__file__': os.path.abspath(filename),
+ }
self.parser = NicerConfigParser(filename, defaults=defaults)
self.parser.optionxform = str # Don't lower-case keys
with open(filename) as f:
@@ -390,11 +406,13 @@ class ConfigLoader(_Loader):
def get_context(self, object_type, name=None, global_conf=None):
if self.absolute_name(name):
- return loadcontext(object_type, name,
- relative_to=os.path.dirname(self.filename),
- global_conf=global_conf)
- section = self.find_config_section(
- object_type, name=name)
+ return loadcontext(
+ object_type,
+ name,
+ relative_to=os.path.dirname(self.filename),
+ global_conf=global_conf,
+ )
+ section = self.find_config_section(object_type, name=name)
defaults = self.parser.defaults()
_global_conf = defaults.copy()
if global_conf is not None:
@@ -406,8 +424,9 @@ class ConfigLoader(_Loader):
for option in self.parser.options(section):
if option.startswith('set '):
name = option[4:].strip()
- global_additions[name] = global_conf[name] = (
- self.parser.get(section, option))
+ global_additions[name] = global_conf[name] = self.parser.get(
+ section, option
+ )
elif option.startswith('get '):
name = option[4:].strip()
get_from_globals[name] = self.parser.get(section, option)
@@ -428,40 +447,51 @@ class ConfigLoader(_Loader):
del local_conf['require']
if section.startswith('filter-app:'):
context = self._filter_app_context(
- object_type, section, name=name,
- global_conf=global_conf, local_conf=local_conf,
- global_additions=global_additions)
+ object_type,
+ section,
+ name=name,
+ global_conf=global_conf,
+ local_conf=local_conf,
+ global_additions=global_additions,
+ )
elif section.startswith('pipeline:'):
context = self._pipeline_app_context(
- object_type, section, name=name,
- global_conf=global_conf, local_conf=local_conf,
- global_additions=global_additions)
+ object_type,
+ section,
+ name=name,
+ global_conf=global_conf,
+ local_conf=local_conf,
+ global_additions=global_additions,
+ )
elif 'use' in local_conf:
context = self._context_from_use(
- object_type, local_conf, global_conf, global_additions,
- section)
+ object_type, local_conf, global_conf, global_additions, section
+ )
else:
context = self._context_from_explicit(
- object_type, local_conf, global_conf, global_additions,
- section)
+ object_type, local_conf, global_conf, global_additions, section
+ )
if filter_with is not None:
filter_with_context = LoaderContext(
obj=None,
object_type=FILTER_WITH,
protocol=None,
- global_conf=global_conf, local_conf=local_conf,
- loader=self)
+ global_conf=global_conf,
+ local_conf=local_conf,
+ loader=self,
+ )
filter_with_context.filter_context = self.filter_context(
- name=filter_with, global_conf=global_conf)
+ name=filter_with, global_conf=global_conf
+ )
filter_with_context.next_context = context
return filter_with_context
return context
- def _context_from_use(self, object_type, local_conf, global_conf,
- global_additions, section):
+ def _context_from_use(
+ self, object_type, local_conf, global_conf, global_additions, section
+ ):
use = local_conf.pop('use')
- context = self.get_context(
- object_type, name=use, global_conf=global_conf)
+ context = self.get_context(object_type, name=use, global_conf=global_conf)
context.global_conf.update(global_additions)
context.local_conf.update(local_conf)
if '__file__' in global_conf:
@@ -485,8 +515,9 @@ class ConfigLoader(_Loader):
return context
- def _context_from_explicit(self, object_type, local_conf, global_conf,
- global_addition, section):
+ def _context_from_explicit(
+ self, object_type, local_conf, global_conf, global_addition, section
+ ):
possible = []
for protocol_options in object_type.egg_protocols:
for protocol in protocol_options:
@@ -495,59 +526,59 @@ class ConfigLoader(_Loader):
break
if len(possible) > 1:
raise LookupError(
- "Multiple protocols given in section %r: %s"
- % (section, possible))
+ f"Multiple protocols given in section {section!r}: {possible}"
+ )
if not possible:
- raise LookupError(
- "No loader given in section %r" % section)
+ raise LookupError("No loader given in section %r" % section)
found_protocol, found_expr = possible[0]
del local_conf[found_protocol]
value = import_string(found_expr)
context = LoaderContext(
- value, object_type, found_protocol,
- global_conf, local_conf, self)
+ value, object_type, found_protocol, global_conf, local_conf, self
+ )
return context
- def _filter_app_context(self, object_type, section, name,
- global_conf, local_conf, global_additions):
+ def _filter_app_context(
+ self, object_type, section, name, global_conf, local_conf, global_additions
+ ):
if 'next' not in local_conf:
raise LookupError(
"The [%s] section in %s is missing a 'next' setting"
- % (section, self.filename))
+ % (section, self.filename)
+ )
next_name = local_conf.pop('next')
- context = LoaderContext(None, FILTER_APP, None, global_conf,
- local_conf, self)
- context.next_context = self.get_context(
- APP, next_name, global_conf)
+ context = LoaderContext(None, FILTER_APP, None, global_conf, local_conf, self)
+ context.next_context = self.get_context(APP, next_name, global_conf)
if 'use' in local_conf:
context.filter_context = self._context_from_use(
- FILTER, local_conf, global_conf, global_additions,
- section)
+ FILTER, local_conf, global_conf, global_additions, section
+ )
else:
context.filter_context = self._context_from_explicit(
- FILTER, local_conf, global_conf, global_additions,
- section)
+ FILTER, local_conf, global_conf, global_additions, section
+ )
return context
- def _pipeline_app_context(self, object_type, section, name,
- global_conf, local_conf, global_additions):
+ def _pipeline_app_context(
+ self, object_type, section, name, global_conf, local_conf, global_additions
+ ):
if 'pipeline' not in local_conf:
raise LookupError(
"The [%s] section in %s is missing a 'pipeline' setting"
- % (section, self.filename))
+ % (section, self.filename)
+ )
pipeline = local_conf.pop('pipeline').split()
if local_conf:
raise LookupError(
"The [%s] pipeline section in %s has extra "
"(disallowed) settings: %s"
- % (section, self.filename, ', '.join(local_conf.keys())))
- context = LoaderContext(None, PIPELINE, None, global_conf,
- local_conf, self)
- context.app_context = self.get_context(
- APP, pipeline[-1], global_conf)
+ % (section, self.filename, ', '.join(local_conf.keys()))
+ )
+ context = LoaderContext(None, PIPELINE, None, global_conf, local_conf, self)
+ context.app_context = self.get_context(APP, pipeline[-1], global_conf)
context.filter_contexts = [
- self.get_context(FILTER, name, global_conf)
- for name in pipeline[:-1]]
+ self.get_context(FILTER, name, global_conf) for name in pipeline[:-1]
+ ]
return context
def find_config_section(self, object_type, name=None):
@@ -562,24 +593,30 @@ class ConfigLoader(_Loader):
possible = []
for name_options in object_type.config_prefixes:
for name_prefix in name_options:
- found = self._find_sections(
- self.parser.sections(), name_prefix, name)
+ found = self._find_sections(self.parser.sections(), name_prefix, name)
if found:
possible.extend(found)
break
if not possible:
raise LookupError(
"No section %r (prefixed by %s) found in config %s"
- % (name,
- ' or '.join(map(repr, _flatten(object_type.config_prefixes))),
- self.filename))
+ % (
+ name,
+ ' or '.join(map(repr, _flatten(object_type.config_prefixes))),
+ self.filename,
+ )
+ )
if len(possible) > 1:
raise LookupError(
"Ambiguous section names %r for section %r (prefixed by %s) "
"found in config %s"
- % (possible, name,
- ' or '.join(map(repr, _flatten(object_type.config_prefixes))),
- self.filename))
+ % (
+ possible,
+ name,
+ ' or '.join(map(repr, _flatten(object_type.config_prefixes))),
+ self.filename,
+ )
+ )
return possible[0]
def _find_sections(self, sections, name_prefix, name):
@@ -590,30 +627,31 @@ class ConfigLoader(_Loader):
name = 'main'
for section in sections:
if section.startswith(name_prefix + ':'):
- if section[len(name_prefix) + 1:].strip() == name:
+ if section[len(name_prefix) + 1 :].strip() == name:
found.append(section)
return found
class EggLoader(_Loader):
-
def __init__(self, spec):
self.spec = spec
def get_context(self, object_type, name=None, global_conf=None):
if self.absolute_name(name):
- return loadcontext(object_type, name,
- global_conf=global_conf)
+ return loadcontext(object_type, name, global_conf=global_conf)
entry_point, protocol, ep_name = self.find_egg_entry_point(
- object_type, name=name)
+ object_type, name=name
+ )
return LoaderContext(
entry_point,
object_type,
protocol,
- global_conf or {}, {},
+ global_conf or {},
+ {},
self,
distribution=pkg_resources.get_distribution(self.spec),
- entry_point_name=ep_name)
+ entry_point_name=ep_name,
+ )
def find_egg_entry_point(self, object_type, name=None):
"""
@@ -626,10 +664,7 @@ class EggLoader(_Loader):
for protocol_options in object_type.egg_protocols:
for protocol in protocol_options:
pkg_resources.require(self.spec)
- entry = pkg_resources.get_entry_info(
- self.spec,
- protocol,
- name)
+ entry = pkg_resources.get_entry_info(self.spec, protocol, name)
if entry is not None:
possible.append((entry.load(), protocol, entry.name))
break
@@ -639,30 +674,49 @@ class EggLoader(_Loader):
raise LookupError(
"Entry point %r not found in egg %r (dir: %s; protocols: %s; "
"entry_points: %s)"
- % (name, self.spec,
- dist.location,
- ', '.join(_flatten(object_type.egg_protocols)),
- ', '.join(_flatten([
- list((pkg_resources.get_entry_info(self.spec, prot, name) or {}).keys())
- for prot in protocol_options] or '(no entry points)'))))
+ % (
+ name,
+ self.spec,
+ dist.location,
+ ', '.join(_flatten(object_type.egg_protocols)),
+ ', '.join(
+ _flatten(
+ [
+ list(
+ (
+ pkg_resources.get_entry_info(
+ self.spec, prot, name
+ )
+ or {}
+ ).keys()
+ )
+ for prot in protocol_options
+ ]
+ or '(no entry points)'
+ )
+ ),
+ )
+ )
if len(possible) > 1:
raise LookupError(
"Ambiguous entry points for %r in egg %r (protocols: %s)"
- % (name, self.spec, ', '.join(_flatten(protocol_options))))
+ % (name, self.spec, ', '.join(_flatten(protocol_options)))
+ )
return possible[0]
class FuncLoader(_Loader):
- """ Loader that supports specifying functions inside modules, without
+ """Loader that supports specifying functions inside modules, without
using eggs at all. Configuration should be in the format:
use = call:my.module.path:function_name
-
+
Dot notation is supported in both the module and function name, e.g.:
use = call:my.module.path:object.method
"""
+
def __init__(self, spec):
self.spec = spec
- if not ':' in spec:
+ if ':' not in spec:
raise LookupError("Configuration not in format module:function")
def get_context(self, object_type, name=None, global_conf=None):
@@ -670,22 +724,29 @@ class FuncLoader(_Loader):
return LoaderContext(
obj,
object_type,
- None, # determine protocol from section type
+ None, # determine protocol from section type
global_conf or {},
{},
self,
- )
+ )
class LoaderContext:
-
- def __init__(self, obj, object_type, protocol,
- global_conf, local_conf, loader,
- distribution=None, entry_point_name=None):
+ def __init__(
+ self,
+ obj,
+ object_type,
+ protocol,
+ global_conf,
+ local_conf,
+ loader,
+ distribution=None,
+ entry_point_name=None,
+ ):
self.object = obj
self.object_type = object_type
self.protocol = protocol
- #assert protocol in _flatten(object_type.egg_protocols), (
+ # assert protocol in _flatten(object_type.egg_protocols), (
# "Bad protocol %r; should be one of %s"
# % (protocol, ', '.join(map(repr, _flatten(object_type.egg_protocols)))))
self.global_conf = global_conf
@@ -710,4 +771,5 @@ class AttrDict(dict):
"""
A dictionary that can be assigned to.
"""
+
pass
diff --git a/src/paste/deploy/paster_templates.py b/src/paste/deploy/paster_templates.py
index edfa97a..063b536 100644
--- a/src/paste/deploy/paster_templates.py
+++ b/src/paste/deploy/paster_templates.py
@@ -20,15 +20,23 @@ class PasteDeploy(Template):
os.path.join(output_dir, 'setup.py'),
'Extra requirements',
'%r,\n' % prereq,
- indent=True)
+ indent=True,
+ )
command.insert_into_file(
os.path.join(output_dir, 'setup.py'),
'Entry points',
- (' [paste.app_factory]\n'
- ' main = %(package)s.wsgiapp:make_app\n') % vars,
- indent=False)
+ (
+ ' [paste.app_factory]\n'
+ ' main = %(package)s.wsgiapp:make_app\n'
+ )
+ % vars,
+ indent=False,
+ )
if command.verbose:
print('*' * 72)
- print('* Run "paster serve docs/devel_config.ini" to run the sample application')
+ print(
+ '* Run "paster serve docs/devel_config.ini" to run the sample'
+ ' application'
+ )
print('* on http://localhost:8080')
print('*' * 72)
diff --git a/src/paste/deploy/util.py b/src/paste/deploy/util.py
index d30466a..6bd6132 100644
--- a/src/paste/deploy/util.py
+++ b/src/paste/deploy/util.py
@@ -20,9 +20,11 @@ def fix_type_error(exc_info, callable, varargs, kwargs):
"""
if exc_info is None:
exc_info = sys.exc_info()
- if (exc_info[0] != TypeError
+ if (
+ exc_info[0] != TypeError
or str(exc_info[1]).find('arguments') == -1
- or getattr(exc_info[1], '_type_error_fixed', False)):
+ or getattr(exc_info[1], '_type_error_fixed', False)
+ ):
return exc_info
exc_info[1]._type_error_fixed = True
argspec = inspect.formatargspec(*inspect.getargspec(callable))
diff --git a/tests/__init__.py b/tests/__init__.py
index cffe526..555181c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,13 +1,28 @@
import os
+import shutil
import sys
here = os.path.dirname(__file__)
base = os.path.dirname(here)
sys.path.insert(0, base)
-# We can only import this after we adjust the paths
-import pkg_resources
+test_dir = os.path.dirname(__file__)
+egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO')
+info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info')
+if not os.path.exists(egg_info_dir):
+ try:
+ os.symlink(info_dir, egg_info_dir)
+ except Exception:
+ shutil.copytree(info_dir, egg_info_dir)
+
+sys.path.append(os.path.dirname(egg_info_dir))
+
+import pkg_resources # noqa E402
# Make absolutely sure we're testing *this* package, not
# some other installed package
pkg_resources.require('PasteDeploy')
+
+# ensure FakeApp is available for use by tests
+pkg_resources.working_set.add_entry(os.path.dirname(egg_info_dir))
+pkg_resources.require('FakeApp')
diff --git a/tests/fake_packages/FakeApp.egg/fakeapp/apps.py b/tests/fake_packages/FakeApp.egg/fakeapp/apps.py
index 9ab5183..18bf478 100644
--- a/tests/fake_packages/FakeApp.egg/fakeapp/apps.py
+++ b/tests/fake_packages/FakeApp.egg/fakeapp/apps.py
@@ -2,26 +2,33 @@
## Apps
############################################################
+
def simple_app(response, environ, start_response):
start_response('200 OK', [('Content-type', 'text/html')])
return ['This is ', response]
+
def basic_app(environ, start_response):
return simple_app('basic app', environ, start_response)
+
def make_basic_app(global_conf, **conf):
return basic_app
+
def basic_app2(environ, start_response):
return simple_app('basic app2', environ, start_response)
-
+
+
def make_basic_app2(global_conf, **conf):
return basic_app2
+
############################################################
## Composits
############################################################
+
def make_remote_addr(loader, global_conf, **conf):
apps = {}
addrs = {}
@@ -35,6 +42,7 @@ def make_remote_addr(loader, global_conf, **conf):
dispatcher.map[addrs[name]] = apps[name]
return dispatcher
+
class RemoteAddrDispatch:
def __init__(self, map=None):
self.map = map or {}
@@ -44,17 +52,20 @@ class RemoteAddrDispatch:
app = self.map.get(addr) or self.map['0.0.0.0']
return app(environ, start_response)
+
############################################################
## Filters
############################################################
+
def make_cap_filter(global_conf, method_to_call='upper'):
def cap_filter(app):
return CapFilter(app, global_conf, method_to_call)
+
return cap_filter
-class CapFilter:
+class CapFilter:
def __init__(self, app, global_conf, method_to_call='upper'):
self.app = app
self.method_to_call = method_to_call
@@ -66,4 +77,3 @@ class CapFilter:
yield getattr(item, self.method_to_call)()
if hasattr(app_iter, 'close'):
app_iter.close()
-
diff --git a/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py b/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py
index 8e125e8..078a4d6 100644
--- a/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py
+++ b/tests/fake_packages/FakeApp.egg/fakeapp/configapps.py
@@ -7,8 +7,8 @@ class SimpleApp:
def __call__(self, environ, start_response):
start_response('200 OK', [('Content-type', 'text/html')])
return ['I am: ', name]
-
+
def make_app(cls, global_conf, **conf):
return cls(global_conf, conf, 'basic')
- make_app = classmethod(make_app)
+ make_app = classmethod(make_app)
diff --git a/tests/fake_packages/FakeApp.egg/setup.py b/tests/fake_packages/FakeApp.egg/setup.py
index 854483e..9d34edb 100644
--- a/tests/fake_packages/FakeApp.egg/setup.py
+++ b/tests/fake_packages/FakeApp.egg/setup.py
@@ -1,23 +1,23 @@
-from setuptools import setup, find_packages
+from setuptools import find_packages, setup
setup(
name="FakeApp",
version="1.0",
packages=find_packages(),
entry_points={
- 'paste.app_factory': """
+ 'paste.app_factory': """
basic_app=fakeapp.apps:make_basic_app
other=fakeapp.apps:make_basic_app2
configed=fakeapp.configapps:SimpleApp.make_app
""",
- 'paste.composit_factory': """
+ 'paste.composit_factory': """
remote_addr=fakeapp.apps:make_remote_addr
""",
- 'paste.filter_factory': """
+ 'paste.filter_factory': """
caps=fakeapp.apps:make_cap_filter
""",
- 'paste.filter_app_factory': """
+ 'paste.filter_app_factory': """
caps2=fakeapp.apps:CapFilter
""",
- },
- )
+ },
+)
diff --git a/tests/fixture.py b/tests/fixture.py
index 751659d..6d92260 100644
--- a/tests/fixture.py
+++ b/tests/fixture.py
@@ -1,20 +1,19 @@
import os
-import sys
import shutil
+import sys
test_dir = os.path.dirname(__file__)
-egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg',
- 'EGG-INFO')
-info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg',
- 'FakeApp.egg-info')
+egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO')
+info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info')
if not os.path.exists(egg_info_dir):
try:
os.symlink(info_dir, egg_info_dir)
- except:
+ except Exception:
shutil.copytree(info_dir, egg_info_dir)
sys.path.append(os.path.dirname(egg_info_dir))
-from pkg_resources import *
-working_set.add_entry(os.path.dirname(egg_info_dir))
-require('FakeApp')
+import pkg_resources # noqa E402
+
+pkg_resources.working_set.add_entry(os.path.dirname(egg_info_dir))
+pkg_resources.require('FakeApp')
diff --git a/tests/test_basic_app.py b/tests/test_basic_app.py
index 1ddb52b..53cf7f2 100644
--- a/tests/test_basic_app.py
+++ b/tests/test_basic_app.py
@@ -1,36 +1,32 @@
-from paste.deploy import loadapp
+import os
-from tests.fixture import *
import fakeapp.apps
+from paste.deploy import loadapp
here = os.path.dirname(__file__)
def test_main():
- app = loadapp('config:sample_configs/basic_app.ini',
- relative_to=here)
+ app = loadapp('config:sample_configs/basic_app.ini', relative_to=here)
assert app is fakeapp.apps.basic_app
- app = loadapp('config:sample_configs/basic_app.ini#main',
- relative_to=here)
+ app = loadapp('config:sample_configs/basic_app.ini#main', relative_to=here)
assert app is fakeapp.apps.basic_app
- app = loadapp('config:sample_configs/basic_app.ini',
- relative_to=here, name='main')
+ app = loadapp('config:sample_configs/basic_app.ini', relative_to=here, name='main')
assert app is fakeapp.apps.basic_app
- app = loadapp('config:sample_configs/basic_app.ini#ignored',
- relative_to=here, name='main')
+ app = loadapp(
+ 'config:sample_configs/basic_app.ini#ignored', relative_to=here, name='main'
+ )
assert app is fakeapp.apps.basic_app
def test_other():
- app = loadapp('config:sample_configs/basic_app.ini#other',
- relative_to=here)
+ app = loadapp('config:sample_configs/basic_app.ini#other', relative_to=here)
assert app is fakeapp.apps.basic_app2
def test_composit():
- app = loadapp('config:sample_configs/basic_app.ini#remote_addr',
- relative_to=here)
+ app = loadapp('config:sample_configs/basic_app.ini#remote_addr', relative_to=here)
assert isinstance(app, fakeapp.apps.RemoteAddrDispatch)
assert app.map['127.0.0.1'] is fakeapp.apps.basic_app
assert app.map['0.0.0.0'] is fakeapp.apps.basic_app2
diff --git a/tests/test_config.py b/tests/test_config.py
index 3acbc5b..33eb808 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -1,8 +1,10 @@
-from paste.deploy import loadapp, appconfig
-from tests.fixture import *
-import fakeapp.configapps as fc
+import os
+import sys
+
import fakeapp.apps
+import fakeapp.configapps as fc
+from paste.deploy import appconfig, loadapp
ini_file = 'config:sample_configs/test_config.ini'
here = os.path.dirname(__file__)
@@ -20,26 +22,28 @@ def test_config1():
assert app.local_conf == {
'setting1': 'foo',
'setting2': 'bar',
- 'apppath': os.path.join(config_path, 'app')}
+ 'apppath': os.path.join(config_path, 'app'),
+ }
assert app.global_conf == {
'def1': 'a',
'def2': 'b',
'basepath': config_path,
'here': config_path,
- '__file__': config_filename}
+ '__file__': config_filename,
+ }
def test_config2():
app = loadapp(ini_file, relative_to=here, name='test2')
- assert app.local_conf == {
- 'local conf': 'something'}
+ assert app.local_conf == {'local conf': 'something'}
assert app.global_conf == {
'def1': 'test2',
'def2': 'b',
'basepath': config_path,
'another': 'TEST',
'here': config_path,
- '__file__': config_filename}
+ '__file__': config_filename,
+ }
# Run this to make sure the global-conf-modified test2
# didn't mess up the general global conf
test_config1()
@@ -50,29 +54,27 @@ def test_config3():
assert isinstance(app, fc.SimpleApp)
assert app.local_conf == {
'local conf': 'something',
- 'another': 'something more\nacross several\nlines'}
+ 'another': 'something more\nacross several\nlines',
+ }
assert app.global_conf == {
'def1': 'test3',
'def2': 'b',
'basepath': config_path,
'another': 'TEST',
'here': config_path,
- '__file__': config_filename}
+ '__file__': config_filename,
+ }
test_config2()
def test_main():
- app = loadapp('config:test_func.ini',
- relative_to=config_path)
+ app = loadapp('config:test_func.ini', relative_to=config_path)
assert app is fakeapp.apps.basic_app
- app = loadapp('config:test_func.ini#main',
- relative_to=config_path)
+ app = loadapp('config:test_func.ini#main', relative_to=config_path)
assert app is fakeapp.apps.basic_app
- app = loadapp('config:test_func.ini',
- relative_to=config_path, name='main')
+ app = loadapp('config:test_func.ini', relative_to=config_path, name='main')
assert app is fakeapp.apps.basic_app
- app = loadapp('config:test_func.ini#ignored',
- relative_to=config_path, name='main')
+ app = loadapp('config:test_func.ini#ignored', relative_to=config_path, name='main')
assert app is fakeapp.apps.basic_app
@@ -91,9 +93,7 @@ def test_composit():
def test_foreign_config():
app = loadapp(ini_file, relative_to=here, name='test_foreign_config')
assert isinstance(app, fc.SimpleApp)
- assert app.local_conf == {
- 'another': 'FOO',
- 'bob': 'your uncle'}
+ assert app.local_conf == {'another': 'FOO', 'bob': 'your uncle'}
assert app.global_conf == {
'def1': 'a',
# Note overwrite of DEFAULT value from foreign config
@@ -102,21 +102,21 @@ def test_foreign_config():
'basepath': config_path,
'glob': 'override',
'here': config_path,
- '__file__': os.path.join(config_path, 'test_config.ini')}
+ '__file__': os.path.join(config_path, 'test_config.ini'),
+ }
def test_config_get():
app = loadapp(ini_file, relative_to=here, name='test_get')
assert isinstance(app, fc.SimpleApp)
- assert app.local_conf == {
- 'def1': 'a',
- 'foo': 'TEST'}
+ assert app.local_conf == {'def1': 'a', 'foo': 'TEST'}
assert app.global_conf == {
'def1': 'a',
'def2': 'TEST',
'basepath': os.path.join(here, 'sample_configs'),
'here': config_path,
- '__file__': config_filename}
+ '__file__': config_filename,
+ }
def test_appconfig():
@@ -127,16 +127,16 @@ def test_appconfig():
'basepath': os.path.join(here, 'sample_configs'),
'here': config_path,
'__file__': config_filename,
- 'foo': 'TEST'}
- assert conf.local_conf == {
- 'def1': 'a',
- 'foo': 'TEST'}
+ 'foo': 'TEST',
+ }
+ assert conf.local_conf == {'def1': 'a', 'foo': 'TEST'}
assert conf.global_conf == {
'def1': 'a',
'def2': 'TEST',
'basepath': os.path.join(here, 'sample_configs'),
'here': config_path,
- '__file__': config_filename}
+ '__file__': config_filename,
+ }
def test_appconfig_filter_with():
@@ -145,8 +145,12 @@ def test_appconfig_filter_with():
def test_global_conf():
- conf = appconfig(ini_file, relative_to=here, name='test_global_conf',
- global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'})
+ conf = appconfig(
+ ini_file,
+ relative_to=here,
+ name='test_global_conf',
+ global_conf={'def2': 'TEST DEF 2', 'inherit': 'bazbar'},
+ )
assert conf == {
'def1': 'a',
# Note overwrite of DEFAULT value
@@ -156,9 +160,8 @@ def test_global_conf():
'inherit': 'bazbar',
'__file__': config_filename,
'test_interp': 'this:bazbar',
- }
- assert conf.local_conf == {
- 'test_interp': 'this:bazbar'}
+ }
+ assert conf.local_conf == {'test_interp': 'this:bazbar'}
def test_interpolate_exception():
@@ -169,4 +172,4 @@ def test_interpolate_exception():
expected = "Error in file %s" % os.path.join(config_path, 'test_error.ini')
assert str(e).split(':')[0] == expected
else:
- assert False, 'Should have raised an exception'
+ raise AssertionError('Should have raised an exception')
diff --git a/tests/test_config_middleware.py b/tests/test_config_middleware.py
index 52ba7d1..519837e 100644
--- a/tests/test_config_middleware.py
+++ b/tests/test_config_middleware.py
@@ -11,6 +11,7 @@ def app_with_exception(environ, start_response):
def cont():
yield b"something"
raise Bug
+
start_response('200 OK', [('Content-type', 'text/html')])
return cont()
diff --git a/tests/test_converters.py b/tests/test_converters.py
index 5361310..887ae32 100644
--- a/tests/test_converters.py
+++ b/tests/test_converters.py
@@ -1,5 +1,6 @@
def test_asbool_truthy():
from paste.deploy.converters import asbool
+
assert asbool('true')
assert asbool('yes')
assert asbool('on')
@@ -7,8 +8,10 @@ def test_asbool_truthy():
assert asbool('t')
assert asbool('1')
+
def test_asbool_falsy():
from paste.deploy.converters import asbool
+
assert not asbool('false')
assert not asbool('no')
assert not asbool('off')
diff --git a/tests/test_filter.py b/tests/test_filter.py
index 470a9dd..6a4a69a 100644
--- a/tests/test_filter.py
+++ b/tests/test_filter.py
@@ -1,53 +1,48 @@
-from paste.deploy import loadapp
-from tests.fixture import *
+import os
+
import fakeapp.apps
+from paste.deploy import loadapp
here = os.path.dirname(__file__)
def test_filter_app():
- app = loadapp('config:sample_configs/test_filter.ini#filt',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter.ini#filt', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert app.app is fakeapp.apps.basic_app
assert app.method_to_call == 'lower'
def test_pipeline():
- app = loadapp('config:sample_configs/test_filter.ini#piped',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter.ini#piped', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert app.app is fakeapp.apps.basic_app
assert app.method_to_call == 'upper'
def test_filter_app2():
- app = loadapp('config:sample_configs/test_filter.ini#filt2',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter.ini#filt2', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert app.app is fakeapp.apps.basic_app
assert app.method_to_call == 'lower'
def test_pipeline2():
- app = loadapp('config:sample_configs/test_filter.ini#piped2',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter.ini#piped2', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert app.app is fakeapp.apps.basic_app
assert app.method_to_call == 'upper'
def test_filter_app_inverted():
- app = loadapp('config:sample_configs/test_filter.ini#inv',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter.ini#inv', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert app.app is fakeapp.apps.basic_app
def test_filter_with_filter_with():
- app = loadapp('config:sample_configs/test_filter_with.ini',
- relative_to=here)
+ app = loadapp('config:sample_configs/test_filter_with.ini', relative_to=here)
assert isinstance(app, fakeapp.apps.CapFilter)
assert isinstance(app.app, fakeapp.apps.CapFilter)
assert app.app.app is fakeapp.apps.basic_app
@@ -55,9 +50,8 @@ def test_filter_with_filter_with():
def test_bad_pipeline():
try:
- app = loadapp('config:sample_configs/test_filter.ini#piped3',
- relative_to=here)
+ loadapp('config:sample_configs/test_filter.ini#piped3', relative_to=here)
except LookupError as err:
assert 'has extra (disallowed) settings' in err.args[0]
else:
- assert False, 'should have raised LookupError'
+ raise AssertionError('should have raised LookupError')
diff --git a/tests/test_load_package.py b/tests/test_load_package.py
index 6ba1ad4..bdd6e3f 100644
--- a/tests/test_load_package.py
+++ b/tests/test_load_package.py
@@ -1,7 +1,8 @@
from pprint import pprint
-import pkg_resources
import sys
+import pkg_resources
+
def test_load_package():
print('Path:')
diff --git a/tox.ini b/tox.ini
index 8df803b..18f23f6 100644
--- a/tox.ini
+++ b/tox.ini
@@ -34,16 +34,32 @@ extras =
[testenv:lint]
skip_install = True
commands =
+ isort --check-only --df src/paste tests
+ black --check --diff .
+ flake8 src/paste tests
check-manifest
# build sdist/wheel
python -m build .
twine check dist/*
deps =
+ black
build
check-manifest
+ flake8
+ flake8-bugbear
+ isort
readme_renderer
twine
+[testenv:format]
+skip_install = true
+commands =
+ isort src/paste tests
+ black .
+deps =
+ black
+ isort
+
[testenv:build]
skip_install = True
commands =