pyloid 0.23.6__py3-none-any.whl → 0.23.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyloid/utils.py
CHANGED
@@ -7,23 +7,43 @@ import socket
|
|
7
7
|
|
8
8
|
def get_production_path(path: Optional[str] = None) -> Optional[str]:
|
9
9
|
"""
|
10
|
-
|
11
|
-
|
10
|
+
Constructs the absolute path to a resource file, adjusting based on the execution environment.
|
11
|
+
|
12
|
+
In a production environment (e.g., when packaged with PyInstaller or Nuitka),
|
13
|
+
it prepends the application's base directory (sys._MEIPASS for PyInstaller,
|
14
|
+
or the directory of the executable for Nuitka) to the provided relative path.
|
15
|
+
If no path is provided, it returns the base path itself.
|
16
|
+
|
17
|
+
If not running in a production environment (e.g., during development as a regular
|
18
|
+
Python script), it simply returns the provided path as is. If no path is provided,
|
19
|
+
it returns None in a non-production environment.
|
20
|
+
|
21
|
+
Parameters
|
22
|
+
----------
|
23
|
+
path : Optional[str], optional
|
24
|
+
The relative path to the resource file from the application's root directory.
|
25
|
+
Defaults to None.
|
12
26
|
|
13
27
|
Returns
|
14
28
|
-------
|
15
|
-
str
|
16
|
-
The path to the resource
|
17
|
-
|
29
|
+
Optional[str]
|
30
|
+
- If in production: The absolute path to the resource file (or the base path if `path` is None).
|
31
|
+
- If not in production: The original `path` value passed to the function.
|
18
32
|
|
19
33
|
Examples
|
20
34
|
--------
|
21
|
-
>>>
|
22
|
-
>>>
|
23
|
-
|
24
|
-
>>>
|
25
|
-
|
26
|
-
|
35
|
+
>>> # Assume running NOT in production
|
36
|
+
>>> get_production_path("assets/icon.ico")
|
37
|
+
'assets/icon.ico'
|
38
|
+
>>> get_production_path()
|
39
|
+
None
|
40
|
+
|
41
|
+
>>> # Assume running IN production (e.g., PyInstaller bundle)
|
42
|
+
>>> # where sys._MEIPASS might be '/tmp/_MEIabcde'
|
43
|
+
>>> get_production_path("assets/icon.ico") # doctest: +SKIP
|
44
|
+
'/tmp/_MEIabcde/assets/icon.ico'
|
45
|
+
>>> get_production_path() # doctest: +SKIP
|
46
|
+
'/tmp/_MEIabcde'
|
27
47
|
"""
|
28
48
|
if is_production():
|
29
49
|
if hasattr(sys, '_MEIPASS'):
|
@@ -40,7 +60,7 @@ def get_production_path(path: Optional[str] = None) -> Optional[str]:
|
|
40
60
|
|
41
61
|
return os.path.join(base_path, path) if path else base_path
|
42
62
|
else:
|
43
|
-
return
|
63
|
+
return path
|
44
64
|
|
45
65
|
|
46
66
|
def is_production() -> bool:
|
@@ -16,8 +16,8 @@ pyloid/thread_pool.py,sha256=fKOBb8jMfZn_7crA_fJCno8dObBRZE31EIWaNQ759aw,14616
|
|
16
16
|
pyloid/timer.py,sha256=RqMsChFUd93cxMVgkHWiIKrci0QDTBgJSTULnAtYT8M,8712
|
17
17
|
pyloid/tray.py,sha256=D12opVEc2wc2T4tK9epaN1oOdeziScsIVNM2uCN7C-A,1710
|
18
18
|
pyloid/url_interceptor.py,sha256=AFjPANDELc9-E-1TnVvkNVc-JZBJYf0677dWQ8LDaqw,726
|
19
|
-
pyloid/utils.py,sha256=
|
20
|
-
pyloid-0.23.
|
21
|
-
pyloid-0.23.
|
22
|
-
pyloid-0.23.
|
23
|
-
pyloid-0.23.
|
19
|
+
pyloid/utils.py,sha256=NqB8W-irXDtTGb74rrJ2swU6tgzU0HSE8lGewrStOKc,5685
|
20
|
+
pyloid-0.23.7.dist-info/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
|
21
|
+
pyloid-0.23.7.dist-info/METADATA,sha256=7P2pX25Afe5LpVh-ydYgYdTiDltSJysxnZ-MY3lXysM,3197
|
22
|
+
pyloid-0.23.7.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
23
|
+
pyloid-0.23.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|