Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Remove setup.py and rely fully on pyproject.toml (#7829)

Chen Qianaeb3e820d7aa
diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml
index 890c02a54..0cb8d7b35 100644
--- a/.github/workflows/build_and_release.yml
+++ b/.github/workflows/build_and_release.yml
@@ -5,7 +5,6 @@ on:
tags:
- "*"
jobs:
-
extract-tag:
runs-on: ubuntu-latest
outputs:
@@ -31,7 +30,7 @@ jobs:
with:
python-version: "3.9"
- name: Install dependencies
- run: python3 -m pip install --upgrade setuptools wheel twine semver packaging
+ run: python3 -m pip install --upgrade setuptools wheel twine build semver packaging
- name: Get correct version for TestPyPI release
id: check_version
run: |
@@ -41,16 +40,12 @@ jobs:
NEW_VERSION=$(python3 .github/workflows/build_utils/test_version.py $PACKAGE_NAME $VERSION)
echo "Version to be used for TestPyPI release: $NEW_VERSION"
echo "::set-output name=version::$NEW_VERSION"
- - name: Update version in setup.py
- run: sed -i '/#replace_package_version_marker/{n;s/__version__="[^"]*"/__version__="${{ steps.check_version.outputs.version }}"/;}' ./dspy/__metadata__.py
- name: Update version in pyproject.toml
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ steps.check_version.outputs.version }}"/;}' pyproject.toml
- - name: Update package name in setup.py
- run: sed -i '/#replace_package_name_marker/{n;s/__name__="[^"]*"/__name__="dspy-ai-test"/;}' ./dspy/__metadata__.py
- name: Update package name in pyproject.toml
run: sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy-ai-test"/;}' pyproject.toml
- name: Build a binary wheel
- run: python3 setup.py sdist bdist_wheel
+ run: python3 -m build
- name: Publish distribution 📦 to test-PyPI
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi/testpypi
with:
@@ -58,6 +53,8 @@ jobs:
build-and-publish-pypi:
needs: [extract-tag, build-and-publish-test-pypi]
+ # Only publish to PyPI if the repository owner is stanfordnlp, while the test-PyPI is open to all forks for testing
+ if: github.repository_owner == 'stanfordnlp'
runs-on: ubuntu-latest
environment:
name: pypi
@@ -71,43 +68,30 @@ jobs:
with:
python-version: "3.9"
- name: Install dependencies
- run: python3 -m pip install --upgrade setuptools wheel twine
- - name: Update version in setup.py (dspy)
- run: sed -i '/#replace_package_version_marker/{n;s/__version__ *= *"[^"]*"/__version__="${{ needs.extract-tag.outputs.version }}"/;}' ./dspy/__metadata__.py
+ run: python3 -m pip install --upgrade setuptools wheel twine build
- name: Update version in pyproject.toml
run: sed -i '/#replace_package_version_marker/{n;s/version *= *"[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' pyproject.toml
# Publish to dspy
- - name: Update package name in setup.py
- run: |
- sed -i '/#replace_package_name_marker/{n;s/__name__ *= *"[^"]*"/__name__="dspy"/;}' ./dspy/__metadata__.py
- name: Update package name in pyproject.toml
run: sed -i '/#replace_package_name_marker/{n;s/name *= *"[^"]*"/name="dspy"/;}' pyproject.toml
- # Remove pyproject.toml temporarily to avoid conflicts
- - name: Temporarily remove pyproject.toml
- run: mv pyproject.toml pyproject.toml.bak
- name: Build a binary wheel
- run: python3 setup.py sdist bdist_wheel
+ run: python3 -m build
- name: Publish distribution 📦 to PyPI (dspy)
- uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
+ uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: false
# Publish to dspy-ai
- - name: Update version in setup.py (dspy-ai)
- run: sed -i '/#replace_package_version_marker/{n;s/version *= *"[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' ./dspy/.internal_dspyai/setup.py
- - name: Update package name in setup.py
- run: sed -i '/#replace_package_name_marker/{n;s/name *= *"[^"]*"/name="dspy-ai"/;}' ./dspy/.internal_dspyai/setup.py
- - name: Update dspy dependency version in setup.py
- run: |
- sed -i '/#replace_dspy_version_marker/{n;s/dspy>=[^"]*/dspy>=${{ needs.extract-tag.outputs.version }}/;}' ./dspy/.internal_dspyai/setup.py
- - name: Build a binary wheel
- run: python3 ./dspy/.internal_dspyai/setup.py sdist bdist_wheel
+ - name: Update package name for dspy-ai
+ run: sed -i '/#replace_package_name_marker/{n;s/name *= *"[^"]*"/name="dspy-ai"/;}' pyproject.toml
+ - name: Build a binary wheel (dspy-ai)
+ run: python3 -m build
- name: Publish distribution 📦 to PyPI (dspy-ai)
- uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
+ uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: false
- # Restore pyproject.toml
- - name: Restore pyproject.toml
- run: mv pyproject.toml.bak pyproject.toml
+ # Restore name to dspy for git commit
+ - name: Restore package name to dspy
+ run: sed -i '/#replace_package_name_marker/{n;s/name *= *"[^"]*"/name="dspy"/;}' pyproject.toml
- uses: stefanzweifel/git-auto-commit-action@v5 # auto commit changes to main
with:
commit_message: Update versions
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index 58e03a4ae..89befa038 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -117,5 +117,5 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: python -m pip install --upgrade "poetry==${{ env.POETRY_VERSION }}"
- - name: Run setup.py build
- run: python setup.py build
+ - name: Build the wheel
+ run: python -m build
diff --git a/pyproject.toml b/pyproject.toml
index 8c512a1d7..f1f2740ed 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -50,6 +50,9 @@ dependencies = [
"cloudpickle",
]
+[tool.setuptools.packages.find]
+include = ["dspy*"]
+
[project.optional-dependencies]
anthropic = ["anthropic>=0.18.0,<1.0.0"]
chromadb = ["chromadb~=0.4.14"]
diff --git a/setup.py b/setup.py
deleted file mode 100644
index c2a993194..000000000
--- a/setup.py
+++ /dev/null
@@ -1,61 +0,0 @@
-from setuptools import find_packages, setup
-import os
-
-# Read the content of the README file
-with open("README.md", encoding="utf-8") as f:
- long_description = f.read()
-
-# Read the content of the requirements.txt file
-with open("requirements.txt", encoding="utf-8") as f:
- requirements = f.read().splitlines()
-
-metadata = {}
-here = os.path.abspath(os.path.dirname(__file__))
-with open(os.path.join(here, "dspy", "__metadata__.py"), "r", encoding="utf-8") as f:
- exec(f.read(), metadata)
-f.close()
-
-
-setup(
- name=metadata["__name__"],
- version=metadata["__version__"],
- description=metadata["__description__"],
- url=metadata["__url__"],
- author=metadata["__author__"],
- author_email=metadata["__author_email__"],
- long_description=long_description,
- long_description_content_type="text/markdown",
- license="MIT License",
- packages=find_packages(include=["dspy.*", "dspy"]),
- python_requires=">=3.9",
- install_requires=requirements,
-
- extras_require={
- "chromadb": ["chromadb~=0.4.14"],
- "lancedb": ["lancedb~=0.11.0"],
- "qdrant": ["qdrant-client", "fastembed"],
- "marqo": ["marqo~=3.1.0"],
- "mongodb": ["pymongo~=3.12.0"],
- "pinecone": ["pinecone-client~=2.2.4"],
- "weaviate": ["weaviate-client~=4.6.5"],
- "faiss-cpu": ["sentence_transformers", "faiss-cpu"],
- "milvus": ["pymilvus~=2.3.7"],
- "google-vertex-ai": ["google-cloud-aiplatform==1.43.0"],
- "myscale":["clickhouse-connect"],
- "snowflake": ["snowflake-snowpark-python"],
- "fastembed": ["fastembed"],
- "groq": ["groq~=0.8.0"],
- "langfuse": ["langfuse~=2.36.1"],
- "pgvector": ["psycopg2~=2.9.9","pgvector~=0.2.5"],
- "falkordb": ["falkordb", "redis", "async-timeout"]
- },
- classifiers=[
- "Development Status :: 3 - Alpha",
- "Intended Audience :: Science/Research",
- "License :: OSI Approved :: MIT License",
- "Operating System :: POSIX :: Linux",
- "Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3.8",
- "Programming Language :: Python :: 3.9",
- ],
-)