Skip to content

Commit 9fe9694

Browse files
committed
chore: add future deprecation warnings
As work starts on the next major version of Pact for Python, we need to start warning users that the current version will be deprecated in the future. This commit adds a warning to the top of all modules and standalone functions that will be deprecated in the next major version. While the class names themselves might remain, the way they are used may change to accommodate the changes in the underlying workings, and to accommodate versions 3 and 4 of the Pact specification. Once the work on the Pact Python v3 is complete, a thorough migration guide will be written. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 77124ee commit 9fe9694

11 files changed

+147
-0
lines changed

pact/broker.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import fnmatch
55
import os
66
from subprocess import Popen
7+
import warnings
78

89
from .constants import BROKER_CLIENT_PATH
910

@@ -36,6 +37,12 @@ def __init__(self, broker_base_url=None, broker_username=None, broker_password=N
3637
the PACT_BROKER_TOKEN environment variable instead.
3738
Defaults to None.
3839
"""
40+
warnings.warn(
41+
"This class will be deprecated Pact Python v3 "
42+
"(see pact-foundation/pact-python#396)",
43+
PendingDeprecationWarning,
44+
stacklevel=2,
45+
)
3946
self.broker_base_url = broker_base_url
4047
self.broker_username = broker_username
4148
self.broker_password = broker_password

pact/consumer.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Classes and methods to describe contract Consumers."""
2+
import warnings
23
from .pact import Pact
34
from .provider import Provider
45

@@ -47,6 +48,12 @@ def __init__(self, name, service_cls=Pact, tags=None,
4748
Defaults to False.
4849
:type auto_detect_version_properties: bool
4950
"""
51+
warnings.warn(
52+
"This class will be deprecated Pact Python v3 "
53+
"(see pact-foundation/pact-python#396)",
54+
PendingDeprecationWarning,
55+
stacklevel=2,
56+
)
5057
self.name = name
5158
self.service_cls = service_cls
5259
self.tags = tags

pact/http_proxy.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Http Proxy to be used as provider url in verifier."""
2+
import warnings
23
from fastapi import FastAPI, status, Request, HTTPException
34
import uvicorn as uvicorn
45
import logging
@@ -55,4 +56,10 @@ async def setup(request: Request):
5556

5657
def run_proxy():
5758
"""Rub HTTP Proxy."""
59+
warnings.warn(
60+
"This class will be deprecated Pact Python v3 "
61+
"(see pact-foundation/pact-python#396)",
62+
PendingDeprecationWarning,
63+
stacklevel=2,
64+
)
5865
uvicorn.run("pact.http_proxy:app", port=PROXY_PORT, log_level=UVICORN_LOGGING_LEVEL)

pact/matchers.py

+37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Classes for defining request and response data that is variable."""
2+
import warnings
23
import six
34
import datetime
45

@@ -50,6 +51,12 @@ def __init__(self, matcher, minimum=1):
5051
Must be greater than or equal to 1.
5152
:type minimum: int
5253
"""
54+
warnings.warn(
55+
"This class will be deprecated Pact Python v3 "
56+
"(see pact-foundation/pact-python#396)",
57+
PendingDeprecationWarning,
58+
stacklevel=2,
59+
)
5360
self.matcher = matcher
5461
assert minimum >= 1, 'Minimum must be greater than or equal to 1'
5562
self.minimum = minimum
@@ -100,6 +107,12 @@ def __init__(self, matcher):
100107
ignored.
101108
:type matcher: None, list, dict, int, float, str, unicode, Matcher
102109
"""
110+
warnings.warn(
111+
"This class will be deprecated Pact Python v3 "
112+
"(see pact-foundation/pact-python#396)",
113+
PendingDeprecationWarning,
114+
stacklevel=2,
115+
)
103116
valid_types = (
104117
type(None), list, dict, int, float, six.string_types, Matcher)
105118

@@ -158,6 +171,12 @@ def __init__(self, matcher, generate):
158171
generating the response to the consumer.
159172
:type generate: basestring
160173
"""
174+
warnings.warn(
175+
"This class will be deprecated Pact Python v3 "
176+
"(see pact-foundation/pact-python#396)",
177+
PendingDeprecationWarning,
178+
stacklevel=2,
179+
)
161180
self.matcher = matcher
162181
self._generate = generate
163182

@@ -188,6 +207,12 @@ def from_term(term):
188207
:return: The JSON representation for this term.
189208
:rtype: dict, list, str
190209
"""
210+
warnings.warn(
211+
"This function will be deprecated Pact Python v3 "
212+
"(see pact-foundation/pact-python#396)",
213+
PendingDeprecationWarning,
214+
stacklevel=2,
215+
)
191216
if term is None:
192217
return term
193218
elif isinstance(term, (six.string_types, six.binary_type, int, float)):
@@ -211,6 +236,12 @@ def get_generated_values(input):
211236
:return: The input resolved to its generated value(s)
212237
:rtype: None, list, dict, int, float, bool, str, unicode, Matcher
213238
"""
239+
warnings.warn(
240+
"This function will be deprecated Pact Python v3 "
241+
"(see pact-foundation/pact-python#396)",
242+
PendingDeprecationWarning,
243+
stacklevel=2,
244+
)
214245
if input is None:
215246
return input
216247
if isinstance(input, (six.string_types, int, float, bool)):
@@ -254,6 +285,12 @@ class Format:
254285

255286
def __init__(self):
256287
"""Create a new Formatter."""
288+
warnings.warn(
289+
"This class will be deprecated Pact Python v3 "
290+
"(see pact-foundation/pact-python#396)",
291+
PendingDeprecationWarning,
292+
stacklevel=2,
293+
)
257294
self.identifier = self.integer_or_identifier()
258295
self.integer = self.integer_or_identifier()
259296
self.decimal = self.decimal()

pact/message_consumer.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Classes and methods to describe contract Consumers."""
2+
import warnings
23
from .message_pact import MessagePact
34
from .provider import Provider
45

@@ -56,6 +57,12 @@ def __init__(
5657
Defaults to False.
5758
:type auto_detect_version_properties: bool
5859
"""
60+
warnings.warn(
61+
"This class will be deprecated Pact Python v3 "
62+
"(see pact-foundation/pact-python#396)",
63+
PendingDeprecationWarning,
64+
stacklevel=2,
65+
)
5966
self.name = name
6067
self.service_cls = service_cls
6168
self.tags = tags

pact/message_pact.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os
66
from subprocess import Popen
7+
import warnings
78

89
from .broker import Broker
910
from .constants import MESSAGE_PATH
@@ -84,6 +85,12 @@ def __init__(
8485
`merge`.
8586
:type file_write_mode: str
8687
"""
88+
warnings.warn(
89+
"This class will be deprecated Pact Python v3 "
90+
"(see pact-foundation/pact-python#396)",
91+
PendingDeprecationWarning,
92+
stacklevel=2,
93+
)
8794
super().__init__(
8895
broker_base_url, broker_username, broker_password, broker_token
8996
)

pact/message_provider.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Contract Message Provider."""
22
import os
33
import time
4+
import warnings
45

56
import requests
67
from requests.adapters import HTTPAdapter
@@ -38,6 +39,12 @@ def __init__(
3839
proxy_port='1234'
3940
):
4041
"""Create a Message Provider instance."""
42+
warnings.warn(
43+
"This class will be deprecated Pact Python v3 "
44+
"(see pact-foundation/pact-python#396)",
45+
PendingDeprecationWarning,
46+
stacklevel=2,
47+
)
4148
self.message_providers = message_providers
4249
self.provider = provider
4350
self.consumer = consumer

pact/pact.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import platform
66
from subprocess import Popen
7+
import warnings
78

89
import psutil
910
import requests
@@ -124,6 +125,12 @@ def __init__(
124125
`overwrite`.
125126
:type file_write_mode: str
126127
"""
128+
warnings.warn(
129+
"This class will be deprecated Pact Python v3 "
130+
"(see pact-foundation/pact-python#396)",
131+
PendingDeprecationWarning,
132+
stacklevel=2,
133+
)
127134
super().__init__(
128135
broker_base_url, broker_username, broker_password, broker_token
129136
)

pact/provider.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Classes and methods to describe contract Providers."""
22

33

4+
import warnings
5+
6+
47
class Provider(object):
58
"""A Pact provider."""
69

@@ -12,4 +15,10 @@ def __init__(self, name):
1215
when it is published.
1316
:type name: str
1417
"""
18+
warnings.warn(
19+
"This class will be deprecated Pact Python v3 "
20+
"(see pact-foundation/pact-python#396)",
21+
PendingDeprecationWarning,
22+
stacklevel=2,
23+
)
1524
self.name = name

pact/verifier.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Classes and methods to verify Contracts."""
22
import json
3+
import warnings
34

45
from pact.verify_wrapper import VerifyWrapper, path_exists, expand_directories
56

@@ -15,6 +16,12 @@ def __init__(self, provider, provider_base_url, **kwargs):
1516
provider_base_url ([String]): provider url
1617
1718
"""
19+
warnings.warn(
20+
"This class will be deprecated Pact Python v3 "
21+
"(see pact-foundation/pact-python#396)",
22+
PendingDeprecationWarning,
23+
stacklevel=2,
24+
)
1825
self.provider = provider
1926
self.provider_base_url = provider_base_url
2027

pact/verify_wrapper.py

+45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Wrapper to verify previously created pacts."""
22

3+
import warnings
34
from pact.constants import VERIFIER_PATH
45
import sys
56
import os
@@ -12,6 +13,12 @@
1213

1314
def capture_logs(process, verbose):
1415
"""Capture logs from ruby process."""
16+
warnings.warn(
17+
"This function will be deprecated Pact Python v3 "
18+
"(see pact-foundation/pact-python#396)",
19+
PendingDeprecationWarning,
20+
stacklevel=2,
21+
)
1522
result = ''
1623
for line in process.stdout:
1724
result = result + line + '\n'
@@ -31,6 +38,12 @@ def path_exists(path):
3138
:return: True if the path exists and is a file, otherwise False.
3239
:rtype: bool
3340
"""
41+
warnings.warn(
42+
"This function will be deprecated Pact Python v3 "
43+
"(see pact-foundation/pact-python#396)",
44+
PendingDeprecationWarning,
45+
stacklevel=2,
46+
)
3447
if path.startswith('http://') or path.startswith('https://'):
3548
return True
3649

@@ -46,6 +59,12 @@ def sanitize_logs(process, verbose):
4659
:type verbose: bool
4760
:rtype: None
4861
"""
62+
warnings.warn(
63+
"This function will be deprecated Pact Python v3 "
64+
"(see pact-foundation/pact-python#396)",
65+
PendingDeprecationWarning,
66+
stacklevel=2,
67+
)
4968
for line in process.stdout:
5069
if (not verbose and line.lstrip().startswith('#')
5170
and ('vendor/ruby' in line or 'pact-provider-verifier.rb' in line)):
@@ -63,6 +82,12 @@ def expand_directories(paths):
6382
JSON files in those directories.
6483
:rtype: list
6584
"""
85+
warnings.warn(
86+
"This function will be deprecated Pact Python v3 "
87+
"(see pact-foundation/pact-python#396)",
88+
PendingDeprecationWarning,
89+
stacklevel=2,
90+
)
6691
paths_ = []
6792
for path in paths:
6893
if path.startswith('http://') or path.startswith('https://'):
@@ -83,6 +108,12 @@ def rerun_command():
83108
84109
:rtype: str
85110
"""
111+
warnings.warn(
112+
"This function will be deprecated Pact Python v3 "
113+
"(see pact-foundation/pact-python#396)",
114+
PendingDeprecationWarning,
115+
stacklevel=2,
116+
)
86117
is_windows = 'windows' in platform.platform().lower()
87118
command = ''
88119
if is_windows:
@@ -119,12 +150,26 @@ class PactException(Exception):
119150

120151
def __init__(self, *args, **kwargs):
121152
"""Create wrapper."""
153+
warnings.warn(
154+
"This class will be deprecated Pact Python v3 "
155+
"(see pact-foundation/pact-python#396)",
156+
PendingDeprecationWarning,
157+
stacklevel=2,
158+
)
122159
super().__init__(*args, **kwargs)
123160
self.message = args[0]
124161

125162
class VerifyWrapper(object):
126163
"""A Pact Verifier Wrapper."""
127164

165+
def __init__(self):
166+
warnings.warn(
167+
"This class will be deprecated Pact Python v3 "
168+
"(see pact-foundation/pact-python#396)",
169+
PendingDeprecationWarning,
170+
stacklevel=2,
171+
)
172+
128173
def _broker_present(self, **kwargs):
129174
if kwargs.get('broker_url') is None:
130175
return False

0 commit comments

Comments
 (0)