Skip to content

Commit bb18437

Browse files
committed
Version Definition: The version is now defined only in datafog/__about__.py
Setup.py Integration: The setup.py file now reads the version from __about__.py without importing the package, which avoids circular dependencies during build GitHub Actions Workflow: The CI/CD workflow has been updated to only modify the version in __about__.py
1 parent d658ec7 commit bb18437

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,34 @@ jobs:
8282
- name: Generate beta version
8383
id: beta_version
8484
run: |
85-
# Read current version from setup.py
86-
CURRENT_VERSION=$(grep -o '__version__ = "[^"]*"' setup.py | cut -d"" -f2)
85+
# Read current version from __about__.py (single source of truth)
86+
CURRENT_VERSION=$(grep -o '__version__ = "[^"]*"' datafog/__about__.py | sed 's/__version__ = "\(.*\)"/\1/')
8787
echo "Current version in files: $CURRENT_VERSION"
8888
8989
# Split version into components
90-
IFS='.' read -r MAJOR MINOR PATCH_FULL <<< "$CURRENT_VERSION"
90+
IFS='.' read -r MAJOR MINOR PATCH_FULL <<< "$CURRENT_VERSION" || true
91+
92+
# Validate we got valid version components
93+
if [[ -z "$MAJOR" || -z "$MINOR" || -z "$PATCH_FULL" ]]; then
94+
echo "Error: Could not parse version components from $CURRENT_VERSION"
95+
echo "Using default version 0.0.1b1"
96+
MAJOR=0
97+
MINOR=0
98+
PATCH_FULL=1
99+
fi
91100
92101
# Handle beta suffix if it exists
93102
if [[ $PATCH_FULL == *b* ]]; then
94103
# Extract the numeric part before 'b'
95104
PATCH_NUM=${PATCH_FULL%%b*}
96105
# Extract the beta number and increment it
97106
BETA_NUM=${PATCH_FULL#*b}
98-
BETA_NUM=$((BETA_NUM + 1))
107+
# Ensure beta number is a valid integer
108+
if ! [[ $BETA_NUM =~ ^[0-9]+$ ]]; then
109+
BETA_NUM=1
110+
else
111+
BETA_NUM=$((BETA_NUM + 1))
112+
fi
99113
else
100114
# If not already a beta, use the patch number and start with beta1
101115
PATCH_NUM=$PATCH_FULL
@@ -107,13 +121,8 @@ jobs:
107121
echo "Generated beta version: $BETA_VERSION"
108122
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
109123
110-
# Update version in setup.py
111-
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" setup.py
112-
113-
# Update version in __about__.py if it exists
114-
if [ -f "datafog/__about__.py" ]; then
115-
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" datafog/__about__.py
116-
fi
124+
# Update version in __about__.py (single source of truth)
125+
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" datafog/__about__.py
117126
- name: Build package
118127
run: python -m build
119128
- name: Create GitHub Pre-Release
@@ -125,7 +134,7 @@ jobs:
125134
git config user.email github-actions@github.com
126135
127136
# Commit the version changes
128-
git add setup.py datafog/__about__.py
137+
git add datafog/__about__.py
129138
git commit -m "Bump version to $BETA_VERSION [skip ci]"
130139
131140
# Create and push tag

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
with open("README.md", "r") as f:
55
long_description = f.read()
66

7-
# Use a single source of truth for the version
8-
__version__ = "4.1.0b4"
7+
# Read version from __about__.py without importing the package
8+
# This avoids circular dependencies during build
9+
about = {}
10+
with open("datafog/__about__.py", "r") as f:
11+
exec(f.read(), about)
12+
13+
__version__ = about["__version__"]
914

1015
project_urls = {
1116
"Homepage": "https://datafog.ai",

test_version.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
# Read version directly from __about__.py
4+
with open('datafog/__about__.py', 'r') as f:
5+
about_content = f.read().strip()
6+
about_version = about_content.split('"')[1] # Simple string split to extract version
7+
8+
print(f"Version in __about__.py: {about_version}")
9+
10+
# Read version from setup.py using the same method setup.py uses
11+
about = {}
12+
with open("datafog/__about__.py", "r") as f:
13+
exec(f.read(), about)
14+
15+
setup_version = about['__version__']
16+
print(f"Version extracted by setup.py: {setup_version}")
17+
18+
# Verify they match
19+
if about_version == setup_version:
20+
print("✅ SUCCESS: Single source of truth is working correctly!")
21+
else:
22+
print("❌ ERROR: Versions don't match")

0 commit comments

Comments
 (0)