Skip to content

Commit 12a22b1

Browse files
Run test before publishing to pypi (stanfordnlp#7904)
* add testing * package name * use __version__ instead of importlib * name back
1 parent 2957c5f commit 12a22b1

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

.github/workflows/build_and_release.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ jobs:
4848
run: python3 -m build
4949
# Test the locally built wheel
5050
- name: Create test environment
51-
run: python -m venv test_env
51+
run: python -m venv test_before_testpypi
5252
- name: Test package installation and functionality
5353
run: |
54-
source test_env/bin/activate
54+
source test_before_testpypi/bin/activate
5555
# Install the locally built wheel and testing dependencies
5656
pip install dist/*.whl pytest
57-
python -c "import dspy; print(dspy.__version__)"
57+
pytest tests/metadata/test_metadata.py tests/predict
5858
deactivate
5959
# Publish to test-PyPI
6060
- name: Publish distribution 📦 to test-PyPI
@@ -93,6 +93,16 @@ jobs:
9393
run: sed -i '/#replace_package_name_marker/{n;s/__name__ *= *"[^"]*"/__name__="dspy"/;}' ./dspy/__metadata__.py
9494
- name: Build a binary wheel
9595
run: python3 -m build
96+
# Test the locally built wheel before publishing to pypi
97+
- name: Create test environment
98+
run: python -m venv test_before_pypi
99+
- name: Test package installation and functionality
100+
run: |
101+
source test_before_pypi/bin/activate
102+
# Install the locally built wheel and testing dependencies
103+
pip install dist/*.whl pytest
104+
pytest tests/metadata/test_metadata.py tests/predict
105+
deactivate
96106
- name: Publish distribution 📦 to PyPI (dspy)
97107
uses: pypa/gh-action-pypi-publish@release/v1
98108
with:

dspy/utils/saving.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
from pathlib import Path
44

55
import cloudpickle
6-
import importlib_metadata
76
import ujson
87

98
logger = logging.getLogger(__name__)
109

1110

1211
def get_dependency_versions():
13-
cloudpickle_version = '.'.join(cloudpickle.__version__.split('.')[:2])
12+
import dspy
13+
14+
cloudpickle_version = ".".join(cloudpickle.__version__.split(".")[:2])
15+
1416
return {
1517
"python": f"{sys.version_info.major}.{sys.version_info.minor}",
16-
"dspy": importlib_metadata.version("dspy"),
18+
"dspy": dspy.__version__,
1719
"cloudpickle": cloudpickle_version,
1820
}
1921

tests/metadata/test_metadata.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import dspy
2+
import re
3+
4+
5+
def test_metadata():
6+
assert dspy.__name__ == "dspy"
7+
assert re.match(r"\d+\.\d+\.\d+", dspy.__version__)
8+
assert dspy.__author__ == "Omar Khattab"
9+
assert dspy.__author_email__ == "[email protected]"
10+
assert dspy.__url__ == "https://github.com/stanfordnlp/dspy"
11+
assert dspy.__description__ == "DSPy"

0 commit comments

Comments
 (0)