Skip to content

Commit 8dd9ea0

Browse files
authored
Update python-publish.yml
1 parent 08302b6 commit 8dd9ea0

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

.github/workflows/python-publish.yml

+29-14
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,42 @@ jobs:
2222
- name: Install build dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
pip install build twine packaging requests
25+
pip install build twine packaging requests tomli
2626
2727
- name: Build package
2828
run: python -m build
2929

30-
# Get current version and package name
30+
# Get current version and package name using Python
3131
- name: Get package info
3232
id: package_info
3333
run: |
34-
if [ -f "pyproject.toml" ]; then
35-
VERSION=$(grep -Po "(?<=version = \")[^\"]*" pyproject.toml)
36-
PACKAGE_NAME=$(grep -Po "(?<=name = \")[^\"]*" pyproject.toml)
37-
elif [ -f "setup.py" ]; then
38-
VERSION=$(python setup.py --version)
39-
PACKAGE_NAME=$(python setup.py --name)
40-
else
41-
echo "No version file found"
42-
exit 1
43-
fi
44-
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45-
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
34+
python - <<EOF >> "$GITHUB_OUTPUT"
35+
import tomli
36+
import json
37+
38+
try:
39+
with open("pyproject.toml", "rb") as f:
40+
data = tomli.load(f)
41+
42+
# Handle different possible TOML structures
43+
if "project" in data:
44+
# PEP 621 metadata
45+
version = data["project"]["version"]
46+
name = data["project"]["name"]
47+
elif "tool" in data and "poetry" in data["tool"]:
48+
# Poetry metadata
49+
version = data["tool"]["poetry"]["version"]
50+
name = data["tool"]["poetry"]["name"]
51+
else:
52+
raise KeyError("Could not find version/name in pyproject.toml")
53+
54+
print(f"version={version}")
55+
print(f"package_name={name}")
56+
57+
except Exception as e:
58+
print(f"Error parsing pyproject.toml: {e}")
59+
exit(1)
60+
EOF
4661
4762
# Check PyPI version using API
4863
- name: Check if version exists on PyPI

0 commit comments

Comments
 (0)