Skip to content

Commit 4d05149

Browse files
author
motorbottle
committed
update python venv for win again
1 parent ccd0986 commit 4d05149

File tree

1,419 files changed

+122334
-649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,419 files changed

+122334
-649
lines changed

install_dependencies.cmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
@echo off
22
SETLOCAL
33

4-
REM Set the directory where the bundled Python is located
5-
SET PYTHON_DIR=%~dp0..\python
4+
@REM REM Set the directory where the bundled Python is located
5+
@REM SET PYTHON_DIR=%~dp0..\python
66

7-
REM Ensure the Python executable and Scripts directory are in the PATH
8-
SET PATH=%PYTHON_DIR%;%PYTHON_DIR%\Scripts;%PATH%
7+
@REM REM Ensure the Python executable and Scripts directory are in the PATH
8+
@REM SET PATH=%PYTHON_DIR%;%PYTHON_DIR%\Scripts;%PATH%
99

10-
REM Optionally check Python version
11-
%PYTHON_DIR%\python.exe --version
10+
@REM REM Optionally check Python version
11+
@REM %PYTHON_DIR%\python.exe --version
1212

13-
REM Optionally list installed packages to verify the environment
14-
%PYTHON_DIR%\python.exe -m pip list
13+
@REM REM Optionally list installed packages to verify the environment
14+
@REM %PYTHON_DIR%\python.exe -m pip list
1515

