Skip to content

Commit

Permalink
prepare for pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
Ion committed Dec 4, 2024
1 parent 7455f9c commit 5e3331a
Show file tree
Hide file tree
Showing 16 changed files with 2,722 additions and 68 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Publish torchTT to pypi

on: push

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/torchTT # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[build-system]
requires = ["setuptools>=61", "setuptools-scm>=8.0", "wheel", "torch>=1.7", "numpy>=1.18", "opt_einsum", "ninja", "scipy>=0.16"]
build-backend = "setuptools.build_meta"

[tool.setuptools.package-data]
torchtt = ["cpp/*"]

[tool.setuptools]
py-modules = []

[project]
name = "torchTT"
version = "0.1"
description = "Tensor-Train decomposition in pytorch."
readme = "README.md"
requires-python = ">=3.7"
dependencies = [
"torch>=1.7",
"numpy>=1.18",
"opt_einsum",
"scipy>=0.16",
"ninja"
]
license = {file = "LICENSE"}
authors = [
{ name = "Ion Gabriel Ion", email = "ion.ion.gabriel@gmail.com" }
]
keywords = ["pytorch", "tensor-train decomposition"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
]
13 changes: 0 additions & 13 deletions pyproject_toml

This file was deleted.

103 changes: 48 additions & 55 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import platform
from warnings import warn

try:
import torch.utils.cpp_extension
from torch.utils.cpp_extension import BuildExtension, CppExtension
except ImportError:
raise Exception("Torch must be installed before running this setup.")

logo_ascii = """
_ _ _____ _____
Expand All @@ -10,62 +18,47 @@
"""

try:
from torch.utils.cpp_extension import BuildExtension, CppExtension
except:
raise Exception("Torch has to be installed first")

os_name = platform.system()

print()
print(logo_ascii)
print()

def python_install():

import warnings
warnings.warn("\x1B[33m\nC++ implementation not available. Using pure Python.\n\033[0m")

setup(name='torchTT',
version='2.0',
description='Tensor-Train decomposition in pytorch',
url='https://github.com/ion-g-ion/torchTT',
author='Ion Gabriel Ion',
author_email='ion.ion.gabriel@gmail.com',
license='MIT',
packages=['torchtt'],
install_requires=['numpy>=1.18','torch>=1.7','opt_einsum'],
test_suite='tests',
zip_safe=False)

print("\n" + logo_ascii + "\n")

if os_name == 'Linux' or os_name == 'Darwin':
if os_name in ['Linux', 'Darwin']:
try:
setup(name='torchTT',
version='2.0',
description='Tensor-Train decomposition in pytorch',
url='https://github.com/ion-g-ion/torchTT',
author='Ion Gabriel Ion',
author_email='ion.ion.gabriel@gmail.com',
license='MIT',
packages=['torchtt'],
install_requires=['pytest', 'numpy>=1.18','torch>=1.7','opt_einsum'],
ext_modules=[
CppExtension('torchttcpp', ['cpp/cpp_ext.cpp'], extra_compile_args=['-lblas', '-llapack', '-std=c++17', '-Wno-c++11-narrowing', '-g', '-w', '-O3']),
],
cmdclass={
'build_ext': BuildExtension
},
test_suite='tests',
zip_safe=False,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
])
except:
python_install()
else:
python_install()


# setup(
# # cmdclass={'build_ext': build_ext},
# ext_modules=[
# Extension(
# name='torchttcpp',
# sources=['cpp/cpp_ext.cpp'],
# include_dirs=torch.utils.cpp_extension.include_paths()+["cpp"],
# libray_dirs = torch.utils.cpp_extension.library_paths(),
# language='c++',
# extra_compile_args=[
# '-lblas', '-llapack', '-std=c++17',
# '-Wno-c++11-narrowing', '-g', '-w', '-O3'
# ])
# ]
# )

setup(
cmdclass={'build_ext': BuildExtension},
ext_modules=[
CppExtension(
'torchttcpp',
['cpp/cpp_ext.cpp'],
include_dirs=["cpp"],
extra_compile_args=[
'-std=c++17',
'-Wno-c++11-narrowing', '-g', '-w', '-O3'
],
is_python_module=True # Ensures linking with PyTorch's C++ libraries
)
],
)
except Exception as e:
warn("\x1B[33m\nC++ implementation not available. Falling back to pure Python.\n\033[0m")
print(f"Error: {e}")
setup()
else:
warn("\x1B[33m\nC++ implementation not supported on this OS. Falling back to pure Python.\n\033[0m")
setup()
Loading

0 comments on commit 5e3331a

Please sign in to comment.