Skip to content

Commit 1db5272

Browse files
authored
Fix/push versions (#1958)
* testing * Automate creation of a release branch and merge it to update the versions on main * Updated to include metadata introspection through a central metadata file and upgrade setuptools version (for PEP compliance)
1 parent 0abc855 commit 1db5272

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

.github/workflows/build_and_release.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ jobs:
2323
name: pypi
2424
permissions:
2525
id-token: write # IMPORTANT: mandatory for trusted publishing
26+
contents: write
2627
steps:
2728
- uses: actions/checkout@v4
2829
- name: Set up Python 3.9
2930
uses: actions/setup-python@v3
3031
with:
3132
python-version: "3.9"
3233
- name: Install dependencies
33-
run: python3 -m pip install setuptools wheel twine semver packaging
34+
run: python3 -m pip install --upgrade setuptools wheel twine semver packaging
3435
- name: Get correct version for TestPyPI release
3536
id: check_version
3637
run: |
@@ -41,11 +42,11 @@ jobs:
4142
echo "Version to be used for TestPyPI release: $NEW_VERSION"
4243
echo "::set-output name=version::$NEW_VERSION"
4344
- name: Update version in setup.py
44-
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ steps.check_version.outputs.version }}"/;}' setup.py
45+
run: sed -i '/#replace_package_version_marker/{n;s/__version__="[^"]*"/__version__="${{ steps.check_version.outputs.version }}"/;}' ./dspy/__metadata__.py
4546
- name: Update version in pyproject.toml
4647
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ steps.check_version.outputs.version }}"/;}' pyproject.toml
4748
- name: Update package name in setup.py
48-
run: sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy-ai-test"/;}' setup.py
49+
run: sed -i '/#replace_package_name_marker/{n;s/__name__="[^"]*"/__name__="dspy-ai-test"/;}' ./dspy/__metadata__.py
4950
- name: Update package name in pyproject.toml
5051
run: sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy-ai-test"/;}' pyproject.toml
5152
- name: Build a binary wheel
@@ -62,22 +63,23 @@ jobs:
6263
name: pypi
6364
permissions:
6465
id-token: write # IMPORTANT: mandatory for trusted publishing
66+
contents: write
6567
steps:
6668
- uses: actions/checkout@v4
6769
- name: Set up Python 3.9
6870
uses: actions/setup-python@v3
6971
with:
7072
python-version: "3.9"
7173
- name: Install dependencies
72-
run: python3 -m pip install setuptools wheel twine
74+
run: python3 -m pip install --upgrade setuptools wheel twine
7375
- name: Update version in setup.py (dspy)
74-
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' setup.py
76+
run: sed -i '/#replace_package_version_marker/{n;s/__version__="[^"]*"/__version__="${{ needs.extract-tag.outputs.version }}"/;}' ./dspy/__metadata__.py
7577
- name: Update version in pyproject.toml
7678
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' pyproject.toml
7779
# Publish to dspy
7880
- name: Update package name in setup.py
7981
run: |
80-
sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy"/;}' setup.py
82+
sed -i '/#replace_package_name_marker/{n;s/__name__="[^"]*"/__name__="dspy"/;}' ./dspy/__metadata__.py
8183
- name: Update package name in pyproject.toml
8284
run: sed -i '/#replace_package_name_marker/{n;s/name="[^"]*"/name="dspy"/;}' pyproject.toml
8385
- name: Build a binary wheel
@@ -86,7 +88,7 @@ jobs:
8688
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
8789
with:
8890
attestations: false
89-
# Publish to dspy-ai
91+
# Publish to dspy-ai
9092
- name: Update version in setup.py (dspy-ai)
9193
run: sed -i '/#replace_package_version_marker/{n;s/version="[^"]*"/version="${{ needs.extract-tag.outputs.version }}"/;}' ./dspy/.internal_dspyai/setup.py
9294
- name: Update package name in setup.py
@@ -99,4 +101,23 @@ jobs:
99101
- name: Publish distribution 📦 to PyPI (dspy-ai)
100102
uses: pypa/gh-action-pypi-publish@release/v1 # This requires a trusted publisher to be setup in pypi
101103
with:
102-
attestations: false
104+
attestations: false
105+
- uses: stefanzweifel/git-auto-commit-action@v5 # auto commit changes to main
106+
with:
107+
commit_message: Update versions
108+
create_branch: true
109+
branch: release-${{ needs.extract-tag.outputs.version }}
110+
- name: Checkout main branch
111+
run: |
112+
git fetch origin
113+
git checkout main
114+
- name: Configure git user
115+
run: |
116+
git config --global user.email "[email protected]"
117+
git config --global user.name "Github Actions"
118+
- name: Merge release branch into main
119+
run: |
120+
git merge --no-ff release-${{ needs.extract-tag.outputs.version }}
121+
- name: Push changes to main
122+
run: |
123+
git push origin main

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.github/

dspy/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
configure = settings.configure
2525
context = settings.context
2626

27+
from .__metadata__ import (
28+
__name__,
29+
__version__,
30+
__description__,
31+
__url__,
32+
__author__,
33+
__author_email__
34+
)
2735

2836
import dspy.teleprompt
2937

dspy/__metadata__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#replace_package_name_marker
2+
__name__="dspy"
3+
#replace_package_version_marker
4+
__version__="2.5.43"
5+
__description__="DSPy"
6+
__url__="https://github.com/stanfordnlp/dspy"
7+
__author__="Omar Khattab"
8+
__author_email__="[email protected]"

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ requires = ["setuptools>=40.8.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6+
# Do not add spaces around the '=' sign for any of the fields
7+
# preceeded by a marker comment as it affects the publish workflow.
68
#replace_package_name_marker
7-
name = "dspy"
9+
name="dspy"
810
#replace_package_version_marker
9-
version = "2.5.43"
11+
version="2.5.43"
1012
description = "DSPy"
1113
readme = "README.md"
1214
authors = [{ name = "Omar Khattab", email = "[email protected]" }]

setup.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from setuptools import find_packages, setup
2+
import os
23

34
# Read the content of the README file
45
with open("README.md", encoding="utf-8") as f:
@@ -8,20 +9,25 @@
89
with open("requirements.txt", encoding="utf-8") as f:
910
requirements = f.read().splitlines()
1011

12+
metadata = {}
13+
here = os.path.abspath(os.path.dirname(__file__))
14+
with open(os.path.join(here, "dspy", "__metadata__.py"), "r", encoding="utf-8") as f:
15+
exec(f.read(), metadata)
16+
f.close()
17+
18+
1119
setup(
12-
#replace_package_name_marker
13-
name="dspy",
14-
#replace_package_version_marker
15-
version="2.5.43",
16-
description="DSPy",
20+
name=metadata["__name__"],
21+
version=metadata["__version__"],
22+
description=metadata["__description__"],
23+
url=metadata["__url__"],
24+
author=metadata["__author__"],
25+
author_email=metadata["__author_email__"],
1726
long_description=long_description,
1827
long_description_content_type="text/markdown",
19-
url="https://github.com/stanfordnlp/dspy",
20-
author="Omar Khattab",
21-
author_email="[email protected]",
2228
license="MIT License",
2329
packages=find_packages(include=["dspy.*", "dspy"]),
24-
python_requires=">=3.9",
30+
python_requires=">=3.9",
2531
install_requires=requirements,
2632

2733
extras_require={

0 commit comments

Comments
 (0)