Skip to content

Commit

Permalink
revamped build system to use hybrid setup.py and pyproject.toml approach
Browse files Browse the repository at this point in the history
  • Loading branch information
bonevbs committed Aug 27, 2024
1 parent cc01d25 commit 78770c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 59 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/deploy_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ jobs:
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build wheel setuptools numpy
python -m pip install build wheel setuptools numpy torch
- name: Build source distribution
- name: Build distribution
run: |
python -m build --sdist
- name: Install torch and build wheel
run: |
python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
python -m build --wheel
python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = [ "setuptools", "setuptools-scm", "torch>=2.4.0"]
build-backend = "setuptools.build_meta"

[project]
name = "torch_harmonics"
authors = [
{ name="Boris Bonev", email = "[email protected]" },
{ name="Thorsten Kurth", email = "[email protected]" },
{ name="Jean Kossaifi" },
{ name="Nikola Kovachki" },
{ name="Christian Hundt" },
]

maintainers = [
{ name="Thorsten Kurth", email = "[email protected]" },
{ name="Boris Bonev", email = "[email protected]" },
]

dynamic = ["version", "readme"]

description = "Differentiable harmonics transforms and convolutions on the sphere for PyTorch."
requires-python = ">=3.10"

classifiers = [
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Modified BSD",
"Operating System :: OS Independent",
]

dependencies = [
"torch>=2.4.0",
"numpy>=1.22.4,<1.25",
]

[tool.setuptools.dynamic]
version = {attr = "torch_harmonics.__version__"}
readme = {file = ["README.md"]}

[tool.setuptools.packages.find]
include = ["torch_harmonics*"]

[project.optional-dependencies]
dev = [
"pytest>=6.0.0",
"coverage>=6.5.0",
]
61 changes: 10 additions & 51 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,24 @@
#

import sys
from pathlib import Path
import re

try:
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup, find_packages

def version(root_path):
"""Returns the version taken from __init__.py"""
version_path = root_path.joinpath("torch_harmonics", "__init__.py")
with version_path.open() as f:
version_file = f.read()
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.")
import torch
from torch.utils import cpp_extension

def readme(root_path):
"""Returns the text content of README.md"""
with root_path.joinpath("README.md").open(encoding="UTF-8") as f:
return f.read()

def get_ext_modules(argv):
# Delay import of torch and cpp_extension
import torch
from torch.utils import cpp_extension

compile_cuda_extension = "--cuda_ext" in argv
if "--cuda_ext" in argv:
argv.remove("--cuda_ext")

print(compile_cuda_extension)

ext_modules = [
cpp_extension.CppExtension("disco_helpers", ["torch_harmonics/csrc/disco/disco_helpers.cpp"]),
]
Expand All @@ -80,39 +66,12 @@ def get_ext_modules(argv):

return ext_modules

root_path = Path(__file__).parent
README = readme(root_path)
VERSION = version(root_path)

config = {
"name": "torch_harmonics",
"packages": find_packages(),
"description": "A differentiable spherical harmonic transform for PyTorch.",
"long_description": README,
"long_description_content_type": "text/markdown",
"url": "https://github.com/NVIDIA/torch-harmonics",
"author": "Boris Bonev",
"author_email": "[email protected]",
"version": VERSION,
"install_requires": ["torch", "numpy"],
"extras_require": {
"sfno": ["tensorly", "tensorly-torch"],
},
"license": "Modified BSD",
"scripts": [],
"include_package_data": True,
"classifiers": ["Topic :: Scientific/Engineering", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3"],
}
if __name__ == "__main__":

def setup_package():
# Delay the decision about ext_modules and cmdclass
ext_modules = get_ext_modules(sys.argv)
if ext_modules:
from torch.utils import cpp_extension
config["ext_modules"] = ext_modules
config["cmdclass"] = {"build_ext": cpp_extension.BuildExtension}

setup(**config)

if __name__ == "__main__":
setup_package()
setup(
packages=find_packages(),
ext_modules=ext_modules,
cmdclass={"build_ext": cpp_extension.BuildExtension},
)

0 comments on commit 78770c2

Please sign in to comment.