setup.py
This is the Python setup.py
script used for packaging and distributing the tensorrt_llm
project.
Imports
It imports necessary modules: os
, platform
, Path
from pathlib
, find_packages
and setup
from setuptools
, and Distribution
from setuptools.dist
.
Parse Requirements
The parse_requirements
function in the setup.py
file is designed to parse the contents of a requirements file to extract the list of dependencies and any additional URLs that might be specified for dependency resolution.
Opening the Requirements File
The function accepts a filename as an argument, which is expected to be a path to a requirements file. It opens this file and reads its contents line by line.
Reading and Splitting Lines
Each line in the requirements file is read individually. The lines are typically a list of package names with optional version specifiers, but they can also include comments (lines starting with #
) or additional options like -i
or --extra-index-url
.
Extracting Extra URLs
if a line contains -i
or --extra-index-url
, it's specifying an additional package index URL where dependencies can be searched for. The URL is extracted and added to a list of extra URLs. This is important for dependencies that are not hosted on the Python Package Index (PyPI).
If a line doesn't start with a comment, recursive include, or extra URL directive, it's assumed to be a package dependency. These dependencies are added to a list.
Return Values
The function returns two lists: one containing the dependencies and another containing the extra URLs. These lists are then used in the setup
function to specify the package's dependencies and any additional repositories to search for these dependencies.
By parsing the requirements file in this manner, the setup.py
script can dynamically determine the dependencies needed for the package and where to find them. This approach enables a more flexible and configurable setup process, accommodating packages that may have dependencies not readily available on the standard package index.
Get Version
The get_version
function is defined to retrieve the version number from the version.py
file located in the tensorrt_llm
directory. It reads the file, looks for the line starting with __version__
, and extracts the version string.
Binary Distribution
The BinaryDistribution
class is defined as a subclass of setuptools.dist.Distribution
.
It overrides the has_ext_modules
method to always return True
, forcing the distribution to be treated as a binary package with a platform name.
Entry Points
The entry_points
attribute defines the console scripts that will be installed with the package.
In this case, it includes the trtllm-build
command, which is mapped to the tensorrt_llm.commands.build:main
function.
This means that when the package is installed, the trtllm-build
command will be available in the system's PATH, and running it will execute the main
function from the tensorrt_llm.commands.build
module.
Platform
The script determines the platform by checking if platform.system()
returns "Windows"
. It then parses the required dependencies and extra URLs from the appropriate requirements file based on the platform (requirements-windows.txt
for Windows, requirements.txt
otherwise).
It also parses the development dependencies from requirements-dev-windows.txt
or requirements-dev.txt
.
The setup
function is called with various arguments to configure the package:
name
: The name of the package ('tensorrt_llm'
).version
: The version obtained from theget_version
function.description
A description of the package.author
: The author of the package ("
NVIDIA Corporation
"
).url
anddownload_url
: URLs for the project's repository and download page.packages
: The packages to include, obtained usingfind_packages()
.classifiers
: A list of classifiers describing the package's development status, intended audience, and Python version compatibility.distclass
: TheBinaryDistribution
class, indicating that the package is a binary distribution.license
: The license under which the package is distributed ("Apache License 2.0"
).keywords
: Keywords related to the package.package_data
: Data files to include in the package, such as shared libraries (.dll
or.so
files) and binding files (.pyd
or.so
).entry_points
: Entry points for console scripts, in this case,trtllm-build
pointing to thetensorrt_llm.commands.build:main
function.extras_require
: Optional dependencies for development ("devel"
) and benchmarking ("benchmarking"
).zip_safe
: Indicates whether the package can be safely installed and used as a ZIP file (True
).install_requires
: The list of required dependencies obtained fromparse_requirements
.dependency_links
: Extra URLs for package indexes, obtained fromparse_requirements
. (Note: This feature has been dropped in newer versions of pip.)python_requires
: The compatible Python version range ("
>=3.7, <4
"
).
This setup.py
script provides a comprehensive configuration for packaging and distributing the tensorrt_llm
project, including dependencies, entry points, and platform-specific settings.
It ensures that the package can be easily installed and used by developers and users.
Last updated