|
15 | 15 |
|
16 | 16 | """The package setup script for modelopt customizing certain aspects of the installation process."""
|
17 | 17 |
|
18 |
| -import glob |
19 | 18 | import os
|
| 19 | +import platform |
20 | 20 |
|
21 | 21 | import setuptools
|
22 |
| -from Cython.Build import cythonize |
23 |
| -from setuptools.command.build_py import build_py |
24 |
| -from setuptools.extension import Extension |
25 |
| -from setuptools_scm import get_version |
26 | 22 |
|
27 | 23 | # Package configuration ############################################################################
|
28 | 24 | name = "nvidia-modelopt"
|
29 |
| -# TODO: Set version to static stable release version when creating the release branch |
30 |
| -# version = os.environ.get("SETUPTOOLS_SCM_PRETEND_VERSION", "X.Y.Z") |
31 |
| -version = get_version(root=".", fallback_version="0.0.0") |
| 25 | +version = os.environ.get( |
| 26 | + "SETUPTOOLS_SCM_PRETEND_VERSION", "0.31.0" if platform.system() == "Linux" else "0.27.0" |
| 27 | +) |
32 | 28 | packages = setuptools.find_namespace_packages(include=["modelopt*"])
|
33 | 29 | package_dir = {"": "."}
|
34 | 30 | package_data = {"modelopt": ["**/*.h", "**/*.cpp", "**/*.cu"]}
|
|
122 | 118 | optional_deps["dev"] = [deps for k in optional_deps for deps in optional_deps[k]]
|
123 | 119 |
|
124 | 120 |
|
125 |
| -# External release overwrites ###################################################################### |
126 |
| -# TODO: Remove this section before copying the setup.py to the modelopt github repository |
127 |
| - |
128 |
| -# You can modify the installation process with the following env variables: |
129 |
| -# - ``MODELOPT_EXTERNAL``: if set to ``true`` (Default is ``False``), external packages (excluding |
130 |
| -# `modelopt.core`) will be packaged into a wheel `nvidia-modelopt`. Also, internal dependencies |
131 |
| -# will not be installed or packaged. This is useful for external releases. |
132 |
| -# - ``MODELOPT_CORE_EXTERNAL``: if set to ``true`` (Default is ``False``), only `modelopt.core` will |
133 |
| -# be compiled into a separate wheel `nvidia-modelopt-core`. This wheel will not have any pip |
134 |
| -# dependencies. This is useful for external releases. |
135 |
| - |
136 |
| -MODELOPT_EXTERNAL = os.environ.get("MODELOPT_EXTERNAL", "false").lower() == "true" |
137 |
| -MODELOPT_CORE_EXTERNAL = os.environ.get("MODELOPT_CORE_EXTERNAL", "false").lower() == "true" |
138 |
| - |
139 |
| -assert not (MODELOPT_EXTERNAL and MODELOPT_CORE_EXTERNAL), ( |
140 |
| - "Cannot set both `MODELOPT_EXTERNAL` and `MODELOPT_CORE_EXTERNAL` to true." |
141 |
| -) |
142 |
| - |
143 |
| - |
144 |
| -if MODELOPT_EXTERNAL: |
145 |
| - packages = setuptools.find_namespace_packages( |
146 |
| - include=[ # Modules for external release (everything except modelopt.core) |
147 |
| - "modelopt", # __init__.py |
148 |
| - "modelopt.deploy*", |
149 |
| - "modelopt.onnx*", |
150 |
| - "modelopt.torch*", |
151 |
| - ] |
152 |
| - ) |
153 |
| -elif MODELOPT_CORE_EXTERNAL: |
154 |
| - name = "nvidia-modelopt-core" |
155 |
| - packages = ["modelopt_core"] + [ |
156 |
| - f"modelopt_core.{p}" for p in setuptools.find_namespace_packages(where="modelopt/core") |
157 |
| - ] |
158 |
| - package_dir = {"modelopt_core": "modelopt/core"} |
159 |
| - package_data = {} |
160 |
| - required_deps = [] |
161 |
| - optional_deps = {} |
162 |
| - |
163 |
| - # Cythonize all non-init files in modelopt_core |
164 |
| - compiled_files = [ |
165 |
| - f.replace(os.sep, "/") # Windows compatible |
166 |
| - for f in glob.iglob("modelopt/core/**/*.py", recursive=True) |
167 |
| - if not f.endswith("__init__.py") |
168 |
| - ] |
169 |
| - ext_modules = cythonize( |
170 |
| - [ |
171 |
| - Extension( |
172 |
| - f.replace("modelopt/core", "modelopt_core").replace(".py", "").replace("/", "."), |
173 |
| - sources=[f], |
174 |
| - ) |
175 |
| - for f in compiled_files |
176 |
| - ], |
177 |
| - compiler_directives={"language_level": "3"}, |
178 |
| - build_dir="build/modelopt_core_build", |
179 |
| - ) |
180 |
| - |
181 |
| - class ModeloptBuildPy(build_py): |
182 |
| - """A custom builder class to modify the python build process for regular installs. |
183 |
| -
|
184 |
| - The build process is executed during ``pip install .``. This is also triggered in certain cases |
185 |
| - during editable installs, i.e., ``pip install -e .``, starting from Python 3.9+. One trigger is |
186 |
| - when new packages are discovered! |
187 |
| - """ |
188 |
| - |
189 |
| - def find_package_modules(self, *args, **kwargs): |
190 |
| - """If a package exists as compiled version skip python version.""" |
191 |
| - return [ |
192 |
| - pm |
193 |
| - for pm in super().find_package_modules(*args, **kwargs) |
194 |
| - if pm[-1].replace(os.sep, "/") not in compiled_files |
195 |
| - ] |
196 |
| - |
197 |
| - setup_kwargs["ext_modules"] = ext_modules |
198 |
| - setup_kwargs["cmdclass"] = {"build_py": ModeloptBuildPy} |
199 |
| -else: |
200 |
| - # remove nvidia-modelopt-core dependency for internal installations / wheels |
201 |
| - required_deps = [dep for dep in required_deps if not dep.startswith("nvidia-modelopt-core")] |
202 |
| - |
203 |
| - |
204 | 121 | if __name__ == "__main__":
|
205 | 122 | setuptools.setup(
|
206 | 123 | name=name,
|
|
0 commit comments