FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MeshLib/scripts/setup_win_python_reqs.py at master · MeshInspector/MeshLib · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
MeshInspector
/
MeshLib
Public
Notifications
You must be signed in to change notification settings
Fork
111
Star
811
Code
Issues
43
Pull requests
18
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
MeshLib
/
scripts
/
setup_win_python_reqs.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (66 loc) · 2.87 KB
Breadcrumbs
MeshLib
/
scripts
/
setup_win_python_reqs.py
Copy path
File metadata and controls
73 lines (66 loc) · 2.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import
platform
import
re
import
os
import
subprocess
from
pathlib
import
Path
def
get_vcpkg_root_from_where
():
try
:
output
=
subprocess
.
check_output
([
"where"
,
"vcpkg"
],
universal_newlines
=
True
)
first_line
=
output
.
strip
().
splitlines
()[
0
]
return
Path
(
first_line
).
resolve
().
parent
except
Exception
as
e
:
print
(
e
)
return
None
def
detect_vcpkg_python_version
(
vcpkg_root
,
triplet
=
"x64-windows-meshlib"
):
include_dir
=
vcpkg_root
/
"installed"
/
triplet
/
"include"
if
include_dir
.
exists
():
for
entry
in
include_dir
.
iterdir
():
match
=
re
.
match
(
r"python3\.(\d+)"
,
entry
.
name
)
if
match
:
minor_version
=
match
.
group
(
1
)
return
f"3.
{
minor_version
}
"
return
None
def
python_version_available
(
version
:
str
)
->
bool
:
try
:
subprocess
.
run
(
f"py -
{
version
}
--version"
,
shell
=
True
,
check
=
True
,
stdout
=
subprocess
.
DEVNULL
,
stderr
=
subprocess
.
DEVNULL
,
)
return
True
except
subprocess
.
CalledProcessError
:
return
False
def
choco_install_python
(
version
:
str
):
version_nodot
=
version
.
replace
(
'.'
,
''
)
# "3.11" -> "311"
choco_package
=
f"python
{
version_nodot
}
"
try
:
print
(
f"Installing
{
choco_package
}
via Chocolatey..."
)
subprocess
.
run
([
"choco"
,
"install"
,
choco_package
,
"-y"
],
check
=
True
)
print
(
f"Successfully installed
{
choco_package
}
"
)
except
subprocess
.
CalledProcessError
:
print
(
f"Failed to install
{
choco_package
}
. Check Chocolatey setup and try again."
)
def
run_python_setup
(
py_version
:
str
):
py_cmd
=
f"py -
{
py_version
}
"
try
:
print
(
f"Ensuring pip is available for Python
{
py_version
}
..."
)
subprocess
.
run
(
f"
{
py_cmd
}
-m ensurepip --upgrade"
,
shell
=
True
,
check
=
True
)
requirements_file
=
Path
(
__file__
).
resolve
().
parents
[
1
]
/
"requirements"
/
"python"
/
"requirements.txt"
if
requirements_file
.
exists
():
subprocess
.
run
(
f"
{
py_cmd
}
-m pip install -r
{
requirements_file
}
"
,
shell
=
True
,
check
=
True
)
else
:
print
(
f"WARNING: Requirements file not found at
{
requirements_file
}
"
)
except
subprocess
.
CalledProcessError
as
e
:
print
(
f"Error during Python setup for
{
py_version
}
:
{
e
}
"
)
exit
(
1
)
if
platform
.
system
()
==
"Windows"
:
vcpkg_root
=
get_vcpkg_root_from_where
()
if
vcpkg_root
:
triplet
=
os
.
environ
.
get
(
"VCPKG_DEFAULT_TRIPLET"
)
or
"x64-windows-meshlib"
detected_version
=
detect_vcpkg_python_version
(
vcpkg_root
,
triplet
=
triplet
)
if
detected_version
:
print
(
f"Using python version
{
detected_version
}
"
)
if
python_version_available
(
detected_version
):
print
(
f"Python
{
detected_version
}
already available, skipping Chocolatey install"
)
else
:
choco_install_python
(
detected_version
)
run_python_setup
(
detected_version
)
Back
|
FazBrowse Home
|
New Git URL