omdev 0.0.0.dev63__py3-none-any.whl → 0.0.0.dev65__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.
Potentially problematic release.
This version of omdev might be problematic. Click here for more details.
- omdev/cli/managers.py +2 -43
- omdev/cli/pathhack.py +43 -0
- omdev/pycharm/__init__.py +0 -0
- omdev/pycharm/runhack.py +1357 -0
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/RECORD +10 -7
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev63.dist-info → omdev-0.0.0.dev65.dist-info}/top_level.txt +0 -0
omdev/cli/managers.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import enum
|
|
2
2
|
import os.path
|
|
3
|
-
import site
|
|
4
3
|
import sys
|
|
5
4
|
|
|
6
5
|
|
|
@@ -44,47 +43,6 @@ def detect_install_manager(cli_pkg: str) -> ManagerType | None:
|
|
|
44
43
|
return None
|
|
45
44
|
|
|
46
45
|
|
|
47
|
-
##
|
|
48
|
-
# Python is insistent on prepending sys.path with an empty string (translating to the current working directory),
|
|
49
|
-
# which leads to problems when using the cli in directories containing python packages (such as within this very
|
|
50
|
-
# source tree). This can't be done in cli main as the code frequently spawns other sys.executable processes which
|
|
51
|
-
# wouldn't know to do that, so a .pth file hack is used. Cleaning sys.path solely there is also insufficient as that
|
|
52
|
-
# code runs before the problematic empty string is added, so a sys.meta_path hook is prepended.
|
|
53
|
-
#
|
|
54
|
-
# See:
|
|
55
|
-
# https://github.com/python/cpython/blob/da1e5526aee674bb33c17a498aa3781587b9850c/Python/sysmodule.c#L3939
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _remove_empty_from_sys_path() -> None:
|
|
59
|
-
while '' in sys.path:
|
|
60
|
-
sys.path.remove('')
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
class _PathHackMetaFinder:
|
|
64
|
-
def find_spec(self, fullname, path, target=None):
|
|
65
|
-
_remove_empty_from_sys_path()
|
|
66
|
-
return None # noqa
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def _activate_path_hack() -> None:
|
|
70
|
-
if not any(isinstance(mp, _PathHackMetaFinder) for mp in sys.meta_path):
|
|
71
|
-
sys.meta_path.insert(0, _PathHackMetaFinder())
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_PATH_HACK_FILE_NAME = f'{"-".join(__name__.split("."))}-path-hack.pth'
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _install_path_hack_file() -> None:
|
|
78
|
-
sp = site.getsitepackages()[0]
|
|
79
|
-
if os.path.isfile(fp := os.path.join(sp, _PATH_HACK_FILE_NAME)):
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
with open(fp, 'w') as f:
|
|
83
|
-
f.write(f'import {__name__}; {__name__}._activate_path_hack()')
|
|
84
|
-
|
|
85
|
-
_activate_path_hack()
|
|
86
|
-
|
|
87
|
-
|
|
88
46
|
##
|
|
89
47
|
|
|
90
48
|
|
|
@@ -92,4 +50,5 @@ def setup_install_manager(cli_pkg: str) -> None:
|
|
|
92
50
|
if detect_install_manager(cli_pkg) is None:
|
|
93
51
|
return
|
|
94
52
|
|
|
95
|
-
|
|
53
|
+
from .pathhack import _install_pth_file
|
|
54
|
+
_install_pth_file()
|
omdev/cli/pathhack.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python is insistent on prepending sys.path with an empty string (translating to the current working directory), which
|
|
3
|
+
leads to problems when using the cli in directories containing python packages (such as within this very source tree).
|
|
4
|
+
This can't be done in cli main as the code frequently spawns other sys.executable processes which wouldn't know to do
|
|
5
|
+
that, so a .pth file hack is used. Cleaning sys.path solely there is also insufficient as that code runs before thej
|
|
6
|
+
problematic empty string is added, so a sys.meta_path hook is prepended.
|
|
7
|
+
|
|
8
|
+
See:
|
|
9
|
+
https://github.com/python/cpython/blob/da1e5526aee674bb33c17a498aa3781587b9850c/Python/sysmodule.c#L3939
|
|
10
|
+
"""
|
|
11
|
+
import os.path
|
|
12
|
+
import site
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _remove_empty_from_sys_path() -> None:
|
|
17
|
+
while '' in sys.path:
|
|
18
|
+
sys.path.remove('')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _PathHackMetaFinder:
|
|
22
|
+
def find_spec(self, fullname, path, target=None):
|
|
23
|
+
_remove_empty_from_sys_path()
|
|
24
|
+
return None # noqa
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _activate_path_hack() -> None:
|
|
28
|
+
if not any(isinstance(mp, _PathHackMetaFinder) for mp in sys.meta_path):
|
|
29
|
+
sys.meta_path.insert(0, _PathHackMetaFinder())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
_PTH_FILE_NAME = f'omlish-{"-".join(__package__.split(".")[1:])}-pathhack.pth'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _install_pth_file() -> None:
|
|
36
|
+
sp = site.getsitepackages()[0]
|
|
37
|
+
if os.path.isfile(fp := os.path.join(sp, _PTH_FILE_NAME)):
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
with open(fp, 'w') as f:
|
|
41
|
+
f.write(f'import {__name__}; {__name__}._activate_path_hack()')
|
|
42
|
+
|
|
43
|
+
_activate_path_hack()
|
|
File without changes
|