-
Notifications
You must be signed in to change notification settings - Fork 6k
Expand file tree
/
Copy pathsetup.py
More file actions
184 lines (160 loc) · 5.81 KB
/
setup.py
File metadata and controls
184 lines (160 loc) · 5.81 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
import os
import io
import re
import sys
import subprocess
import platform
import logging
from setuptools import setup, find_namespace_packages
FACE3D_BUILD_FLAG = '--with-face3d'
def strtobool_env(value):
return str(value).strip().lower() in ('1', 'true', 'yes', 'on')
build_face3d = strtobool_env(os.environ.get('INSIGHTFACE_WITH_FACE3D', ''))
if FACE3D_BUILD_FLAG in sys.argv:
build_face3d = True
sys.argv.remove(FACE3D_BUILD_FLAG)
def read(*names, **kwargs):
with io.open(os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")) as fp:
return fp.read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
pypandoc_enabled = True
try:
import pypandoc
print('pandoc enabled')
long_description = pypandoc.convert_file('README.md', 'rst')
except (IOError, ImportError, ModuleNotFoundError):
print('WARNING: pandoc not enabled')
long_description = read('README.md')
pypandoc_enabled = False
#import pypandoc
#long_description = pypandoc.convert('README.md', 'rst')
VERSION = find_version('insightface', '__init__.py')
requirements = [
'numpy',
'onnx',
'onnxruntime',
'opencv-python',
'tqdm',
'requests',
'scipy',
#'opencv-python',
'scikit-image',
]
gui_requirements = [
'PySide6-Essentials>=6.5',
'Pillow',
'reportlab',
'scikit-learn',
]
face3d_requirements = [
'cython',
'albumentations',
'matplotlib',
]
package_data = {
"insightface.data.images": ["*.jpg", "*.jpeg", "*.png"],
"insightface.data.objects": ["*.pkl"],
"insightface.gui.assets": ["*.png", "*.ico", "*.icns"],
}
packages = find_namespace_packages(
include=("insightface", "insightface.*"),
exclude=("docs", "docs.*", "tests", "tests.*", "scripts", "scripts.*"),
)
if not build_face3d:
packages = [
package
for package in packages
if package != "insightface.thirdparty.face3d.mesh.cython"
]
ext_modules = []
include_dirs = []
headers = []
if build_face3d:
import numpy
from distutils.core import Extension
from Cython.Build import cythonize
extensions = [
Extension("insightface.thirdparty.face3d.mesh.cython.mesh_core_cython",
["insightface/thirdparty/face3d/mesh/cython/mesh_core_cython.pyx", "insightface/thirdparty/face3d/mesh/cython/mesh_core.cpp"], language='c++'),
]
package_data["insightface.thirdparty.face3d.mesh.cython"] = [
"*.h",
"*.c",
"*.cpp",
"*.pyx",
"*.py",
]
ext_modules = cythonize(extensions)
include_dirs = [numpy.get_include()]
headers = ['insightface/thirdparty/face3d/mesh/cython/mesh_core.h']
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
# Check if running on macOS (Darwin)
if platform.system() == "Darwin":
logging.info("Detected macOS. Checking if Homebrew, LLVM, and OpenMP are installed...")
# Check if Homebrew is installed
brew_check = subprocess.run(["which", "brew"], capture_output=True, text=True)
if brew_check.returncode != 0:
logging.warning("Homebrew is not installed. You may need to manually install dependencies.")
logging.warning(" Install Homebrew: https://brew.sh/")
logging.warning(" Then, run: brew install llvm libomp")
logging.info("Proceeding without setting the compiler.")
else:
# Check if LLVM is installed
llvm_check = subprocess.run(["brew", "--prefix", "llvm"], capture_output=True, text=True)
if llvm_check.returncode != 0:
logging.warning("LLVM is not installed. This may cause installation issues.")
logging.warning(" To install, run: brew install llvm libomp")
logging.warning(" Then, restart the installation process.")
logging.info("Proceeding without setting the compiler.")
else:
# Set compiler dynamically if LLVM is installed
llvm_path = subprocess.getoutput("brew --prefix llvm")
llvm_cc = f"{llvm_path}/bin/clang"
llvm_cxx = f"{llvm_path}/bin/clang++"
if os.path.exists(llvm_cc) and os.path.exists(llvm_cxx):
os.environ["CC"] = llvm_cc
os.environ["CXX"] = llvm_cxx
logging.info(f"Using compiler: {os.environ['CC']}")
else:
logging.warning("Homebrew LLVM path exists but clang/clang++ was not found.")
logging.info("Falling back to the default system compiler.")
setup(
# Metadata
name='insightface',
version=VERSION,
author='InsightFace Contributors',
author_email='contact@insightface.ai',
url='https://github.com/deepinsight/insightface',
description='InsightFace Python Library',
long_description=long_description,
long_description_content_type='text/markdown',
# Package info
packages=packages,
package_data=package_data,
zip_safe=True,
include_package_data=False,
entry_points={
"console_scripts": [
"insightface-cli=insightface.commands.insightface_cli:main",
"insightface-gui=insightface.gui.__main__:main",
"insightface-eval-studio=insightface.gui.__main__:main",
"insightface-desktop=insightface.gui.__main__:main",
]
},
extras_require={"gui": gui_requirements, "face3d": face3d_requirements},
install_requires=requirements,
headers=headers,
ext_modules=ext_modules,
include_dirs=include_dirs,
)
print('pypandoc enabled:', pypandoc_enabled)
print('face3d build enabled:', build_face3d)