1 Star 0 Fork 6

蒲公英/Glass-Engine

forked from Time-Coder/Glass-Engine 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
setup_assimpy.py 4.60 KB
一键复制 编辑 原始数据 按行查看 历史
Time-Coder 提交于 2024-05-30 22:30 . optimize assimpy build scripts
import platform
import zipfile
import subprocess
import shutil
import sys
import os
try:
import requests
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "requests"])
import requests
def public_ip():
try:
response = requests.get("https://httpbin.org/ip")
return response.json().get("origin")
except:
return "127.0.0.1"
def is_China_ip(ip_address):
try:
response = requests.get(f"https://ipinfo.io/{ip_address}/json/")
data = response.json()
return data['country'] == 'CN'
except Exception as e:
return True
_is_China_user = None
def is_China_user():
global _is_China_user
if _is_China_user is None:
_is_China_user = is_China_ip(public_ip())
return _is_China_user
def pip_install(package):
if is_China_user():
subprocess.check_call([sys.executable, "-m", "pip", "install", package, "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"])
else:
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
try:
import setuptools
except ImportError:
pip_install("setuptools")
import setuptools
bits = platform.architecture()[0]
if bits == '64bit':
bits = 'x64'
else:
bits = 'Win32'
extra_flags = []
if platform.system() == "Windows":
extra_flags = ["-A", bits]
library_dirs = [
f"build/assimp-5.4.1/{bits}/lib/MinSizeRel",
f"build/assimp-5.4.1/{bits}/contrib/zlib/MinSizeRel"
]
else:
library_dirs = [
f"build/assimp-5.4.1/{bits}/lib",
f"build/assimp-5.4.1/{bits}/contrib/zlib"
]
if shutil.which("ninja") is not None:
extra_flags = ["-G", "Ninja"]
if (
(
not os.path.isfile(library_dirs[0] + "/assimp.lib") and
not os.path.isfile(library_dirs[0] + "/assimp.a") and
not os.path.isfile(library_dirs[0] + "/libassimp.lib") and
not os.path.isfile(library_dirs[0] + "/libassimp.a")
) or (
not os.path.isfile(library_dirs[1] + "/zlibstatic.lib") and
not os.path.isfile(library_dirs[1] + "/zlibstatic.a") and
not os.path.isfile(library_dirs[1] + "/libzlibstatic.lib") and
not os.path.isfile(library_dirs[1] + "/libzlibstatic.a")
)
):
zip_file = zipfile.ZipFile("assimpy/assimp-5.4.1.zip")
zip_file.extractall("assimpy")
zip_file.close()
zip_file = zipfile.ZipFile("assimpy/pybind11-2.12.0.zip")
zip_file.extractall("assimpy")
zip_file.close()
if shutil.which("cmake") is None:
pip_install("cmake")
subprocess.check_call(
[
"cmake", "assimpy/assimp-5.4.1",
"-B", f"build/assimp-5.4.1/{bits}",
"-DCMAKE_CONFIGURATION_TYPES=MinSizeRel",
"-DBUILD_SHARED_LIBS=OFF",
"-DASSIMP_BUILD_TESTS=OFF",
"-DASSIMP_INJECT_DEBUG_POSTFIX=OFF",
"-DASSIMP_INSTALL=OFF",
"-DASSIMP_INSTALL_PDB=OFF",
"-DASSIMP_WARNINGS_AS_ERRORS=OFF",
"-DLIBRARY_SUFFIX="
] + extra_flags
)
subprocess.check_call(
[
"cmake", "--build", f"build/assimp-5.4.1/{bits}", "--config", "MinSizeRel", "--parallel"
]
)
ext = setuptools.Extension(
"assimpy_ext",
sources=[
"assimpy/assimpy_ext.cpp",
"assimpy/module.cpp"
],
include_dirs=[
"assimpy",
"assimpy/pybind11-2.12.0/include",
"assimpy/assimp-5.4.1/include",
f"build/assimp-5.4.1/{bits}/include"
],
libraries=[
"assimp",
"zlibstatic"
],
library_dirs=library_dirs
)
if platform.system() != "Windows":
ext.extra_compile_args = ["-std=c++11"]
ext_modules = [ext]
extra_files = ["LICENSE", "__pyinstaller/assimp/LICENSE", "__pyinstaller/pybind11/LICENSE"]
with open("assimpy/README_PYPI.md", "r", encoding='utf-8') as in_file:
long_description = in_file.read()
setuptools.setup(
name="assimpy",
version="5.4.1",
author="王炳辉 (BingHui-WANG)",
author_email="binghui.wang@foxmail.com",
description="3D model loader for Glass-Engine",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Time-Coder/Glass-Engine",
include_package_data=False,
python_requires=">=3.7",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
'Operating System :: OS Independent',
],
packages=["assimpy", "assimpy/__pyinstaller"],
package_data={
'assimpy': extra_files,
},
ext_modules=ext_modules,
entry_points={'pyinstaller40': ['hook-dirs = assimpy.__pyinstaller:get_hook_dirs']}
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/knight_of_liam/Glass-Engine.git
git@gitee.com:knight_of_liam/Glass-Engine.git
knight_of_liam
Glass-Engine
Glass-Engine
main

搜索帮助