Skip to content

Commit

Permalink
Run test before publishing to pypi (stanfordnlp#7904)
Browse files Browse the repository at this point in the history
* add testing

* package name

* use __version__ instead of importlib

* name back
  • Loading branch information
chenmoneygithub authored Mar 4, 2025
1 parent 2957c5f commit 12a22b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ jobs:
run: python3 -m build
# Test the locally built wheel
- name: Create test environment
run: python -m venv test_env
run: python -m venv test_before_testpypi
- name: Test package installation and functionality
run: |
source test_env/bin/activate
source test_before_testpypi/bin/activate
# Install the locally built wheel and testing dependencies
pip install dist/*.whl pytest
python -c "import dspy; print(dspy.__version__)"
pytest tests/metadata/test_metadata.py tests/predict
deactivate
# Publish to test-PyPI
- name: Publish distribution 📦 to test-PyPI
Expand Down Expand Up @@ -93,6 +93,16 @@ jobs:
run: sed -i '/#replace_package_name_marker/{n;s/__name__ *= *"[^"]*"/__name__="dspy"/;}' ./dspy/__metadata__.py
- name: Build a binary wheel
run: python3 -m build
# Test the locally built wheel before publishing to pypi
- name: Create test environment
run: python -m venv test_before_pypi
- name: Test package installation and functionality
run: |
source test_before_pypi/bin/activate
# Install the locally built wheel and testing dependencies
pip install dist/*.whl pytest
pytest tests/metadata/test_metadata.py tests/predict
deactivate
- name: Publish distribution 📦 to PyPI (dspy)
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
8 changes: 5 additions & 3 deletions dspy/utils/saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
from pathlib import Path

import cloudpickle
import importlib_metadata
import ujson

logger = logging.getLogger(__name__)


def get_dependency_versions():
cloudpickle_version = '.'.join(cloudpickle.__version__.split('.')[:2])
import dspy

cloudpickle_version = ".".join(cloudpickle.__version__.split(".")[:2])

return {
"python": f"{sys.version_info.major}.{sys.version_info.minor}",
"dspy": importlib_metadata.version("dspy"),
"dspy": dspy.__version__,
"cloudpickle": cloudpickle_version,
}

Expand Down
11 changes: 11 additions & 0 deletions tests/metadata/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dspy
import re


def test_metadata():
assert dspy.__name__ == "dspy"
assert re.match(r"\d+\.\d+\.\d+", dspy.__version__)
assert dspy.__author__ == "Omar Khattab"
assert dspy.__author_email__ == "okhattab@stanford.edu"
assert dspy.__url__ == "https://github.com/stanfordnlp/dspy"
assert dspy.__description__ == "DSPy"

0 comments on commit 12a22b1

Please sign in to comment.