|
11 | 11 | """ |
12 | 12 |
|
13 | 13 | import os |
14 | | -from pathlib import Path |
| 14 | +import sys |
| 15 | +import stat |
| 16 | +import shutil |
| 17 | +import locale |
| 18 | +import tempfile |
15 | 19 | import subprocess |
| 20 | +import configparser as cp |
| 21 | +from pathlib import Path |
16 | 22 | import re |
17 | 23 | import tarfile |
18 | 24 | import zipfile |
19 | | -import tempfile |
20 | | -import shutil |
21 | 25 | import atexit |
22 | | -import sys |
23 | | -import stat |
24 | | -import locale |
25 | 26 | import io |
26 | | -import configparser as cp |
27 | | - |
28 | | -# Local imports |
29 | 27 | import winreg |
30 | 28 |
|
31 | | -def get_python_executable(path = None): |
32 | | - """return the python executable""" |
33 | | - my_path = sys.executable if path == None else path # default = current one |
34 | | - my_path = my_path if Path(my_path).is_dir() else str(Path(my_path).parent) |
35 | | - exec_py = str(Path(my_path) / 'python.exe') |
36 | | - exec_pypy = str(Path(my_path) / 'pypy3.exe') # PyPy ! |
37 | | - # PyPy >=7.3.6 3.8 aligns to python.exe and Lib\site-packages |
38 | | - python_executable = exec_py if Path(exec_py).is_file() else exec_pypy |
39 | | - return python_executable |
40 | | - |
41 | | -def get_site_packages_path(path = None): |
42 | | - """return the python site-packages""" |
43 | | - my_path = sys.executable if path == None else path # default = current one |
44 | | - my_path = my_path if Path(my_path).is_dir() else str(Path(my_path).parent) |
45 | | - site_py = str(Path(my_path) / 'Lib' / 'site-packages') |
46 | | - site_pypy = str(Path(my_path) / 'site-packages') # PyPy !! |
47 | | - site_packages_path = site_pypy if Path(site_pypy).is_dir() else site_py |
48 | | - return site_packages_path |
| 29 | +def get_python_executable(path=None): |
| 30 | + """Return the path to the Python executable.""" |
| 31 | + python_path = sys.executable if path is None else path |
| 32 | + base_dir = Path(python_path).parent if not Path(python_path).is_dir() else Path(python_path) |
| 33 | + python_exe = base_dir / 'python.exe' |
| 34 | + pypy_exe = base_dir / 'pypy3.exe' # For PyPy |
| 35 | + return str(python_exe if python_exe.is_file() else pypy_exe) |
| 36 | + |
| 37 | +def get_site_packages_path(path=None): |
| 38 | + """Return the path to the Python site-packages directory.""" |
| 39 | + python_path = sys.executable if path is None else path |
| 40 | + base_dir = Path(python_path).parent if not Path(python_path).is_dir() else Path(python_path) |
| 41 | + site_packages = base_dir / 'Lib' / 'site-packages' |
| 42 | + pypy_site_packages = base_dir / 'site-packages' # For PyPy |
| 43 | + return str(pypy_site_packages if pypy_site_packages.is_dir() else site_packages) |
49 | 44 |
|
50 | 45 | def onerror(function, path, excinfo): |
51 | 46 | """Error handler for `shutil.rmtree`. |
|
0 commit comments