utils¤
Common utility functions.
check_dot_net_config ¤
check_dot_net_config(py_exe_path)
Checks if the useLegacyV2RuntimeActivationPolicy property is enabled.
By default, Python.NET works with .NET 4.0+ and therefore it cannot automatically load a library that was compiled with .NET < 4.0.
This function ensures that the useLegacyV2RuntimeActivationPolicy property is defined in the py_exe_path.config file and that it is enabled.
This link provides an overview explaining why the useLegacyV2RuntimeActivationPolicy property is required.
The py_exe_path.config file that is created is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
py_exe_path
|
PathLike
|
The path to a Python executable. |
required |
Returns:
Type | Description |
---|---|
tuple[int, str]
|
A status flag and a message describing the outcome. The flag will be one of the following values:
|
Source code in src/msl/loadlib/utils.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
generate_com_wrapper ¤
generate_com_wrapper(lib, out_dir=None)
Generate a Python wrapper module around a COM library.
For more information see Accessing type libraries.
Attention
This function is only supported on Windows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lib
|
Any
|
The COM library to create a wrapper of. Can be any of the following:
|
required |
out_dir
|
PathLike | None
|
The output directory to save the wrapper to. If not specified,
the module is saved to the |
None
|
Returns:
Type | Description |
---|---|
ModuleType
|
The wrapper module that was generated. |
Added in version 0.9
Source code in src/msl/loadlib/utils.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
get_available_port ¤
get_available_port()
int — Returns a port number that is available.
Source code in src/msl/loadlib/utils.py
235 236 237 238 239 240 241 |
|
get_com_info ¤
get_com_info(*additional_keys)
Reads the registry for the COM libraries that are available.
Attention
This function is only supported on Windows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
additional_keys
|
str
|
The Program ID ( |
()
|
Example:
from msl.loadlib import utils
info = utils.get_com_info()
more_info = utils.get_com_info("Version", "ToolboxBitmap32")
Returns:
Type | Description |
---|---|
dict[str, dict[str, str | None]]
|
The keys are the Class ID's and each value is a dict of the information that was requested. |
Added in version 0.5
Source code in src/msl/loadlib/utils.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
is_comtypes_installed ¤
is_comtypes_installed()
Checks if comtypes
is installed.
Returns:
Type | Description |
---|---|
bool
|
Whether |
Added in version 0.5
Source code in src/msl/loadlib/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
is_port_in_use ¤
is_port_in_use(port)
Checks whether the TCP port is in use.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port
|
int
|
The port number to test. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the TCP port is in use. |
Changed in version 0.10
Only check TCP ports (instead of both TCP and UDP ports).
Uses the ss
command instead of netstat
on Linux.
Changed in version 0.7
Renamed from port_in_use
and added support for macOS.
Source code in src/msl/loadlib/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
is_py4j_installed ¤
is_py4j_installed()
Checks if py4j
is installed.
Returns:
Type | Description |
---|---|
bool
|
Whether |
Added in version 0.4
Source code in src/msl/loadlib/utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
is_pythonnet_installed ¤
is_pythonnet_installed()
Checks if pythonnet
is installed.
Returns:
Type | Description |
---|---|
bool
|
Whether |
Source code in src/msl/loadlib/utils.py
56 57 58 59 60 61 62 63 64 65 66 |
|
wait_for_server ¤
wait_for_server(host, port, timeout)
Wait for the 32-bit server to start.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The hostname or IP address of the server. |
required |
port
|
int
|
The port number of the server. |
required |
timeout
|
float
|
The maximum number of seconds to wait to establish a connection to the server. |
required |
Raises:
Type | Description |
---|---|
ConnectionTimeoutError
|
If a timeout occurred. |
Source code in src/msl/loadlib/utils.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|