Skip to content

Commit 309cef2

Browse files
Started removing pkg_resources. Formatting fixes.
1 parent 47be71c commit 309cef2

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/pyff/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
pyFF is a SAML metadata aggregator.
33
"""
44

5-
import pkg_resources
5+
import importlib
66

7-
__author__ = 'Leif Johansson'
8-
__copyright__ = "Copyright 2009-2018 SUNET and the IdentityPython Project"
9-
__license__ = "BSD"
10-
__maintainer__ = "[email protected]"
11-
__status__ = "Production"
12-
__version__ = pkg_resources.require("pyFF")[0].version
7+
__version__ = importlib.metadata.version('pyFF')

src/pyff/api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from json import dumps
55
from typing import Any, Dict, Generator, Iterable, List, Mapping, Optional, Tuple
66

7-
import pkg_resources
87
import pyramid.httpexceptions as exc
98
import pytz
109
import requests
@@ -26,12 +25,13 @@
2625
from pyff.resource import Resource
2726
from pyff.samlmd import entity_display_name
2827
from pyff.utils import b2u, dumptree, hash_id, json_serializer, utc_now
28+
from pyff import __version__
2929

3030
log = get_log(__name__)
3131

3232

3333
class NoCache(object):
34-
""" Dummy implementation for when caching isn't enabled """
34+
"""Dummy implementation for when caching isn't enabled"""
3535

3636
def __init__(self) -> None:
3737
pass
@@ -70,7 +70,7 @@ def status_handler(request: Request) -> Response:
7070
if 'Validation Errors' in r.info and r.info['Validation Errors']:
7171
d[r.url] = r.info['Validation Errors']
7272
_status = dict(
73-
version=pkg_resources.require("pyFF")[0].version,
73+
version=__version__,
7474
invalids=d,
7575
icon_store=dict(size=request.registry.md.icon_store.size()),
7676
jobs=[dict(id=j.id, next_run_time=j.next_run_time) for j in request.registry.scheduler.get_jobs()],
@@ -163,7 +163,7 @@ def process_handler(request: Request) -> Response:
163163
_ctypes = {'xml': 'application/samlmetadata+xml;application/xml;text/xml', 'json': 'application/json'}
164164

165165
def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional[str]]:
166-
""" Split a path into a base component and an extension. """
166+
"""Split a path into a base component and an extension."""
167167
if x is not None:
168168
x = x.strip()
169169

@@ -214,7 +214,7 @@ def _d(x: Optional[str], do_split: bool = True) -> Tuple[Optional[str], Optional
214214
pfx = request.registry.aliases.get(alias, None)
215215
if pfx is None:
216216
log.debug("alias {} not found - passing to storage lookup".format(alias))
217-
path=alias #treat as path
217+
path = alias # treat as path
218218

219219
# content_negotiation_policy is one of three values:
220220
# 1. extension - current default, inspect the path and if it ends in
@@ -478,7 +478,7 @@ def cors_headers(request: Request, response: Response) -> None:
478478
{
479479
'Access-Control-Allow-Origin': '*',
480480
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
481-
'Access-Control-Allow-Headers': ('Origin, Content-Type, Accept, ' 'Authorization'),
481+
'Access-Control-Allow-Headers': ('Origin, Content-Type, Accept, Authorization'),
482482
'Access-Control-Allow-Credentials': 'true',
483483
'Access-Control-Max-Age': '1728000',
484484
}

src/pyff/test/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import tempfile
77
from unittest import TestCase
88

9-
import pkg_resources
9+
import importlib.resources
1010
import six
11-
1211
from pyff import __version__ as pyffversion
1312

1413
# range of ports where available ports can be found
@@ -118,7 +117,6 @@ def _p(args, outf=None, ignore_exit=False):
118117

119118

120119
class SignerTestCase(TestCase):
121-
122120
datadir = None
123121
private_keyspec = None
124122
public_keyspec = None
@@ -128,7 +126,10 @@ def sys_exit(self, code):
128126

129127
@classmethod
130128
def setUpClass(cls):
131-
cls.datadir = pkg_resources.resource_filename(__name__, 'data')
129+
with importlib.resources.path(
130+
__name__, 'data'
131+
) as context: # We just want the path for now to be compatible downstream
132+
cls.datadir = context.as_posix()
132133
cls.private_keyspec = tempfile.NamedTemporaryFile('w').name
133134
cls.public_keyspec = tempfile.NamedTemporaryFile('w').name
134135

0 commit comments

Comments
 (0)