[libclang/python] Enable packaging clang python bindings (#125806)

This adds a pyproject.toml file for packaging the clang Python bindings
as a sdist tarball and pure Python wheel packages for the clang python
bindings. It is required to move updates of the clang and libclang PyPI
packages to the LLVM monorepo. Versioning information is derived from
LLVM git tags (using hatch-vcs, which is based on setuptools_scm), so no
manual updates are needed to bump version numbers. The minimum python
version required is set to 3.10 due to cindex.py using PEP 604 union
type syntax (str | bytes | None).

The .git_archival.txt file is populated with version information needed
to get accurate version information if the bindings are installed from
an LLVM/clang source code archive. The .gitignore file is populated with
files that may get created as part of building/testing the sdist and
wheel that should not be committed to source control.

This is first step for addressing #125220, and moving publishing of the
clang and libclang PyPI packages into the LLVM monorepo.

Signed-off-by: Ryan Mast <mast.ryan@gmail.com>
This commit is contained in:
Ryan Mast
2025-11-24 17:21:24 -08:00
committed by GitHub
parent 78994706d8
commit e6f2fbb0fa
4 changed files with 69 additions and 0 deletions

2
.gitattributes vendored
View File

@@ -1,3 +1,5 @@
clang/bindings/python/.git_archival.txt export-subst
libcxx/src/**/*.cpp merge=libcxx-reformat
libcxx/include/**/*.h merge=libcxx-reformat

View File

@@ -0,0 +1,3 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=llvmorg-*[0-9]*)$

21
clang/bindings/python/.gitignore vendored Normal file
View File

@@ -0,0 +1,21 @@
# setuptools_scm auto-generated version file
_version.py
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Distribution / packaging
build/
dist/
*.egg-info/
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

View File

@@ -0,0 +1,43 @@
[build-system]
requires = ["hatchling>=1.27", "hatch-vcs>=0.4"]
build-backend = "hatchling.build"
[project]
name = "clang"
description = "clang python bindings"
readme = {file = "README.txt", content-type = "text/plain"}
license = "Apache-2.0 WITH LLVM-exception"
authors = [
{ name = "LLVM" }
]
keywords = ["llvm", "clang", "libclang"]
classifiers = [
"Intended Audience :: Developers",
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Compilers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.8"
dynamic = ["version"]
[project.urls]
Homepage = "https://clang.llvm.org/"
Download = "https://llvm.org/releases/download.html"
Discussions = "https://discourse.llvm.org/"
"Issue Tracker" = "https://github.com/llvm/llvm-project/issues"
"Source Code" = "https://github.com/llvm/llvm-project/tree/main/clang/bindings/python"
[tool.hatch.version]
source = "vcs"
version-scheme = "no-guess-dev"
# regex version capture group gets x.y.z with optional -rcN, -aN, -bN suffixes; -init is just consumed
tag-pattern = "^llvmorg-(?P<version>\\d+(?:\\.\\d+)*(?:-rc\\d+)?)"
[tool.hatch.build.hooks.vcs]
version-file = "clang/_version.py"
[tool.hatch.version.raw-options]
search_parent_directories = true
version_scheme = "no-guess-dev"