From a4ce249911e978ca7aa4dc6546bac8e7838154ac Mon Sep 17 00:00:00 2001 From: mentatai <162378962+mentatai@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:45:52 +0000 Subject: [PATCH] Fix PyPI publishing by modernizing package configuration This commit updates our package configuration to use modern Python packaging tools: - Moves build configuration to pyproject.toml using hatchling as the build backend - Updates metadata version to properly handle license-file - Converts setup.py to a custom build hook for dynamic dependency handling - Maintains existing functionality while using modern packaging standards Fixes #596 --- pyproject.toml | 33 ++++++++++++++++++++++++++++++++- setup.py | 48 +++++++++++------------------------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5d5d4701a..c605153e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,37 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "mentat" +dynamic = ["version"] +description = "AI coding assistant on your command line" +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.10" +authors = [ + { name = "Abante AI", email = "contact@abante.ai" }, +] +dependencies = [ + # We'll dynamically read these from requirements.txt in the [tool.hatch.build.targets.wheel] section +] + +[tool.hatch.version] +path = "mentat/VERSION" + +[tool.hatch.build.targets.wheel] +packages = ["mentat", "benchmarks"] + +[tool.hatch.build.targets.wheel.hooks.custom] +path = "setup.py" + +[project.scripts] +mentat = "mentat.terminal.client:run_cli" +mentat-server = "mentat.server.mentat_server:main" +mentat-daemon = "mentat.daemon:main" + [tool.ruff] line-length = 120 [tool.pytest.ini_options] addopts = "--ignore=vscode/bundled --ignore=benchmarks/benchmark_repos --ignore=testbed/exercism-python" - diff --git a/setup.py b/setup.py index 4369787f1..d9693ca94 100644 --- a/setup.py +++ b/setup.py @@ -2,44 +2,18 @@ from pathlib import Path import pkg_resources -from setuptools import find_packages, setup -readme_path = os.path.join(Path(__file__).parent, "README.md") -with open(readme_path, "r", encoding="utf-8") as f: - long_description = f.read() +def read_requirements(filename): + """Read requirements from a file and return as a list of strings.""" + with open(os.path.join(os.path.dirname(__file__), filename)) as f: + return [str(r) for r in pkg_resources.parse_requirements(f)] -version_path = os.path.join(Path(__file__).parent, "mentat/VERSION") -with open(version_path, "r", encoding="utf-8") as f: - VERSION = f.read().strip() -setup( - name="mentat", - version=VERSION, - python_requires=">=3.10", - packages=find_packages(include=["mentat", "mentat.*", "benchmarks", "benchmarks.*"]), - install_requires=[ - str(r) - for r in pkg_resources.parse_requirements(open(os.path.join(os.path.dirname(__file__), "requirements.txt"))) - ], - entry_points={ - "console_scripts": [ - "mentat=mentat.terminal.client:run_cli", - "mentat-server=mentat.server.mentat_server:main", - "mentat-daemon=mentat.daemon:main", - ], - }, - description="AI coding assistant on your command line", - long_description=long_description, - long_description_content_type="text/markdown", - license="Apache-2.0", - include_package_data=True, - extras_require={ - "dev": [ - str(r) - for r in pkg_resources.parse_requirements( - open(os.path.join(os.path.dirname(__file__), "dev-requirements.txt")) - ) - ], - }, -) +def hook(version, build_data): + """Custom build hook for hatchling to set dynamic dependencies.""" + build_data["dependencies"] = read_requirements("requirements.txt") + build_data["optional-dependencies"] = { + "dev": read_requirements("dev-requirements.txt") + } + return build_data