1616
ENDLOCAL

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let pythonScriptPath = path.join(process.resourcesPath, 'GetFont.py');
4747
let pythonExecutablePath;
4848
if (process.platform === "win32") {
4949
// Path for Windows bundled Python executable
50-
pythonExecutablePath = path.join(process.resourcesPath, 'python', 'Scripts', 'python.exe'); // For Windows
50+
pythonExecutablePath = path.join(process.resourcesPath, 'python', 'python.exe'); // For Windows
5151
} else {
5252
// Default to system Python on macOS (and potentially other Unix-like systems)
5353
pythonExecutablePath = 'python3';

python/LICENSE.txt

Lines changed: 702 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# don't import any costly modules
2+
import sys
3+
import os
4+
5+
6+
def warn_distutils_present():
7+
if 'distutils' not in sys.modules:
8+
return
9+
import warnings
10+
11+
warnings.warn(
12+
"Distutils was imported before Setuptools, but importing Setuptools "
13+
"also replaces the `distutils` module in `sys.modules`. This may lead "
14+
"to undesirable behaviors or errors. To avoid these issues, avoid "
15+
"using distutils directly, ensure that setuptools is installed in the "
16+
"traditional way (e.g. not an editable install), and/or make sure "
17+
"that setuptools is always imported before distutils."
18+
)
19+
20+
21+
def clear_distutils():
22+
if 'distutils' not in sys.modules:
23+
return
24+
import warnings
25+
26+
warnings.warn("Setuptools is replacing distutils.")
27+
mods = [
28+
name
29+
for name in sys.modules
30+
if name == "distutils" or name.startswith("distutils.")
31+
]
32+
for name in mods:
33+
del sys.modules[name]
34+
35+
36+
def enabled():
37+
"""
38+
Allow selection of distutils by environment variable.
39+
"""
40+
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
41+
return which == 'local'
42+
43+
44+
def ensure_local_distutils():
45+
import importlib
46+
47+
clear_distutils()
48+
49+
# With the DistutilsMetaFinder in place,
50+
# perform an import to cause distutils to be
51+
# loaded from setuptools._distutils. Ref #2906.
52+
with shim():
53+
importlib.import_module('distutils')
54+
55+
# check that submodules load as expected
56+
core = importlib.import_module('distutils.core')
57+
assert '_distutils' in core.__file__, core.__file__
58+
assert 'setuptools._distutils.log' not in sys.modules
59+
60+
61+
def do_override():
62+
"""
63+
Ensure that the local copy of distutils is preferred over stdlib.
64+
65+
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
66+
for more motivation.
67+
"""
68+
if enabled():
69+
warn_distutils_present()
70+
ensure_local_distutils()
71+
72+
73+
class _TrivialRe:
74+
def __init__(self, *patterns):
75+
self._patterns = patterns
76+
77+
def match(self, string):
78+
return all(pat in string for pat in self._patterns)
79+
80+
81+
class DistutilsMetaFinder:
82+
def find_spec(self, fullname, path, target=None):
83+
# optimization: only consider top level modules and those
84+
# found in the CPython test suite.
85+
if path is not None and not fullname.startswith('test.'):
86+
return None
87+
88+
method_name = 'spec_for_{fullname}'.format(**locals())
89+
method = getattr(self, method_name, lambda: None)
90+
return method()
91+
92+
def spec_for_distutils(self):
93+
if self.is_cpython():
94+
return None
95+
96+
import importlib
97+
import importlib.abc
98+
import importlib.util
99+
100+
try:
101+
mod = importlib.import_module('setuptools._distutils')
102+
except Exception:
103+
# There are a couple of cases where setuptools._distutils
104+
# may not be present:
105+
# - An older Setuptools without a local distutils is
106+
# taking precedence. Ref #2957.
107+
# - Path manipulation during sitecustomize removes
108+
# setuptools from the path but only after the hook
109+
# has been loaded. Ref #2980.
110+
# In either case, fall back to stdlib behavior.
111+
return None
112+
113+
class DistutilsLoader(importlib.abc.Loader):
114+
def create_module(self, spec):
115+
mod.__name__ = 'distutils'
116+
return mod
117+
118+
def exec_module(self, module):
119+
pass
120+
121+
return importlib.util.spec_from_loader(
122+
'distutils', DistutilsLoader(), origin=mod.__file__
123+
)
124+
125+
@staticmethod
126+
def is_cpython():
127+
"""
128+
Suppress supplying distutils for CPython (build and tests).
129+
Ref #2965 and #3007.
130+
"""
131+
return os.path.isfile('pybuilddir.txt')
132+
133+
def spec_for_pip(self):
134+
"""
135+
Ensure stdlib distutils when running under pip.
136+
See pypa/pip#8761 for rationale.
137+
"""
138+
if sys.version_info >= (3, 12) or self.pip_imported_during_build():
139+
return
140+
clear_distutils()
141+
self.spec_for_distutils = lambda: None
142+
143+
@classmethod
144+
def pip_imported_during_build(cls):
145+
"""
146+
Detect if pip is being imported in a build script. Ref #2355.
147+
"""
148+
import traceback
149+
150+
return any(
151+
cls.frame_file_is_setup(frame) for frame, line in traceback.walk_stack(None)
152+
)
153+
154+
@staticmethod
155+
def frame_file_is_setup(frame):
156+
"""
157+
Return True if the indicated frame suggests a setup.py file.
158+
"""
159+
# some frames may not have __file__ (#2940)
160+
return frame.f_globals.get('__file__', '').endswith('setup.py')
161+
162+
def spec_for_sensitive_tests(self):
163+
"""
164+
Ensure stdlib distutils when running select tests under CPython.
165+
166+
python/cpython#91169
167+
"""
168+
clear_distutils()
169+
self.spec_for_distutils = lambda: None
170+
171+
sensitive_tests = (
172+
[
173+
'test.test_distutils',
174+
'test.test_peg_generator',
175+
'test.test_importlib',
176+
]
177+
if sys.version_info < (3, 10)
178+
else [
179+
'test.test_distutils',
180+
]
181+
)
182+
183+
184+
for name in DistutilsMetaFinder.sensitive_tests:
185+
setattr(
186+
DistutilsMetaFinder,
187+
f'spec_for_{name}',
188+
DistutilsMetaFinder.spec_for_sensitive_tests,
189+
)
190+
191+
192+
DISTUTILS_FINDER = DistutilsMetaFinder()
193+
194+
195+
def add_shim():
196+
DISTUTILS_FINDER in sys.meta_path or insert_shim()
197+
198+
199+
class shim:
200+
def __enter__(self):
201+
insert_shim()
202+
203+
def __exit__(self, exc, value, tb):
204+
_remove_shim()
205+
206+
207+
def insert_shim():
208+
sys.meta_path.insert(0, DISTUTILS_FINDER)
209+
210+
211+
def _remove_shim():
212+
try:
213+
sys.meta_path.remove(DISTUTILS_FINDER)
214+
except ValueError:
215+
pass
216+
217+
218+
if sys.version_info < (3, 12):
219+
# DistutilsMetaFinder can only be disabled in Python < 3.12 (PEP 632)
220+
remove_shim = _remove_shim
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('_distutils_hack').do_override()
106 KB
Binary file not shown.
106 KB
Binary file not shown.
106 KB
Binary file not shown.

0 commit comments

Comments
 (0)