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

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 4 22:13:30 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ryan Mast (nightlark)

<details>
<summary>Changes</summary>

Add files for packaging libclang Python bindings as a sdist tarball and pure Python wheel. setuptools_scm is used to derive version numbers from git tags for a future workflow that automates publishing updated versions for new LLVM releases. The .git_archival.txt file is populated with version information needed to get accurate version information if the bindings are ever 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 would be the first step for addressing #<!-- -->125220. Subsequent steps include a workflow for automating new releases, and sorting out the package name on PyPI.

---
Full diff: https://github.com/llvm/llvm-project/pull/125806.diff


4 Files Affected:

- (added) .git_archival.txt (+3) 
- (modified) .gitattributes (+2) 
- (added) clang/bindings/python/.gitignore (+21) 
- (added) clang/bindings/python/pyproject.toml (+34) 


``````````diff
diff --git a/.git_archival.txt b/.git_archival.txt
new file mode 100644
index 000000000000000..7c5100942aae489
--- /dev/null
+++ b/.git_archival.txt
@@ -0,0 +1,3 @@
+node: $Format:%H$
+node-date: $Format:%cI$
+describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
diff --git a/.gitattributes b/.gitattributes
index 6b281f33f737db9..b94d65d60a8840a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,5 @@
+.git_archival.txt  export-subst
+
 libcxx/src/**/*.cpp     merge=libcxx-reformat
 libcxx/include/**/*.h   merge=libcxx-reformat
 
diff --git a/clang/bindings/python/.gitignore b/clang/bindings/python/.gitignore
new file mode 100644
index 000000000000000..da1a0b4b0aa60d2
--- /dev/null
+++ b/clang/bindings/python/.gitignore
@@ -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/
\ No newline at end of file
diff --git a/clang/bindings/python/pyproject.toml b/clang/bindings/python/pyproject.toml
new file mode 100644
index 000000000000000..1097f76f7e00787
--- /dev/null
+++ b/clang/bindings/python/pyproject.toml
@@ -0,0 +1,34 @@
+[build-system]
+requires = ["setuptools>=42", "setuptools_scm"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "clang"
+description = "libclang python bindings"
+readme = {file = "README.txt", content-type = "text/plain"}
+
+license = { text = "Apache-2.0 with LLVM exception" }
+authors = [
+    { name = "LLVM" }
+]
+keywords = ["llvm", "clang", "libclang"]
+classifiers = [
+    "Intended Audience :: Developers",
+    "License :: OSI Approved :: Apache Software License",
+    "Development Status :: 5 - Production/Stable",
+    "Topic :: Software Development :: Compilers",
+    "Operating System :: OS Independent",
+    "Programming Language :: Python :: 3",
+]
+dynamic = ["version"]
+
+[project.urls]
+Homepage = "http://clang.llvm.org/"
+Download = "http://llvm.org/releases/download.html"
+
+[tool.setuptools_scm]
+root = "../../.."
+version_file = "clang/_version.py"
+fallback_version = "0.0.0.dev0"
+# Regex version capture group gets x.y.z with optional -rcN, -aN, -bN suffixes; -init is just consumed
+tag_regex = "^llvmorg-(?P<version>[vV]?\\d+(?:\\.\\d+)*(?:-(?:rc|a|b)\\d+)?)(?:.*)$"
\ No newline at end of file

``````````

</details>


https://github.com/llvm/llvm-project/pull/125806


More information about the cfe-commits mailing list