Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sharktank] Modernize setup.py based project #371

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions sharktank/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "sharktank"
authors = [
{name = "SHARK Authors"},
]
description = "SHARK layers and inference models for genai"
readme = "README.md"
license = {text = "Apache-2.0"}
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
requires-python = ">= 3.11"
dependencies = ["iree-turbine"]
dynamic = ["version"] # the version is set via the `setup.py`

[project.optional-dependencies]
testing = ["pytest"]

[project.urls]
Repository = "https://github.com/nod-ai/SHARK-Platform"

[tool.setuptools.packages.find]
where = ["."]
include = ["sharktank*"]
namespaces = true

[tool.setuptools.package-data]
sharktank = ["py.typed", "kernels/templates/*.mlir"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.pytest.ini_options]
addopts = [
"-ra",
Expand Down
80 changes: 1 addition & 79 deletions sharktank/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@

import json
import os
import distutils.command.build
from pathlib import Path

from setuptools import find_namespace_packages, setup # type: ignore
from setuptools import setup

SETUPPY_DIR = os.path.realpath(os.path.dirname(__file__))


with open(
os.path.join(
SETUPPY_DIR,
"README.md",
),
"rt",
) as f:
README = f.read()


# Setup and get version information.
VERSION_INFO_FILE = os.path.join(SETUPPY_DIR, "version_info.json")

Expand All @@ -36,72 +24,6 @@ def load_version_info():
version_info = load_version_info()
PACKAGE_VERSION = version_info["package-version"]

packages = find_namespace_packages(
include=[
"sharktank",
"sharktank.*",
],
)

print("Found packages:", packages)

# Lookup version pins from requirements files.
requirement_pins = {}


def load_requirement_pins(requirements_file: Path):
with open(requirements_file, "rt") as f:
lines = f.readlines()
pin_pairs = [line.strip().split("==") for line in lines if "==" in line]
requirement_pins.update(dict(pin_pairs))


load_requirement_pins("requirements.txt")


def get_version_spec(dep: str):
if dep in requirement_pins:
return f">={requirement_pins[dep]}"
else:
return ""


# Override build command so that we can build into _python_build
# instead of the default "build". This avoids collisions with
# typical CMake incantations, which can produce all kinds of
# hilarity (like including the contents of the build/lib directory).
class BuildCommand(distutils.command.build.build):
def initialize_options(self):
distutils.command.build.build.initialize_options(self)
self.build_base = "_python_build"


setup(
name=f"sharktank",
version=f"{PACKAGE_VERSION}",
author="SHARK Authors",
description="SHARK layers and inference models for genai",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/nod-ai/SHARK-Platform",
license="Apache-2.0",
classifiers=[
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
],
packages=packages,
include_package_data=True,
package_data={
"sharktank": ["py.typed", "kernels/templates/*.mlir"],
},
install_requires=[
"iree-turbine",
],
extras_require={
"testing": [
f"pytest{get_version_spec('pytest')}",
],
},
cmdclass={"build": BuildCommand},
)
Loading