Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/plaster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# public api
# flake8: noqa

from .exceptions import InvalidURI, LoaderNotFound, MultipleLoadersFound, PlasterError
from .exceptions import (
InvalidURI,
LoaderNotFound,
MultipleLoadersFound,
PlasterError,
)
from .interfaces import ILoader, ILoaderFactory, ILoaderInfo
from .loaders import find_loaders, get_loader, get_sections, get_settings, setup_logging
from .loaders import (
find_loaders,
get_loader,
get_sections,
get_settings,
setup_logging,
)
from .uri import PlasterURL, parse_uri
3 changes: 2 additions & 1 deletion src/plaster/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def __init__(self, scheme, loaders, protocols=None, message=None):
if protocols is not None:
scheme_msg += ', protocol "{}"'.format(", ".join(protocols))
loader_list = ", ".join(
loader.scheme for loader in sorted(loaders, key=lambda v: v.scheme)
loader.scheme
for loader in sorted(loaders, key=lambda v: v.scheme)
)
message = (
"Multiple plaster loaders were found for {}. "
Expand Down
7 changes: 5 additions & 2 deletions src/plaster/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def find_loaders(scheme, protocols=None):
matching_groups = ["plaster.loader_factory"]

if protocols:
matching_groups += [f"plaster.{proto}_loader_factory" for proto in protocols]
matching_groups += [
f"plaster.{proto}_loader_factory" for proto in protocols
]
scheme = scheme.lower()

# if a distribution is specified then it overrides the default search
Expand Down Expand Up @@ -203,7 +205,8 @@ class EntryPointLoaderInfo(ILoaderInfo):
def __init__(self, dist, ep, protocols=None):
self.entry_point = ep
self.scheme = "{}+{}".format(
dist.metadata["name"] if "name" in dist.metadata else "Unknown", ep.name
dist.metadata["name"] if "name" in dist.metadata else "Unknown",
ep.name,
)
self.protocols = protocols

Expand Down
4 changes: 3 additions & 1 deletion src/plaster/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@ def parse_uri(config_uri):
),
)

return PlasterURL(scheme=scheme, path=path, options=options, fragment=fragment)
return PlasterURL(
scheme=scheme, path=path, options=options, fragment=fragment
)
11 changes: 8 additions & 3 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ def test_it(self):
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols is None
assert exc.message == ('Could not find a matching loader for the scheme "foo".')
assert exc.message == (
'Could not find a matching loader for the scheme "foo".'
)

def test_it_with_protocol(self):
exc = self._makeOne("foo", ["wsgi"])
assert isinstance(exc, ValueError)
assert exc.scheme == "foo"
assert exc.protocols == ["wsgi"]
assert exc.message == (
'Could not find a matching loader for the scheme "foo", ' 'protocol "wsgi".'
'Could not find a matching loader for the scheme "foo", '
'protocol "wsgi".'
)

def test_it_with_multiple_protocols(self):
Expand Down Expand Up @@ -94,7 +97,9 @@ def test_it_with_protocol(self):
def test_it_with_multiple_protocols(self):
dummy1 = DummyLoaderInfo("dummy1")
dummy2 = DummyLoaderInfo("dummy2")
exc = self._makeOne("https", [dummy1, dummy2], protocols=["wsgi", "qt"])
exc = self._makeOne(
"https", [dummy1, dummy2], protocols=["wsgi", "qt"]
)
assert isinstance(exc, ValueError)
assert exc.message == (
'Multiple plaster loaders were found for scheme "https", '
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extras =
[testenv:lint]
skip_install = True
commands =
isort --check-only --df src/plaster tests
black --check --diff .
isort --check-only --line-length 79 --df src/plaster tests
black --check --diff --line-length 79 .
flake8 src/plaster tests
check-manifest
# build sdist/wheel
Expand Down