Skip to content

Commit 808cae8

Browse files
committed
pynipap: Move to Python package
Mainly to avoid cluttering the global namespace with the name "tracing", moved the pynipap module to its own package. The intention is that the package should be fully compatible with the stans-alone module and require no changes to the applications using it.
1 parent e363e73 commit 808cae8

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

Diff for: pynipap/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ clean:
4949
VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
5050
bumpversion:
5151
# replace version number in pynipap.py
52-
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' pynipap.py
52+
sed -i 's/\(__version__\s*= \)"[^"]\+"/\1"$(VER)"/' pynipap/__init__.py
5353
# # update debian/changelog
5454
../utilities/news2dch.py ../NEWS debian/changelog

Diff for: pynipap/pynipap/__init__.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from .pynipap import *
2+
3+
__version__ = "0.32.5"
4+
__author__ = "Kristian Larsson, Lukas Garberg"
5+
6+
__copyright__ = "Copyright 2011, Kristian Larsson, Lukas Garberg"
7+
__license__ = "MIT"
8+
__status__ = "Development"
9+
__url__ = "http://SpriteLink.github.io/NIPAP"
10+
11+
12+
# This variable holds the URI to the nipap XML-RPC service which will be used.
13+
# It must be set before the Pynipap can be used!
14+
xmlrpc_uri = None
15+
16+
# If set, the value assigned to the variable below will be used as a bearer
17+
# token.
18+
bearer_token = None
19+
20+
# Caching of objects is enabled per default but can be disabled for certain
21+
# scenarios. Since we don't have any cache expiration time it can be useful to
22+
# disable for long running applications.
23+
CACHE = True

Diff for: pynipap/pynipap.py renamed to pynipap/pynipap/pynipap.py

+10-22
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,11 @@
209209
import xmlrpc.client as xmlrpclib
210210
import urllib.parse
211211

212-
from tracing import create_span
212+
from .tracing import create_span
213213

214-
__version__ = "0.32.5"
215-
__author__ = "Kristian Larsson, Lukas Garberg"
216-
217-
__copyright__ = "Copyright 2011, Kristian Larsson, Lukas Garberg"
218-
__license__ = "MIT"
219-
__status__ = "Development"
220-
__url__ = "http://SpriteLink.github.io/NIPAP"
221-
222-
223-
# This variable holds the URI to the nipap XML-RPC service which will be used.
224-
# It must be set before the Pynipap can be used!
225-
xmlrpc_uri = None
226-
bearer_token = None
227-
228-
# Caching of objects is enabled per default but can be disabled for certain
229-
# scenarios. Since we don't have any cache expiration time it can be useful to
230-
# disable for long running applications.
231-
CACHE = True
214+
# Will be overwritten by import from . when setting up XML-RPC-connection, but
215+
# needs to be defined here if it's read before the connections is set up.
216+
CACHE = False
232217

233218
class AuthOptions:
234219
""" A global-ish authentication option container.
@@ -261,8 +246,6 @@ class XMLRPCConnection:
261246
""" Handles a shared XML-RPC connection.
262247
"""
263248

264-
__shared_state = {}
265-
266249
connection = None
267250
_logger = None
268251

@@ -275,13 +258,18 @@ def __init__(self):
275258
variable is set.
276259
"""
277260

261+
# This is not a pretty solution, but needed to maintain backwards
262+
# compatibility and avoiding circular imports.
263+
from . import xmlrpc_uri, bearer_token, CACHE as cache_enabled
264+
CACHE = cache_enabled
265+
278266
if xmlrpc_uri is None:
279267
raise NipapError('XML-RPC URI not specified')
280268

281269
p = urllib.parse.urlsplit(xmlrpc_uri)
282270

283271
try:
284-
from tracing import TracingXMLTransport, TracingXMLSafeTransport
272+
from .tracing import TracingXMLTransport, TracingXMLSafeTransport
285273
if p.scheme == "http":
286274
xml_transport = TracingXMLTransport
287275
elif p.scheme == "https":

Diff for: pynipap/tracing.py renamed to pynipap/pynipap/tracing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def decorated(*args, **kwargs):
4949
"""
5050
"""
5151

52-
from pynipap import AuthOptions
52+
from . import AuthOptions
5353
signature = inspect.signature(f)
5454

5555
if args[0].__class__ == type:

Diff for: pynipap/setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
author_email = pynipap.__author_email__,
1818
license = pynipap.__license__,
1919
url = pynipap.__url__,
20-
py_modules = ['pynipap','tracing'],
20+
packages = ['pynipap'],
2121
keywords = ['nipap'],
2222
classifiers = [
2323
'Development Status :: 4 - Beta',
@@ -26,7 +26,6 @@
2626
'License :: OSI Approved :: MIT License',
2727
'Natural Language :: English',
2828
'Operating System :: POSIX :: Linux',
29-
'Programming Language :: Python :: 3',
30-
'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware'
29+
'Programming Language :: Python :: 3'
3130
]
3231
)

0 commit comments

Comments
 (0)