2121# SOFTWARE.
2222
2323"""
24- ServerContext
24+ ServerContext.
2525
2626Gives the ability to choose the context with which the server should be started.
2727The context allows you to choose the licensing logic for operators.
4343
4444
4545class LicensingContextType (Enum ):
46+ """Enum representing different types of licensing contexts."""
47+
4648 none = 5
4749 premium = 1
4850 """Checks if at least one license increment exists
@@ -52,10 +54,33 @@ class LicensingContextType(Enum):
5254 and does not allow operators to block an increment."""
5355
5456 def __int__ (self ):
57+ """
58+ Return the integer values of the licensing context.
59+
60+ Returns
61+ -------
62+ int
63+ Integer values corresponding to the licensing context.
64+ """
5565 return self .value
5666
5767 @staticmethod
5868 def same_licensing_context (first , second ):
69+ """
70+ Determine if two licensing contexts are compatible.
71+
72+ Parameters
73+ ----------
74+ first : LicensingContextType
75+ The first licensing context to compare.
76+ second : LicensingContextType
77+ The second licensing context to compare.
78+
79+ Returns
80+ -------
81+ bool
82+ True if the licensing contexts are compatible, False otherwise.
83+ """
5984 if (first == LicensingContextType .none and second != LicensingContextType .none ) or (
6085 first != LicensingContextType .none and second == LicensingContextType .none
6186 ):
@@ -73,6 +98,7 @@ def same_licensing_context(first, second):
7398
7499class LicenseContextManager :
75100 """Can optionally be used to check out a license before using licensed DPF Operators.
101+
76102 Improves performance if you are using multiple Operators that require licensing.
77103 It can also be used to force checkout before running a script when few
78104 Ansys license increments are available.
@@ -152,13 +178,45 @@ def release_data(self):
152178 self ._license_checkout_operator = None
153179
154180 def __enter__ (self ):
181+ """
182+ Enter the runtime context for the license context manager.
183+
184+ This method is called when the object is used within a `with` statement.
185+ It ensures that the license is checked out before the operations within the context block are executed.
186+
187+ Returns
188+ -------
189+ LicenseContextManager
190+ The current instance of the license context manager.
191+ """
155192 return self
156193
157194 def __exit__ (self , type , value , tb ):
195+ """
196+ Exit the runtime context for the license context manager.
197+
198+ This method is called at the end of a `with` statement. It ensures
199+ that the license is checked in and any resources allocated are released.
200+
201+ Parameters
202+ ----------
203+ type : type or None
204+ The exception type, if an exception occurred within the context block, or None otherwise.
205+ value : Exception or None
206+ The exception instance, if an exception occurred within the context block, or None otherwise.
207+ tb : traceback or None
208+ The traceback object, if an exception occurred within the context block, or None otherwise.
209+
210+ Returns
211+ -------
212+ bool
213+ If True, suppresses the exception. Otherwise, the exception is propagated.
214+ """
158215 if tb is None :
159216 self .release_data ()
160217
161218 def __del__ (self ):
219+ """Release the license when the instance is deleted."""
162220 self .release_data ()
163221 pass
164222
@@ -176,6 +234,7 @@ def status(self):
176234
177235class ServerContext :
178236 """The context defines whether DPF capabilities requiring a license checkout are allowed.
237+
179238 xml_path argument won't be taken into account if using LicensingContextType.entry.
180239
181240 Parameters
@@ -211,13 +270,15 @@ def xml_path(self):
211270 return self ._xml_path
212271
213272 def __str__ (self ):
273+ """Return string representation of the ServerContext instance."""
214274 return (
215275 f"Server Context of type { self .licensing_context_type } "
216276 f" with { 'no' if len (self .xml_path ) == 0 else '' } xml path"
217277 f"{ '' if len (self .xml_path ) == 0 else ': ' + self .xml_path } "
218278 )
219279
220280 def __eq__ (self , other ):
281+ """Compare two ServerContext instances for equality."""
221282 if not isinstance (other , ServerContext ):
222283 return False
223284 return os .path .normpath (self .xml_path ) == os .path .normpath (
@@ -227,6 +288,7 @@ def __eq__(self, other):
227288 )
228289
229290 def __ne__ (self , other ):
291+ """Check that two server contexts are not equal."""
230292 return not self == other
231293
232294
@@ -266,8 +328,9 @@ class AvailableServerContexts:
266328
267329
268330def set_default_server_context (context = AvailableServerContexts .premium ) -> None :
269- """Sets this context as default for any new server. Also applies it to
270- the global server if it is running as Entry and requested context is Premium.
331+ """Set this context as default for any new server.
332+
333+ Also applies it to the global server if it is running as Entry and requested context is Premium.
271334
272335 The context enables to choose whether DPF capabilities requiring a license checkout are allowed.
273336
0 commit comments