mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-19 09:10:18 +00:00
impr: prebuild update
This commit is contained in:
parent
90e66a43fe
commit
7dee8114bf
113
prebuild.py
113
prebuild.py
@ -1,70 +1,87 @@
|
|||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
|
import subprocess
|
||||||
from importlib import metadata
|
from importlib import metadata
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# fill VERSION file
|
|
||||||
|
def getGitDesc():
|
||||||
|
gitDescribe = subprocess.run(
|
||||||
|
["git", "describe", "--tags", "--long"],
|
||||||
|
capture_output=True,
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
if gitDescribe.returncode == 0:
|
||||||
|
return gitDescribe.stdout.replace("\n", "")
|
||||||
|
|
||||||
|
# describe failed, try rev-parse
|
||||||
|
gitRevParse = subprocess.run(
|
||||||
|
["git", "rev-parse", "--short", "HEAD"],
|
||||||
|
capture_output=True,
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
if gitRevParse.returncode == 0:
|
||||||
|
return f"commit {gitRevParse.stdout}".replace("\n", "")
|
||||||
|
|
||||||
|
return "version/commit unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def getBuildToolsVer():
|
||||||
|
texts = []
|
||||||
|
possibleBuildTools = ["Nuitka", "pyinstaller"]
|
||||||
|
for possibleBuildTool in possibleBuildTools:
|
||||||
|
try:
|
||||||
|
version = metadata.version(possibleBuildTool)
|
||||||
|
texts.append(f"{possibleBuildTool}=={version}")
|
||||||
|
except metadata.PackageNotFoundError:
|
||||||
|
texts.append(f"{possibleBuildTool} not installed")
|
||||||
|
return ", ".join(texts)
|
||||||
|
|
||||||
|
|
||||||
|
def writeVersionFile():
|
||||||
versionFile = Path("ui/resources/VERSION")
|
versionFile = Path("ui/resources/VERSION")
|
||||||
assert versionFile.exists()
|
assert versionFile.exists()
|
||||||
|
|
||||||
versionTexts = []
|
versionText = (
|
||||||
|
"arcaea-offline-pyside-ui\n{gitDesc}\n{buildToolsVer}\n\n"
|
||||||
|
"{pythonVer}\n\n"
|
||||||
|
"{depsVer}\n"
|
||||||
|
)
|
||||||
|
|
||||||
projectVersionText = "arcaea-offline-pyside-ui\n"
|
gitDesc = getGitDesc()
|
||||||
gitDescribe = os.popen("git describe --tags --long")
|
buildToolsVer = getBuildToolsVer()
|
||||||
gitDescribeContent = gitDescribe.read().replace("\n", "")
|
|
||||||
if gitDescribe.close() is None:
|
|
||||||
projectVersionText += f"{gitDescribeContent}"
|
|
||||||
else:
|
|
||||||
gitRevParse = os.popen("git rev-parse --short HEAD")
|
|
||||||
gitRevParseContent = gitRevParse.read().replace("\n", "")
|
|
||||||
projectVersionText += f"commit {gitRevParseContent}"
|
|
||||||
gitRevParse.close()
|
|
||||||
projectVersionText += "\n"
|
|
||||||
|
|
||||||
versionTexts.append(projectVersionText)
|
pythonVer = f"{platform.python_implementation()} {platform.python_version()} ({platform.python_build()[0]})"
|
||||||
|
|
||||||
|
|
||||||
# detect pip
|
|
||||||
pipName = None
|
|
||||||
possiblePipNames = ["pip3", "pip"]
|
|
||||||
for possiblePipName in possiblePipNames:
|
|
||||||
result = os.popen(possiblePipName).read()
|
|
||||||
if (
|
|
||||||
"<command> [options]" in result
|
|
||||||
and "install" in result
|
|
||||||
and "--upgrade" in result
|
|
||||||
):
|
|
||||||
pipName = possiblePipName
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
# if possiblePipName:
|
|
||||||
# pipFreezeLines = os.popen(f"{possiblePipName} freeze").read().split("\n")
|
|
||||||
# text = [
|
|
||||||
# pipFreezeResult
|
|
||||||
# for pipFreezeResult in pipFreezeLines
|
|
||||||
# if (
|
|
||||||
# "arcaea-offline" in pipFreezeResult
|
|
||||||
# or "PySide6" in pipFreezeResult
|
|
||||||
# or "exif" in pipFreezeResult
|
|
||||||
# or "opencv-python" in pipFreezeResult
|
|
||||||
# or "SQLAlchemy" in pipFreezeResult
|
|
||||||
# )
|
|
||||||
# ]
|
|
||||||
# versionTexts.append("\n".join(text))
|
|
||||||
|
|
||||||
importLibTexts = [
|
importLibTexts = [
|
||||||
f"{module}=={metadata.version(module)}"
|
f"{module}=={metadata.version(module)}"
|
||||||
for module in [
|
for module in sorted(
|
||||||
|
[
|
||||||
"arcaea-offline",
|
"arcaea-offline",
|
||||||
"arcaea-offline-ocr",
|
"arcaea-offline-ocr",
|
||||||
"exif",
|
"exif",
|
||||||
|
"numpy",
|
||||||
"opencv-python",
|
"opencv-python",
|
||||||
|
"Pillow",
|
||||||
"PySide6",
|
"PySide6",
|
||||||
"SQLAlchemy",
|
"SQLAlchemy",
|
||||||
"SQLAlchemy-Utils",
|
"SQLAlchemy-Utils",
|
||||||
|
"Whoosh",
|
||||||
|
],
|
||||||
|
key=lambda s: s.lower(),
|
||||||
|
)
|
||||||
]
|
]
|
||||||
]
|
importLibText = "\n".join(importLibTexts)
|
||||||
versionTexts.append("\n".join(importLibTexts))
|
|
||||||
|
|
||||||
with versionFile.open("w", encoding="utf-8") as vf:
|
with versionFile.open("w", encoding="utf-8") as vf:
|
||||||
vf.write("\n".join(versionTexts))
|
vf.write(
|
||||||
|
versionText.format(
|
||||||
|
gitDesc=gitDesc,
|
||||||
|
buildToolsVer=buildToolsVer,
|
||||||
|
pythonVer=pythonVer,
|
||||||
|
depsVer=importLibText,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
writeVersionFile()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user