2020import hashlib
2121import hmac
2222import logging
23+ import warnings
2324from base64 import b64encode
2425from contextlib import contextmanager
2526from datetime import datetime , timedelta , timezone
@@ -100,11 +101,13 @@ def __repr__(self) -> str:
100101 )
101102
102103 def __enter__ (self ):
103- """Enter a context by locking the corresponding remote workspace.
104-
105- Note: this method is deprecated in favour of lock(), and will be removed in a
106- future relesae.
107- """
104+ """Enter a context by locking the corresponding remote workspace."""
105+ warnings .warn (
106+ "Using the `StructurizrClient` in a context is deprecated since version "
107+ "0.4.1 and will be removed in a future release. Please use the "
108+ "preferred method `.lock()` instead." ,
109+ DeprecationWarning ,
110+ )
108111 is_successful = self .lock_workspace ()
109112 if not is_successful :
110113 raise StructurizrClientException (
@@ -114,11 +117,13 @@ def __enter__(self):
114117 return self
115118
116119 def __exit__ (self , exc_type , exc_val , exc_tb ):
117- """Exit a context by unlocking the corresponding remote workspace.
118-
119- Note: this method is deprecated in favour of lock(), and will be removed in a
120- future relesae.
121- """
120+ """Exit a context by unlocking the corresponding remote workspace."""
121+ warnings .warn (
122+ "Using the `StructurizrClient` in a context is deprecated since version "
123+ "0.4.1 and will be removed in a future release. Please use the "
124+ "preferred method `.lock()` instead." ,
125+ DeprecationWarning ,
126+ )
122127 is_successful = self .unlock_workspace ()
123128 self ._client .close ()
124129 if exc_type is None and not is_successful :
@@ -135,7 +140,7 @@ def lock(self):
135140 f"Failed to lock the Structurizr workspace { self .workspace_id } ."
136141 )
137142 try :
138- yield None
143+ yield self
139144 finally :
140145 is_successful = self .unlock_workspace ()
141146 self ._client .close ()
0 commit comments